java过滤器中如何转移地址?

06-05-14 aill
例如:我要把/user/userName这个地址影射到

/user/userIndex.jsp?userId=userName

我是这样做的:

  public void doFilter (ServletRequest request,
               ServletResponse response,
               FilterChain chain)
    {

      try
      {
        chain.doFilter (request, response);
        String name = ((HttpServletRequest)request).getRequestURI();
             String userName=name.substring(6);
    request.getRequestDispatcher("/user/userLoad.jsp?userId="+userName).forward(request,response);

      } catch (IOException io) {
        System.out.println ("IOException raised in UserIndexFilter");
      } catch (ServletException se) {
        System.out.println ("ServletException raised in UserIndexFilter");
      }
    }


提示的错误是:
java.lang.IllegalStateException: Cannot forward after response has been committed
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:368)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
	at webLoad.UserIndexFilter.doFilter(UserIndexFilter.java:34)

<p>

请问老大到底要怎么做?

banq
2006-05-15 18:12
chain.doFilter (request, response);是转移到下一个filter

而你又想forward到一个jsp,到底你想往哪里走?

一般在filter中不会forward到jsp的。

aill
2006-05-15 18:23
不好意思,学艺不精!

谢谢老大

猜你喜欢