Action 标签在 Struts 2 中不执行
我在使用 struts2 中的标记从 jsp 页面调用操作时遇到问题。 我有 login.jsp 文件:
<s:action name="headerMenu" executeResult="true" namespace="/menu"</s:action>
<s:form action="executeLogin">
<s:textfield name="username" label="Username"></s:textfield>
<s:password name="password" label="Password"></s:password>
<s:submit></s:submit>
</s:form>
headerMenu 操作在 header.jsp 中呈现结果:
<div id="menu">
<s:iterator value="menus">
<s:property escape="false" value="'<a href=\"'+path+'\" title=\"'+description+'\">'+title+'</a>'"/>
</s:iterator>
</div>
该 jsp 文件呈现来自 headerMenu 操作的 Action 类中的 LinkedList(命名菜单)的菜单。
访问“login.action”时,菜单呈现正常,但如果我在表单中输入数据,提交表单,并且提交有验证错误,我返回到页面,表单呈现正常,但菜单不见了。 我的页面中仍然有“...”,但没有菜单...这就像调用菜单的操作,但执行()方法没有执行...
有人可以帮我解决这个问题吗?
瓦西。
I have a problem invoking actions from my jsp pages with tag in struts2. I have the login.jsp file:
<s:action name="headerMenu" executeResult="true" namespace="/menu"</s:action>
<s:form action="executeLogin">
<s:textfield name="username" label="Username"></s:textfield>
<s:password name="password" label="Password"></s:password>
<s:submit></s:submit>
</s:form>
The headerMenu action renders the result in header.jsp:
<div id="menu">
<s:iterator value="menus">
<s:property escape="false" value="'<a href=\"'+path+'\" title=\"'+description+'\">'+title+'</a>'"/>
</s:iterator>
</div>
This jsp file renders a menu that comes from a LinkedList (named menus) in the Action class of headerMenu action.
When accessing the "login.action", the menu is rendered fine, but if I enter data in the form, the submit the form, and submission has validation errors, I return to the page, the form is rendered ok, but the menu is missing. I still have "..." in the page, but no menu... It is like the action that gives the menu is invoked but the execute() method does not execute...
Can somebody please help me with this?
Vasi.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意第一行。 s:action 标签未正确关闭。 应该是这样的:
Please pay attention to the 1st line. The s:action tag is not closed properly. It should be as follows:
我正在研究原因是否可能与 struts2 标签文档中的以下 2 个片段有关:
“在 struts.xml 中为此操作定义的任何结果处理器都将被忽略,除非指定了executeResult 参数。”
“在评估整个标签之前,该操作不会发布到上下文,这意味着在标签体内,无法访问该操作”
I'd be looking into whether the cause might be related to the following 2 snippets from the struts2 tag documentation:
"Any result processor defined for this action in struts.xml will be ignored, unless the executeResult parameter is specified."
"The action will not be published to the context until the whole tag is evaluated, meaning that inside the body of the tag, the action cannot be accessed"