public class TableFilter extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { // Get all headers set by the previous servlet and echo them java.util.Enumeration e = req.getHeaderNames(); while (e.hasMoreElements()) { String header = (String)e.nextElement(); String value = req.getHeader(header); resp.setHeader(header, value); } // Get the input and output streams ServletInputStream in = req.getInputStream(); ServletOutputStream out = resp.getOutputStream(); // Only process if this is a recognized MIME type String type = req.getContentType(); if (type.equals("text/html") || type.equals("text/table") || type.equals("application/x-www-form-urlencoded")) { resp.setContentType("text/html"); // Create a buffered reader that we can use to read // a single line at a time BufferedReader br = new BufferedReader(new InputStreamReader(in));
// If we are in the middle of a table command, process // the line
if (inTable) {
// Search for the end of the table if (s.startsWith("<!--end table")) { out.println("</table></center>"); inTable = false; } else { // We've got a row of a table - format it s = formatRow(s, tableCols, headerRow); headerRow = false; } } else {
// Search for the start of a table if (s.startsWith("<!--table")) { int pos = s.indexOf("columns="); tableCols = 0; if (pos >= 0) {
public class ghq extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { // Create a PrintWriter to write the response java.io.PrintWriter out = new java.io.PrintWriter(resp.getOutputStream()); // Set the content type of the response resp.setContentType("text/html;charset=gb2312"); // Print the HTML header out.println("<html>"); out.println("<head>"); out.println("<title>Java Servlets Sample - " + "通讯录 </title>"); out.println("</head>"); out.println("<h2><center>"); out.println("通讯录</center></h2>"); out.println("<br>");
// Output special table formatting instructions for // the TableFilter servlet