Struts2锚标记不包括contextPath
%{#request.contextPath}
在 Struts2 中的 s:a 标记内不起作用。 (具体来说是 Struts 2.2.1。)有没有办法让它工作?它适用于其他 Struts2 标签。
以下是 Struts 2 项目中 JSP 文件中的两行,其上下文路径为“/websites”:
<s:a href="%{#request.contextPath}/clickme" theme="simple">Click here.</s:a>
<s:form method="post" action="%{#request.contextPath}/submitme" theme="simple"></s:form>
以下是输出:
<a href="/clickme">Click here.</a>
<form id="submitme" name="submitme" action="/websites/submitme" method="post"></form>
请注意,上下文路径离开了锚点,但包含在表单中。
PS 我不能在这里使用 ${#pageContext.request.contextPath}
因为 Struts2 标记中不允许使用 ${}
。此外,我努力保持一致。我通常也会尝试避免 ${}
因为它不会自动转义输出。
谢谢!
%{#request.contextPath}
doesn't work inside an s:a tag in Struts2. (Struts 2.2.1 to be specific.) Is there a way to make it work? It works in other Struts2 tags.
Here are two lines in a JSP file in a Struts 2 project whose context path is "/websites":
<s:a href="%{#request.contextPath}/clickme" theme="simple">Click here.</s:a>
<s:form method="post" action="%{#request.contextPath}/submitme" theme="simple"></s:form>
And here is the output:
<a href="/clickme">Click here.</a>
<form id="submitme" name="submitme" action="/websites/submitme" method="post"></form>
Notice that the context path is left off the anchor but is included in the form.
P.S. I can't use ${#pageContext.request.contextPath}
here because ${}
isn't allowed in Struts2 tags. Besides, I'm trying to be consistent. And I also try generally to avoid ${}
since it does not auto-escape the output.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该有效:
但是,您不应该这样做。当您需要 url 时,请使用
标记:顺便说一下,您不需要表单的 action 属性的上下文路径:
This should work:
However, you're not supposed to do this. When you need an url, use the
<s:url>
tag:By the way, you don't need a context path for the action attribute of a form:
Struts 2 支持
EL
吗?如果确实如此,您可以使用
${request.contextPath}
...Does Struts 2 support
EL
?You can use
${request.contextPath}
if it does....