struts.xml看不到我的瓷砖

时间:2012-09-05 11:14:25

标签: java jsp struts2 tiles

嗨,我是Struts2中的新手,我有这样的问题

我用瓷砖写web应用程序 这是我的应用程序的结构

enter image description here

这是我的web.xml

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
    <listener-class>
        org.apache.struts2.tiles.StrutsTilesListener
    </listener-class>
</listener>
<context-param>
    <param-name>tilesDefinitions</param-name>
    <param-value>/WEB-INF/tile/tiles.xml</param-value>
</context-param>

这是我的tiles.xml

<tiles-definitions>
    <definition name="baseLayout" template="/jspf/base_layout/base_layout.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/jspf/header.jsp" />
        <put-attribute name="menu" value="/jspf/menu.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/jspf/footer.jsp" />
    </definition>
    <definition name="news.tiles" extends="baseLayout">
        <put-attribute name="title" value="index.title" />
        <put-attribute name="body" value="/jsp/news_list.jsp" />
    </definition>
    <definition name="create.tiles" extends="baseLayout">
        <put-attribute name="title" value="news.add" />
        <put-attribute name="body" value="/jsp/add_news.jsp" />
    </definition>
    <definition name="edit.tiles" extends="baseLayout">
        <put-attribute name="title" value="news.edit" />
        <put-attribute name="body" value="/jsp/edit_news.jsp" />
    </definition>
</tiles-definitions>

那是我的struts.xml

<struts>
    <constant name="struts.enable.DynamicMethodInvocation"
              value="false" />
    <constant name="struts.custom.i18n.resources" value="properties.locale" />
    <constant name="struts.devMode" value="false" />

    <package name="tiles" extends="struts-default" namespace="/">
        <result-types>
            <result-type name="tiles"
                         class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>
        <action name="newsList" class="by.bulgak.newsmanagement.action.NewsAction" >
            <result type="tiles">news.tiles</result>
        </action>
        <action name="addNewsForm" class="by.bulgak.newsmanagement.action.AddNewsFormAction">
            <result type="tiles">create.tiles</result>
        </action>
        <action name="editNewsForm" class="by.bulgak.newsmanagement.action.EditNewsFormAction">
            <result type="tiles">edit.tiles</result>
        </action>

        <action name="addNews" class="by.bulgak.newsmanagement.action.AddNewsAction">
            <result name="success"></result>
            <result name="error"></result>
        </action>

        <action name="deleteNews" class="by.bulgak.newsmanagement.action.DeleteNewsAction">
            <result name="success"></result>
            <result name="error"></result>
        </action>

        <action name="editNews" class="by.bulgak.newsmanagement.action.EditeNewsAction">
            <result name="success"></result>
            <result name="error"></result>
        </action>

        <action name="deleteNewsList" class="by.bulgak.newsmanagement.action.DeleteNewsListAction">
            <result name="success"></result>
            <result name="error"></result>
        </action>
    </package>
    <package name="locale" namespace="/" extends="struts-default">
        <action name="locale" class="by.bulgak.newsmanagement.action.LocaleAction">
            <result>index.jsp</result>
        </action>
    </package>
</struts>

当我添加所有图块

时,它就像这样

enter image description here

当我启动我的应用程序并调用addNews操作浏览器时显示我的这个

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.tiles.definition.NoSuchDefinitionException: news.tiles
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:578)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:246)
    org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105)
    org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
    com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.

请告诉我,我在哪里犯了错误

感谢)

1 个答案:

答案 0 :(得分:2)

在你的web.xml中输入这些条目。

 <context-param>
  <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
  <param-value>/WEB-INF/tile/tiles.xml,/org/apache/tiles/classpath-defs.xml</param-value>
 </context-param>