struts 2 tile NoSuchDefinitionException [英] struts 2 tiles NoSuchDefinitionException

查看:308
本文介绍了struts 2 tile NoSuchDefinitionException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用struts 2和tile时遇到这个异常

I am getting this exception when using struts 2 with tiles

org.apache.tiles.definition.NoSuchDefinitionException:/index.jsp

org.apache.tiles.definition.NoSuchDefinitionException: /index.jsp

// tiles.xml

//tiles.xml

<tiles-definitions>
<definition name="baseLayout" template="/index.jsp">
    <put-attribute name="title" value="/Template" />
    <put-attribute name="header" value="/Header.jsp" />
    <put-attribute name="menu" value="/Menu.jsp" />
    <put-attribute name="body" value="/body.jsp" />
    <put-attribute name="footer" value="/Footer.jsp" />
</definition>
<tiles-definitions>

// index.jsp

//index.jsp

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<tiles:insertAttribute name="header"/>
<tiles:insertAttribute name="footer"/>   
</body>
</html>

// web.xml

//web.xml

<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.  
DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>

// struts.xml

//struts.xml

    <package name="default" namespace="/test" extends="struts-default">
    <result-types>
    <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
    </result-types>

    <action name="login" class="com.medics.action.LoginAction">
        <result name="SUCCESS" type="tiles">/index.jsp</result>
    </action>
    </package> 

我搜索了很多,但没有发现

I have searched a lot but found nothing

推荐答案

org.apache.tiles.definition.NoSuchDefinitionException: /index.jsp

意味着没有瓷砖定义,这是没有定义的名称/index.jsp

Means that there is no tiles definition, that is no definition of the name "/index.jsp"

当使用struts和tile ...你的请求进入struts,然后到瓷砖组成视图的瓷砖,所以你不应该有任何瓷砖定义叫anything.jsp。

When using struts and tiles... Your request comes into struts then out to tiles where tiles composes the view so you shouldn't have any tiles definitions called "anything.jsp".

所以只需替换

<result name="SUCCESS" type="tiles">/index.jsp</result>

<result name="SUCCESS" type="tiles">baseLayout/result>

现在已经解决了...我将重命名index.jsp,template.jsp(我认为是少混淆),为什么你有一个put属性叫做/ Template?

Now that is resolved... I would rename index.jsp, template.jsp (I think it's less confusing), why do you have a put-attribute called "/Template" ?

现在要解决此问题,我建议您将struts2结果目标更改为baseLayout,但这可能不是您的意思,因此您可能希望使用baseLayout定义新页面,以便添加一个新的定义:

Now to fix the issue I recommended that you change the struts2 result target to "baseLayout" but this is probably not what you mean, so you probably want to use your baseLayout definition for new pages so add a new definition:

<definition name="index" extends="baseLayout">
  <put-attribute name="title" value="My Title for Index" />
  <put-attribute name="body" value="/index.jsp" />
</definition>

现在上面将在defaultTemplate中使用该值,并添加(或如果名称相同,则覆盖)在基本模板中创建了一个index.jsp的页面,现在你的struts.xml应该有

Now the above will take that value in defaultTemplate and add (or if the name is the same, override) what was in the base template creating a page for index.jsp, and now your struts.xml should have

 <result name="SUCCESS" type="tiles">index</result>

这篇关于struts 2 tile NoSuchDefinitionException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆