重写 HttpServlet 中的 doGet()方法和 doPost()方法打印出九九乘法表
时间: 2024-05-04 20:18:45 浏览: 121
打印九九乘法表
以下是在 `doGet()` 方法中打印九九乘法表的示例代码:
```java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>九九乘法表</title>");
out.println("</head>");
out.println("<body>");
out.println("<table border=\"1\">");
for (int i = 1; i <= 9; i++) {
out.println("<tr>");
for (int j = 1; j <= i; j++) {
out.println("<td>" + j + "x" + i + "=" + (i * j) + "</td>");
}
out.println("</tr>");
}
out.println("</table>");
out.println("</body>");
out.println("</html>");
}
```
以下是在 `doPost()` 方法中打印九九乘法表的示例代码:
```java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
```
这两个方法都很简单,只需要在响应中输出九九乘法表即可。
阅读全文