Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
antonio alcantara
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it rendering correctly?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Believe me--we're all blind at some point or another :) Glad you figured it out, and welcome to JavaRanch!
 
antonio alcantara
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I guess! Thanks very much again, I didn't know this forum but I'll try to help if I can.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic