File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Passing params in a hyper-link, and NOT as request parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Passing params in a hyper-link, and NOT as request parameters" Watch "Passing params in a hyper-link, and NOT as request parameters" New topic
Author

Passing params in a hyper-link, and NOT as request parameters

Mallika R Kumar
Ranch Hand

Joined: Jan 21, 2004
Posts: 38
Hi,
I have an object that I iterate over, and generate rows of hyper-links in my jsp page. The way I'm constructing the href is:
in a for loop, I have the following:
<a href="/userShow.do?userValue="+dataList.get(i)%>" > <%=dataNameList.get(i)%></a>

A user sees a list of names, and clicking on any one of them will take them to userShow.do action, where they can see its details. But, the resulting page displays the userValue in the address bar, which is a sensitive piece of information.

What is the best way to pass the value from a loop, in a href, to the next action ?

Any response will be helpful.

Thanks,
Mallika.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I think you have to use hidden fields and do a post rather than a get.
Franck Tranchant
Ranch Hand

Joined: Aug 07, 2003
Posts: 75
Hi

You consider "userValue" as a sensitive piece of information and you use it as hypertext link label ??

Doesn't make sense to me...

Maybe use a "userId" instead of a full name then retrieve the associated "userValue" right in the "userShow" Action.
Or use a Form submit with hidden field for each row as proposed by Steven.
Or use a frame at your application top level to 'hide' actual Actions requests from address bar.


Franck<p>--------------------
Mallika R Kumar
Ranch Hand

Joined: Jan 21, 2004
Posts: 38
Hi,
Thanks for the responses. If I use a hidden input in the loop, then my actionform bean contains a list of values for the field, and picks the first value. This is not what I want to accomplish. How can I use post method, if I want to pass user values being generated dynamically in the loop ? If there were a submit button, and the dynamic value that needed to be passed for a field was not coming from a loop, then hidden input makes sense. But, based on the link a user clicks, I need to send that link's value. Other option is for me to have a key value mapping, for the name clicked on and its value, then populate my bean with this value, and do processing.
Will <html:link> pass values to my bean from the loop ? What is the best way to do this ?

Mallika.
Anil Sadi
Greenhorn

Joined: Jan 09, 2001
Posts: 23
Hi,

The follwing approach may help you:

<script language="javascript">
function enableLink(userValueParamValue) {
document.linkForm.userValueParam.value=userValueParamValue;
document.linkForm.action="/userShow.do";
document.linkForm.submit();
}
</script>

<html:form action="...">
....
....
<a href="#" onCick="enableLink('<%=dataNameList.get(i)%>')"><%=dataNameList.get(i)%></a>
...
...
</html:form>

<form name="linkForm">
<input type="hidden" name="userValueParam" value=""/>
</form>

Hope it helps!!!

Anil Sadineni
Mallika R Kumar
Ranch Hand

Joined: Jan 21, 2004
Posts: 38
Thanks so much for your responses. Anil, the onclick event did the trick! Thanks for the code, it was very helpful.

Mallika.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing params in a hyper-link, and NOT as request parameters