Tag Archives: Servlet

web.xml 버전별로 정리

를 하려고 했지만…. 최근것만

4.0

은 언제 나오나

 

3.1

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
		 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
</web-app>

 

3.0

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
		 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
		 metadata-complete="true" version="3.0">
</web-app>

 

Sevlet Filter에서 Session 사용샘플

public class LoginFilter implements Filter{

	@Resource(name="userService")
	private UserService userService;

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		System.out.println("destroy");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		System.out.println("doFilter");

		HttpSession session = ((HttpServletRequest)request).getSession();

		User user = (User)session.getAttribute("auth");

		if(user==null){
			((HttpServletResponse)response).sendRedirect("");
		}

		User user2 = userService.get(user);

		//이거 꼭있어야 다음으로 넘어감
		chain.doFilter(request, response);

	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		System.out.println("init");

	}

}

별것은 아니지만 그냥 기록

필요한 사람이 있을지도 모르니