레이블이 문제 해결인 게시물을 표시합니다. 모든 게시물 표시
레이블이 문제 해결인 게시물을 표시합니다. 모든 게시물 표시

2013년 1월 13일 일요일

@WebServlet annotation with Tomcat 7 and 404 error

@WebSerlvet annotation 을 사용해서 servlet 을 정의했지만 404 에러가 발생했다.
문제는 web.xml 파일에 metadata-complete 를 true 로 설정했기 때문이었다.

아래와 같이 metatdata-complete 를 false 로 설정해야 했다.

<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="false"
version="3.0">

!) eclipse 에서 프로젝트를 clean 하고 다시 build 해야 할 수도 있다.

2012년 11월 2일 금요일

HttpServletRequest 의 getServletContext() 함수 사용 문제

참고: http://stackoverflow.com/questions/7860782/request-getservletcontext-not-found-even-with-new-jar

JSP 페이지에서 request.getServletContext() 사용시 아래와 같은 에러가 발생했다.

The method getServletContext() is undefined for the type HttpServletRequest

Tomcat 7 에서는 문제가 되지 않았지만 tomcat6 에서는 문제가 되었다.

!) 원인은 HttpServletRequest 의 getServletContext() 함수는 Servlet 3.0 부터 지원되기 때문이었다. Tomcat7 부터 Servlet 3.0 을 지원한다.

그냥 getServletContext() 함수를 부르면 Tomcat 6 와 Tomcat 7 에서도 에러가 발생하지 않았다.

예)
<%= getServletContext().gerRealPath("/") %>