Header

  1. View current page

    정상혁의 수첩

Profile_img_60x60_08
195

Filter 설정예

 <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <display-name>
 test</display-name>
 <welcome-file-list>
  <welcome-file>index.html</welcome-file>
  <welcome-file>index.htm</welcome-file>
  <welcome-file>index.jsp</welcome-file>
  <welcome-file>default.html</welcome-file>
  <welcome-file>default.htm</welcome-file>
  <welcome-file>default.jsp</welcome-file>
 </welcome-file-list>
 <filter>
  <filter-name>TestFilter</filter-name>
   <filter-class>test.TestFilter</filter-class>
 </filter>
 
 <filter-mapping>
        <filter-name>TestFilter</filter-name>
 <url-pattern>*.nhn</url-pattern>
    </filter-mapping>

</web-app>

 

 

 package test;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class TestFilter implements Filter {


 public void destroy() {
 }

 @Override
 public void doFilter(ServletRequest req, ServletResponse res,
   FilterChain arg2) throws IOException, ServletException {
  RequestDispatcher dispatcher = req.getRequestDispatcher("/MyError.jsp");
  dispatcher.forward(req, res);
  
 }

 @Override
 public void init(FilterConfig arg0) throws ServletException {
  // TODO Auto-generated method stub
  
 }
}

History

Last edited on 04/16/2008 20:54 by benelog

Comments (0)

You must log in to leave a comment. Please sign in.