Shortcut Struts2 does not include contextPath

%{#request.contextPath}doesn't work inside 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 the JSP file in the 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 conclusion:

<a href="/clickme">Click here.</a>
<form id="submitme" name="submitme" action="/websites/submitme" method="post"></form>

Please note that the context path is left unbound, but is included in the form.

PS I can’t use it ${#pageContext.request.contextPath}here because it’s ${}not allowed in Struts2 tags. In addition, I try to be consistent. And I also try to avoid it altogether ${}, as it does not automatically delete the output.

Thank!

+3
source share
2 answers

:

<s:set id="contextPath"  value="#request.get('javax.servlet.forward.context_path')" />
<s:a href="%{contextPath}/clickme" theme="simple">Click here.</s:a>

. URL-, <s:url>:

<%-- Without specifying an action --%>
<s:url id="myUrl" value="clickme" />
<s:a href="%{myUrl}" theme="simple">Click here.</s:a>

<%-- With an action --%>
<s:url id="myUrl" action="clickme" />
<s:a href="%{myUrl}" theme="simple">Click here.</s:a>

, :

<s:form method="post" action="submitme" theme="simple"></s:form>
+1

Struts 2 EL?

${request.contextPath}, ....

+1

Source: https://habr.com/ru/post/1770176/


All Articles