public class BodyServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//获取输出流 字符流
PrintWriter writer = response.getWriter();
writer.print("<table border='1px' width='200px' height='150px' align='center'>");
writer.println("<tr>");
writer.println("<th>ID");
writer.println("</th>");
writer.println("<th>Name");
writer.println("</th>");
writer.println("</tr>");
writer.println("<tr>");
writer.println("<td>1");
writer.println("</td>");
writer.println("<th>tom");
writer.println("</td>");
writer.println("</tr>");
writer.println("<tr>");
writer.println("<td>2");
writer.println("</td>");
writer.println("<td>jerry");
writer.println("</td>");
writer.println("</tr>");
writer.print("</table>");
//关闭流
writer.close();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
Servlet 返回浏览器一个表格
最新推荐文章于 2022-10-24 10:48:02 发布