Servlet2.java~3~
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. package filter5;
  2. import javax.servlet.*;
  3. import javax.servlet.http.*;
  4. import java.io.*;
  5. import java.util.*;
  6. public class Servlet2 extends HttpServlet implements Filter {
  7.   private FilterConfig filterConfig;
  8.   //Handle the passed-in FilterConfig
  9.   public void init(FilterConfig filterConfig) {
  10.     this.filterConfig = filterConfig;
  11.   }
  12.   //Process the request/response pair
  13.   public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
  14.     try{
  15.     String password = ((HttpServletRequest) request).getParameter("password");
  16.            if(password.equals("cwj")) {
  17.                filterChain.doFilter(request, response);
  18.            } else {
  19.                response.setContentType("text/html");
  20.                PrintWriter out = response.getWriter();
  21.                out.println("<HTML>");
  22.                out.println("<HEAD>");
  23.                out.println("<TITLE>");
  24.                out.println("Incorrect Password");
  25.                out.println("</TITLE>");
  26.                out.println("</HEAD>");
  27.                out.println("<BODY>");
  28.                out.println("<H1>Incorrect Password</H1>");
  29.                out.println("Sorry, that password was incorrect.");
  30.                out.println("</BODY>");
  31.                out.println("</HTML>");
  32.            }
  33.        }
  34.     catch(ServletException sx) {
  35.       filterConfig.getServletContext().log(sx.getMessage());
  36.     }
  37.     catch(IOException iox) {
  38.       filterConfig.getServletContext().log(iox.getMessage());
  39.     }
  40.   }
  41.   //Clean up resources
  42.   public void destroy() {
  43.   }
  44. }