말라
109
2015-12-04 09:38:55
7
4761

스프링 인터셉터 사용중 오류입니다.도와주세요!


안녕하십니까?

신입 개발자 인데 인터셉터 사용중에 오류가있어서 여쭤보려 질문 글을 올려봅니다

인터셉터class를 만들고 servlet-context.xml에 아래와 같이 설정을 해두었습니다.

<interceptors>

<interceptor>

<mapping path="/**"/>

<beans:bean class="***.com.interceptor.HeaderInterceptor"/>

</interceptor>

</interceptors>

근데 아래와 같은 에러가 계속 발생하면서 웹페이지가 깨져서 나오더라고요.

인터셉터에서 print 찍어보면 잘나오긴하는데 에러는 계속 출력됩니다.

저 인터셉터를 모든 명령어에 실행되도록 하려고 하는데 잘안되서 여쭤봅니다.


심각: Servlet.service() for servlet [appServlet] in context with path [/app] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

java.lang.NullPointerException

at *.com.interceptor.HeaderInterceptor.postHandle(HeaderInterceptor.java:33)

at org.springframework.web.servlet.HandlerExecutionChain.applyPostHandle(HandlerExecutionChain.java:152)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:966)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:745)


---------------------------------------------------------------------------------------------------------------------------------------

headerInterceptor 입니다

	@Inject
	ProductService productService;
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
		List<Category> list = productService.categoryList();
		
		modelAndView.addObject("category", list);
		
		//modelAndView.setViewName("/include/header");
		
		System.out.println("HeaderInterceptor"+list.get(0).getCategory_name());
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub

	}

아 그리고 servlet-context 에는 로그인 인터셉터도 설정되있는데 로그인인터셉터는 잘되더라고요..



<interceptors>
		<interceptor>
			<mapping path="/product/add" />
			<beans:bean class="com.interceptor.LoginInterceptor" />
		</interceptor>
		<interceptor>
			<mapping path="/product/order" />
			<beans:bean class="com.interceptor.LoginInterceptor" />
		</interceptor>
		<interceptor>
			<mapping path="/qnaboard register" />
			<beans:bean class="com.interceptor.LoginInterceptor" />
		</interceptor>
		<interceptor>
			<mapping path="/review/register" />
			<beans:bean class="com.interceptor.LoginInterceptor" />
		</interceptor>
		
	</interceptors>

문제점을 알려주시면 감사하겠습니다

0
0
  • 답변 7

  • catsfriend
    2k
    2015-12-04 09:59:22

    HeaderInterceptor.java:33 이게 어디 해당되는 부분이죵>?

    0
  • 말라
    109
    2015-12-04 09:59:30

    아그리고 , servlet-context.xml  에서 저 mapping path를 "/"이걸루만 해두면 메인페이지에서는 잘작동합니다.

    전체 명령어에서 쓰고 싶어서 /** 이걸쓰면 에러가 계속 나네요,,,저걸 잘못지정한건가여?


    0
  • 말라
    109
    2015-12-04 10:00:04

    catsfriend 님

    modelAndView.addObject("category", list);

    이부분입니다

    0
  • catsfriend
    2k
    2015-12-04 10:04:01

    변수들이 널인지 확인 해보셔야 할거 같애요

    HttpServletRequest request,

    HttpServletResponse response,

    Object handler,

    ModelAndView modelAndView

    요 변수들을 체크해보세용

    0
  • 말라
    109
    2015-12-04 10:08:49

    catsfriend 

    null을 확인하려 print 찍어봤는데 null 이 나오는건 없네여ㅜㅜ

    servlet-context.xml에서 인터셉터 설정 중 path = "/" 이 명령어만 선택하주면 잘되는데

    " /** " 이걸로만 했다하면 에러가 나네요 ㅠㅠ 저번에도 그렇고 catsfreind님 답변감사합니다

    0
  • catsfriend
    2k
    2015-12-04 10:22:08

    널 포인트 에러자체를 잡아야 할것 같은데요;

    메소드내에 코드 주석 처리하시고

    /** 로 바꾸신후 다시 값들 찍어보세요


    0
  • 말라
    109
    2015-12-04 11:59:55

    해결하였습니다

    preHandle 메소드에서 불러서 request.setAttribute 로 값을 넘겼습니다

    답변 감사합니다 :) ㅎㅎㅎ

    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.