java過濾器中如何轉移地址?

aill發表於2006-05-14
例如:我要把/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 class="indent">


請問老大到底要怎麼做?

相關文章