2 lxm yl lxm_yl 于 2015.05.27 17:21 提问

struts2整合sitemesh无法访问action问题 5C

struts2版本2.3.24

sitemesh2.4.2
应有的jar包都已加入
web.xml

 <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
    </filter>

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

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

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

decorators.xml

 <decorators defaultdir="/WEB-INF/decorators/">  
    <excludes>
        <pattern>/login.jsp</pattern>
        <pattern>/common/**</pattern>
    </excludes>
    <decorator name="main" page="default.jsp">  
        <pattern>/*</pattern>  
    </decorator>  
</decorators> 

这时候直接访问http://localhost:8080/login.jsp是正确的,没有被装饰,
访问http://localhost:8080/test/test.jsp是被装饰了的。
但是通过action跳转http://localhost:8080/login.action---result返回test/test.jsp
直接报空指针异常(ps:action里面没有任何业务代码,就是一个return success),异常信息:

 java.lang.NullPointerException
    at org.apache.struts2.components.ServletUrlRenderer.renderUrl(ServletUrlRenderer.java:80)
    at org.apache.struts2.components.URL.end(URL.java:147)
    at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
    at org.apache.jsp.WEB_002dINF.decorators.default_jsp._jspx_meth_s_005furl_005f0(default_jsp.java:307)
    at org.apache.jsp.WEB_002dINF.decorators.default_jsp._jspService(default_jsp.java:100)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543)
    at com.opensymphony.sitemesh.compatability.OldDecorator2NewDecorator.render(OldDecorator2NewDecorator.java:46)
    at com.opensymphony.sitemesh.webapp.decorator.BaseWebAppDecorator.render(BaseWebAppDecorator.java:33)
    at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:84)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

根据异常信息看是是被sitemesh的filter过滤了,struts2的action都没进入,不知怎么回事,网上说加入ActionContextCleanUp,但是这个类已经过时了

3个回答

renshiqiang123
renshiqiang123   2015.05.27 18:17

满烦你把decorators.xml改成struts。xml然后看看struts。xml格式



<!-- 初始化应用环境清单查询页面 -->

/pages/docinfo/envlistpub/EnvListPubQuery.jsp

<!-- 初始化灾备环境清单查询页面 -->

/pages/docinfo/disaterenvlistpub/DisaterEnvListPubQuery.jsp
/pages/docinfo/disaterenvlistpub/DisaterEnvListPubQuery.jsp

lxm_yl
lxm_yl decorators.xml改成struts。xml???有struts.xml文件额
2 年多之前 回复
qq_26313453
qq_26313453   2015.05.27 20:28

你没有加入struts2的配置文件,可以自己加一个,吧web.xml里面的代码全部复制到struts2,估计就行了

qq_16794101
qq_16794101   2015.05.27 23:19

你没有加入struts2的配置文件,可以自己加一个,吧web.xml里面的代码全部复制到struts2,估计就行了

lxm_yl
lxm_yl 吧web.xml里面的代码全部复制到struts2 这是什么意思,有struts.xml文件的
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片