我是 servlet 的新手,所以请耐心等待。
我想制作一个 servlet,它使用默认值(例如 2 行、2 列)在两个文本值下面编写一个标准表。
在这些文本框中,我想填写想要的行和列。将这些文本值填入表格后,必须更改为要求的表格。
此时我收到 404 错误
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
@SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("Text/html");
PrintWriter pw = response.getWriter();
pw.println("<html><body>");
pw.println("<h1>Table generator</h1><table border=1>");
Integer row = (Integer) request.getAttribute("rows");
Integer col = (Integer) request.getAttribute("cols");
if (row != null && col != null) {
for (int i = 1; i < col; i++) {
pw.print(HtmlUtils.getTH("center", "COL" + i));
}
@SuppressWarnings("rawtypes")
Vector av = new Vector();
for (int i = 1; i < row; i++) {
for (int y = 1; i < col; y++) {
av.addElement("index" + col + "." + y);
}
}
} else {
pw.print(HtmlUtils.getTableHead("center", 1));
pw.print(HtmlUtils.getTH("center", "COL1"));
pw.print(HtmlUtils.getTH("center", "COL2"));
@SuppressWarnings("rawtypes")
Vector av = new Vector();
for (int i = 1; i < 5; i++) {
av.addElement("index1." + i);
av.addElement("index2." + i);
}
pw.print(HtmlUtils.getTableContents("center", av, 2));
}
pw.println("</table>");
pw.println("<form action='input' method='post'>");
pw.println("Rows : <input type='text' name='rows'><br>");
pw.println("Cols : <input type='text' name='cols'><br>");
pw.println("<input type='submit'>");
pw.println("</form></body></html>");
}
有什么建议么