2013-04-01 107 views
1

我搜索了所有在這個網站上提出的問題,並嘗試所有的更改,但沒有運氣。所以在這裏張貼查詢:屬性找不到:NoSuchAttributeException在瓷磚與彈簧

我得到以下異常:

HTTP Status 500 - org.apache.tiles.template.NoSuchAttributeException: Attribute 'body' not found. 

type Exception report 

message org.apache.tiles.template.NoSuchAttributeException: Attribute 'body' not found. 

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

exception 

org.apache.jasper.JasperException: org.apache.tiles.template.NoSuchAttributeException: Attribute 'body' not found. 
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) 
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262) 
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180) 
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950) 
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) 
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 

root cause 

org.apache.tiles.template.NoSuchAttributeException: Attribute 'body' not found. 
    org.apache.tiles.template.DefaultAttributeResolver.computeAttribute(DefaultAttributeResolver.java:49) 
    org.apache.tiles.template.InsertAttributeModel.resolveAttribute(InsertAttributeModel.java:187) 
    org.apache.tiles.template.InsertAttributeModel.start(InsertAttributeModel.java:107) 
    org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:306) 
    org.apache.jsp.WEB_002dINF.views.home_jsp._jspx_meth_tiles_005finsertAttribute_005f0(home_jsp.java:146) 
    org.apache.jsp.WEB_002dINF.views.home_jsp._jspService(home_jsp.java:79) 
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) 
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262) 
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180) 
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950) 
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) 
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.35 logs. 
Apache Tomcat/7.0.35 

我有我的tiles.xml爲:

<tiles-definitions> 
    <definition name="base.definition" template="/WEB-INF/views/home.jsp"> 
     <put-attribute name="body" value="/WEB-INF/views/menu.jsp" /> 
    </definition> 
</tiles-definitions> 

最後我的servlet-context.xml中有以下條目:

<beans:bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/> 
    </beans:bean> 

    <!-- 
    <beans:bean id="viewResolver" 
    class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
    <beans:property name="viewClass"> 
     <beans:value> 
      org.springframework.web.servlet.view.tiles2.TilesView 
     </beans:value> 
    </beans:property> 
    </beans:bean> 
--> 
    <beans:bean id="tilesConfigurer" 
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> 
    <beans:property name="definitions"> 
     <beans:list> 
      <beans:value>/WEB-INF/tiles.xml</beans:value> 
     </beans:list> 
    </beans:property> 
    </beans:bean> 

有一些評論部分,因爲我試着從以前發佈的問題這個答案,但發生同樣的問題。

我的pom.xml有以下條目(只是要確定)

  <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-core</artifactId> 
     <version>2.2.2</version> 
     <type>jar</type> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-template</artifactId> 
     <version>2.2.2</version> 
     <type>jar</type> 
     <scope>compile</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-jsp</artifactId> 
     <version>2.2.2</version> 
     <type>jar</type> 
     <scope>compile</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-servlet</artifactId> 
     <version>2.2.2</version> 
     <type>jar</type> 
     <scope>compile</scope> 
    </dependency> 

我有這樣的代碼在我回到Home.jsp爲:

<tiles:insertAttribute name="body" /> 

而且我引入了menu.jsp是:

<ul> 
<li><a href="search.htm">Search</a></li> 
<li><a href="showMessages.htm">Messages</a></li> 
<li><a href="contacts.htm">My Contacts</a></li> 
<li><a href="change.htm">Password</a></li> 
<li><a href="logout.htm">Logout</a></li> 
</ul> 

請大家幫忙。如果需要其他東西,請詢問。 在此先感謝。

+0

我面臨同樣的問題。你有沒有得到任何解決方案? – ArunM

+0

其實是的。您必須首先創建一個基本定義,然後您必須擴展該定義以適應所有用法。 我現在編輯帖子。 –

+0

@ArunM:我認爲它也適用於你。 –

回答

2

我找到了答案在tiles.xml

的主要問題一些修改後它是不能直接使用的定義。你必須擴展它,然後才能使用它。

轉寄此我編輯的代碼:

<definition name="new.definition" template="/WEB-INF/layout/newlayout.jsp"> 
<put-attribute name="title" value="" /> 
<put-attribute name="body" value="" /> 
<put-attribute name="menu" value="" /> 
</definition> 

<definition name="choice" extends="new.definition"> 
<put-attribute name="title" value="" /> 
<put-attribute name="body" value="/WEB-INF/views/choice.jsp" /> 
<put-attribute name="menu" value="" /> 
<put-attribute name="right" value="" /> 
    </definition> 

<definition name="logout" extends="new.definition"> 
<put-attribute name="title" value="Logging out.." /> 
<put-attribute name="body" value="/WEB-INF/views/logout.jsp" /> 
<put-attribute name="menu" value="" /> 
<put-attribute name="right" value="" /> 
</definition> 

正如你所看到的,我最初創造了新的定義:「new.definition」,然後選擇退出,我擴展現有的定義。

+0

不幸的是我沒有爲我工作。我詳細的問題在這裏.. http://stackoverflow.com/questions/19947933/org-apache-tiles-template-nosuchattributeexception-attribute-dog-tiles-not-fo – ArunM