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 返回瀏覽器一個表格
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.