ermao3545
the big fundmental
2010-05-13 18:23

Ajax的请求在struts2中怎么实现跳转

  • ext
  • javascript

我前台用的ext,所有请求都是Ajax的请求,然后我后台用的struts,配置了一个全局的权限拦截器。如果未登录就自动跳转到登陆界面。也配置了全局的跳转。

/login.jsp

但是因为是Ajax的请求,所以界面并不跳转。但是都可以在后台输出跳转
2010-05-13 17:05:49,281 DEBUG (org.apache.struts2.dispatcher.ServletRedirectResult:57) - Redirecting to finalLocation /graduation/login.jsp
用firedebug也有跳转到login.jsp的一个get方法。
后来想在拦截器里面直接用后台的代码跳转。
HttpServletRequest req = (HttpServletRequest) ctx.get(StrutsStatics.HTTP_REQUEST);
HttpServletResponse resp = (HttpServletResponse) ctx.get(StrutsStatics.HTTP_RESPONSE);
resp.sendRedirect(req.getContextPath()+"/login.jsp");

或者是 req.getRequestDispatcher("/login.jsp").forward(req, resp);
但是都会在后台报错:严重: Servlet.service() for servlet default threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:770)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:505)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
请教高手啦、、、、、

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

8条回答

为你推荐

换一换