Hi..there,,
Can anyone help me with this Core servlet and javaserver program..I want to build a table consisting of rows and columns specified from the user. Below ,is the HTML page that take parameter from the user asking for how many rows and column they want..than from that it will build a table of rows and column.This is like handling a user request in term of Form Data.I'm having the problem on how :
1)to convert the String input to the Integer.
2)on the nested for loop .
Can anyone help me..Thanks.HTML Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>Rows and Colums</TITLE></HEAD> <BODY BGCOLOR="#FDF5E6"> <H1 ALIGN="CENTER">Rows and Colums Parameters</H1> <FORM ACTION="/first/homework"> Enter no of rows: <INPUT TYPE="TEXT" NAME="row"><BR> Enter no of colums: <INPUT TYPE="TEXT" NAME="colums"><BR> <CENTER><INPUT TYPE="SUBMIT"></CENTER> </FORM> </BODY></HTML>
package coreservlets; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /* Simple servlet that reads three parameters from the form data. */ public class Table extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String title = "Reading Three Request Parameters"; String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n"; out.println(docType + "<HTML>\n" + "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=\"CENTER\">" + title + "</H1>\n" + Integer.parseInt(request.getParameter("row")); Integer.parseInt(request.getParameter("colums")); out.println("<table border=1 cellspacing=1 cellpadding=5>\n"); for (int i=1;i<=row ;i++) { out.println("<tr>"); for (int j=1;j<=colums;j++) { out.println("<td>" + (i + j) + "</td>"); } out.println("<tr>"); } out.println("</table>"); out.println("</BODY></HTML>"); } }