How to create a hyperlink with href = request.getHeader("Referer") in struts2 tiles page

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to create a hyperlink with href = request.getHeader("Referer") in struts2 tiles page

Gurpreet-Singh
Hi there,

I am developing online store application using Struts2 tiles on bea weblogic server 10. I am trying to create a url on a Jsp tile page to show a link to the page from where its called like with this link user can navigate to previous page or calling page. I am trying to do this using request.getHeader("Referer").

Application flow is:
User navigates to particular item online webstore and then clicks on Purchase button. Now, user will be routed to its cooresponding action and depending upon result of this action, it will show the specific tile page configured in tiles.xml file. So, this result tile page should generate the link to previous page.

I am doing this as using following snippet:

Approach 1:

<s:url id="url" value="%{someUrl}" includeParams="none">
<s:param name="returnURL" value='%{#context.get(@org.apache.struts2.StrutsStatics@HTTP_REQUEST).getHeader("Referer")}' />
</s:url>
<s:a href="%{url}">URL</s:a>

So, it is giving the value of returnURL in the URL as follows:
returnURL=http%3A%2F%2Flocalhost%3A7001%2Fab%2FHTML%2FPurchaseOptions.action%3FprodId%3DCF24932

But it should give: http://localhost:7001/ab/HTML/PurchaseOptions.action?prodId=CF24932

I am not sure why it is converting the : / & characters in the parameter value. I tried to copy the value of returnURL parameter and pasted in a new broser window. But IE fails to to recognize this converted value.

Approach 2:

I tried to make the returnURL parameter as:
<s:param name="returnURL" value='request.getHeader("Referer")' />

But with this, it gives the error as: This attribute does not support request time values.

Approach 3:
I tried to make the returnURL parameter as:
<s:param name="returnURL" value="%{header['referer']" />
But this time, parameter doest not get appended to the url.

Please give pointer or any solution to make a hyperlink in a jsp tiles page with href property set to request.getHeader("Referer") in struts2 tiles.

Thanks
Gurpreet Singh