现在的位置: 首页 > 综合 > 正文

struts2 tiles 模块异常 花费了我一天的时间

2013年10月28日 ⁄ 综合 ⁄ 共 3776字 ⁄ 字号 评论关闭
30元程序员衣装优惠券,仅剩3天!点击领取
javax.servlet.ServletException: java.lang.NullPointerException
	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:518)
	org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421)

root cause

java.lang.NullPointerException
	org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:104)
	org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
	com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:343)
	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
	com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:213)
	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
	com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
	com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
	com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
	org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
	com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
	com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
	com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
	com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
	com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
	com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
	com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
	com.opensymphony.xwork2.interceptor.ParametersInterceptor.intercept(ParametersInterceptor.java:161)
	com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
	com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
	com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
	com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
	com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
	com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
	com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
原因:tomcat在加载web.xml文件 没有对tiles 的工厂实例化
解决一:在web.xml中添加:
	<context-param>
   <param-name>
    org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
   </param-name>
   <param-value>/WEB-INF/tiles-defs.xml</param-value>
  </context-param>

 <listener>
  <listener-class>
   org.apache.struts2.tiles.StrutsTilesListener
  </listener-class>
 </listener>
解决二:在web.xml添加
	<listener>
   <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
 </listener>
   
    <context-param>
   <param-name>definitions-config</param-name>
   <param-value>/WEB-INF/tiles-defs.xml</param-value>
 </context-param>

   
	
30元程>序员衣装优惠券,仅剩3天!点击领取

抱歉!评论已关闭.