aspose file tools*
The moose likes Struts and the fly likes How to pass  parameters from the Jsp to the Action file in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to pass  parameters from the Jsp to the Action file in Struts 2" Watch "How to pass  parameters from the Jsp to the Action file in Struts 2" New topic
Author

How to pass parameters from the Jsp to the Action file in Struts 2

antonio alcantara
Greenhorn

Joined: May 06, 2010
Posts: 8
Hi all

I have a link in my jsp file and I need to pass the text on the link to the action file.

Does anybody know how to do it?

I've tried this (just trying to get at least the name of the action to execute in the "execute()" method)

<a href="<s:action name="management"><s:param name="action">showBook</s:param></s:action></a>

But when it gets to the action, the param "action" is null. Any idea?

Thanks very much
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is it rendering correctly?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not sure why you're doing it that way, though; there are cleaner, built-in mechanisms for defining specific action methods to execute for a link. Why roll your own?
antonio alcantara
Greenhorn

Joined: May 06, 2010
Posts: 8
Hi David

And thanks very much for answering the question. I'm new to Struts 2 and I don't know how to do it. I need to launch the action when clicking the link, and I need to pass the text in the link to the action file in order to search it in the database. Can you give me any advice on how to do it please?
antonio alcantara
Greenhorn

Joined: May 06, 2010
Posts: 8
Before using s:action I was using this

<a href="<s:url action="management"><s:param name="action">showBook</s:param><s:param name="name"><s:property value="title"/></s:param></s:url>"

That was working the way I wanted, but if the title had non ascii characters the text that I got in "name" in the action file was incorrect, so it wouldn't find anything in the database.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's an encoding issue, not Struts, though.

It strikes me as risky to assume that two books will never have the same title, though--it'd be better, and avoid the encoding issue, if you just used a unique ID.
antonio alcantara
Greenhorn

Joined: May 06, 2010
Posts: 8
You're completely right. How can I be so blind. Thanks very much for your help. Now it works perfectly sending the Id from the jsp to the action file. Chapeau. Great job yours in this forum. Thanks again
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Believe me--we're all blind at some point or another :) Glad you figured it out, and welcome to JavaRanch!
antonio alcantara
Greenhorn

Joined: May 06, 2010
Posts: 8
Yeah, I guess! Thanks very much again, I didn't know this forum but I'll try to help if I can.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass parameters from the Jsp to the Action file in Struts 2