Problem in struts2 tiles plug-in.
I want to componentization my project by using struts2 tiles plug-in. The tiles.xml file I have written is like this:
<tiles-definitions>
<definition name="indexBaseLayout" template="/indexBaseLayout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="topBar" value="/topbar.action" />
<put-attribute name="catalog" value="" />
<put-attribute name="searchForm" value="" />
<put-attribute name="main" value="" />
<put-attribute name="footer" value="" />
</definition>
<definition name="regInput.tiles" extends="indexBaseLayout">
<put-attribute name="title" value="注册" />
<put-attribute name="main" value="/reg/input.action" />
</definition>
<definition name="regSuccess.tiles" extends="indexBaseLayout">
<put-attribute name="title" value="注册" />
<put-attribute name="main" value="/reg_success.jsp" />
</definition>
<definition name="index.tiles" extends="indexBaseLayout">
<put-attribute name="title" value="主页" />
<put-attribute name="main" value="/i开发者_JAVA百科ndex.jsp" />
</definition>
And a part of struts.xml like this:
<package name="main" extends="struts-default" namespace="/">
<action name="topbar" class="topBarAction">
<result name="success">/topbar.jsp</result>
</action>
</package>
As you see, I put some action urls in put-attribute value. I thought they would be executed as struts actions and display the returned result view. But the fact is that the tiles plugin recognize "xxxx.action" as a file: java.io.FileNotFoundException: The requested resource (/bookstore/topbar.action) is not available. So is there any solution to insert an action's result view into tiles layouts?
As far as I know you can't execute an action from a tiles definition.
If you're trying to perform some logic on this jsp prior to rendering on all the other tiles results, another solution might be to use some asynchronous jquery calls to a struts action using the json plugin or something similar.
I'm not sure what your end goal is here, if you can describe what you're shooting for perhaps I can help more.
EDIT: further definition with using conditionals in a JSP
In your tiles definition you would reference the JSP as normal:
<definition name="indexBaseLayout" template="/indexBaseLayout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="topBar" value="/topbar.jsp" />
<put-attribute name="catalog" value="" />
<put-attribute name="searchForm" value="" />
<put-attribute name="main" value="" />
<put-attribute name="footer" value="" />
</definition>
In the JSP you would base what renders on a struts tag conditional:
<s:if test="%{#session.user != null && #session.user.Authenticated"}>
Welcome <s:property value="%{#session.user.name}" />
</s:if><s:else>
<%-- Login form goes here --%>
</s:else>
This solution gives you a way to check for user object in session, which is where I would probably be maintaining a user info object personally. If the user object is null or the boolean authenticated is false, then it will show the log in form, otherwise it will show the welcome message and perhaps a logout button.
精彩评论