Servlet 返回浏览器一个表格

来源:互联网 发布:java重载 返回值 编辑:程序博客网 时间:2024/05/23 12:27
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);}}

原创粉丝点击