struts2 - WebSphere Application Server 8 (WAS 8) 上的 Struts 2 和自定义错误页面

标签 struts2 web.xml custom-error-pages websphere-8

我们正在将服务器从 WAS 7 迁移到 WAS 8,并面临 WAS 7 中不会发生的问题:如果请求无效 URL,WAS 7 会使用我们在 web.xml 中设置的自定义错误页面进行响应。 xml,这是一个JSP并使用Struts标签。然而,在 WAS 8 中,情况并非如此,并且会显示下面的错误页面/堆栈跟踪。仅当无效 URL 没有默认的 struts 扩展名时才会发生这种情况,因此我认为问题出在 web.xml 配置上,其代码片段显示在错误页面之后。



错误页/堆栈跟踪

Error Page Exception
SRVE0260E: The server cannot use the error page specified for your application to handle the Original Exception printed below.

Original Exception:
Error Message: javax.servlet.ServletException: java.io.FileNotFoundException: SRVE0190E: File not found: /whatever
Error Code: 404
Target Servlet: com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor
Error Stack:
java.io.FileNotFoundException: SRVE0190E: File not found: /whatever
     at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor._processEDR(DefaultExtensionProcessor.java:874)
     at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.processEDR(DefaultExtensionProcessor.java:855)
     at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:433)
     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:92)
     at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
     at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
     at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:919)
     at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1016)
     at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3703)
     at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
     at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:953)
     at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1655)
     at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
     at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
     at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
     at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
     at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
     at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
     at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
     at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
     at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
     at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
     at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)



Error Page Exception:
Error Message: The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
Error Code: 0
Target Servlet:
Error Stack:
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
     at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
     at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
     at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
     at com.ibm._jsp._error404._jspx_meth_s_i18n_0(_error404.java:374)
     at com.ibm._jsp._error404._jspService(_error404.java:108)
     at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
     at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1152)
     at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:722)
     at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:449)
     at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
     at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)
     at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:205)
     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
     at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:77)
     at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:919)
     at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1016)
     at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:1384)
     at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:193)
     at com.ibm.ws.webcontainer.webapp.WebApp.sendError(WebApp.java:3206)
     at com.ibm.ws.webcontainer.webapp.WebApp.handleException(WebApp.java:3733)
     at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3714)
     at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
     at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:953)
     at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1655)
     at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
     at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
     at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
     at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
     at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
     at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
     at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
     at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
     at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
     at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
     at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)

WEB.XML 片段

<filter>
    <filter-name>struts-cleanup</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<error-page>
    <error-code>404</error-code>
    <location>/error/error404.jsp</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/error/error500.jsp</location>
</error-page>

由于它在 WAS 7 上运行良好,我想知道我错过了什么?要让 struts 在 WAS 8 上处理自定义错误页面,是否需要进行任何配置更改?请注意,我们仍然使用完全相同的配置文件,并且仍然指向 2.4 servlet,如以下代码段所示:

<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

最佳答案

联系产品支持后,解决方案是向 web.xml 添加额外的映射,以使 ERROR 调度程序也映射到 Struts 过滤器,如下所示:

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/error/*</url-pattern>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

看来,在缺乏特定调度程序的映射的情况下,WAS 7 使用默认值,而 WAS 8 不会将请求传递给任何过滤器(因为没有映射)。

关于struts2 - WebSphere Application Server 8 (WAS 8) 上的 Struts 2 和自定义错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11868692/

相关文章:

java - struts2从2.3.16更新到2.3.32(修复S2-045)后,JSP文件无法解析某些Object的字段

java - 配置中的 Struts2 {}

java - Spring 应用程序上下文 : access web. xml 上下文参数?

java - 对于基于 Servlet 的 Java Web 应用程序,我真的需要 web.xml 吗?

php - Nginx、PHP + FPM 自定义错误页面

java - JSON Jquery 到 Struts2 Action

java - 将 session ID 传递到 Struts 2 中的 URL JSP 页面

java - 如何调用作为 jar 依赖项添加到另一个 Maven 项目的 axis2 Web 服务项目?

symfony - 通过覆盖ExceptionController的Symfony自定义错误页面

python - Django handler500 作为基于类的 View