views:

32

answers:

2

Hi.

I'm using struts2, now in my jsp file i've got 2 variables:

${server_address}
${pageContext.request.contextPath}

Now i want to connect it in my tag:

<s:form action="%{server_address}%{pageContext.request.contextPath}/actionName.action">

But generated output looks like that:

<form method="post" action="http://10.0.0.5:8088/actionName.action" name="actionName" id="actionName">

There is no contextPath... How can i connect this two variable ?

+2  A: 

Use ${pageContext} instead of %{pageContext}. The pageContext isn't available in Struts2's scope, but in JSP's scope.

BalusC
Ok, that's part of solution i need. Now how can i add ${pageContext} to action in form above? I've got this exception if i use $ instead of %: According to TLD or attribute directive in tag file, attribute value does not accept any expressions
tzim
Sorry, I don't do Struts2. Without going into code detail, I'd say that you basically need to grab the `HttpServletRequest` somehow in your Struts2 bean and then delegate it. As a completely different advice, use the HTML `<base>` tag for this.
BalusC
Ok, i found it. ${attr.request['javax.servlet.forward.context_path']} but still, how can i connect 2 or more string variable to new one or how can i add those 2 variable to my s:form so it will works ?
tzim
+1  A: 

Try something like this

<s:set var="baseUrl">${server_address}${pageContext.request.contextPath}</s:set>

<s:set var="actionUrl">${baseUrl}<s:url action="actionName"/></s:set>

<s:form action="%{actionUrl}">
`enter code here`...
</s:form>
Monku
Works like a charm! <s:set var="sth">${server_address}${attr.request['javax.servlet.forward.context_path']}</s:set>
tzim