Servlet2.java~3~
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package filter5;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.io.*;
- import java.util.*;
- public class Servlet2 extends HttpServlet implements Filter {
- private FilterConfig filterConfig;
- //Handle the passed-in FilterConfig
- public void init(FilterConfig filterConfig) {
- this.filterConfig = filterConfig;
- }
- //Process the request/response pair
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
- try{
- String password = ((HttpServletRequest) request).getParameter("password");
- if(password.equals("cwj")) {
- filterChain.doFilter(request, response);
- } else {
- response.setContentType("text/html");
- PrintWriter out = response.getWriter();
- out.println("<HTML>");
- out.println("<HEAD>");
- out.println("<TITLE>");
- out.println("Incorrect Password");
- out.println("</TITLE>");
- out.println("</HEAD>");
- out.println("<BODY>");
- out.println("<H1>Incorrect Password</H1>");
- out.println("Sorry, that password was incorrect.");
- out.println("</BODY>");
- out.println("</HTML>");
- }
- }
- catch(ServletException sx) {
- filterConfig.getServletContext().log(sx.getMessage());
- }
- catch(IOException iox) {
- filterConfig.getServletContext().log(iox.getMessage());
- }
- }
- //Clean up resources
- public void destroy() {
- }
- }