在controller中使用重定向其它域名问题

举例,在index方法中添加如下。

this.getResponse().sendRedirect("https://www.baidu.com");

return;


可以跳转但是会报错,这是什么情况?

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

[ERROR]-[Thread: http-nio-8080-exec-5]-[com.jfinal.core.ActionHandler.handle()]: /xxxx

com.jfinal.render.RenderException: java.lang.IllegalStateException: Cannot forward after response has been committed

at com.jfinal.render.JspRender.render(JspRender.java:69)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:97)

at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:75)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)

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

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

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

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

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

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

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)

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

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

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:745)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

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)

Caused by: java.lang.IllegalStateException: Cannot forward after response has been committed

at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:322)

at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311)

at com.jfinal.render.JspRender.render(JspRender.java:67)

... 21 more


评论区

JFinal

2017-01-07 01:16

重定向直接使用 redirect(url) 方法即可

如果一定要如楼主这样用,再多添加一行 renderNull() 也可以

热门反馈

扫码入社