struts - pass parameters to action

D

Daniel Wang

Hi all,

How do I pass parameters to an action?

For example, I want to use <html:link...> and have create a link like
/action/MyAction.do?id=1&other=2

How do I pass the "id" and "name" variable and their values? An example with
<html:link> (or if not appropriate, some other tag) would be appreciated.

Thanks in advance.
 
D

Daniel

I know about the link tag and my tag would look like:
<html:link
href="/somedirectory/action/UserEdit.do?id=${user.id}">${user.lastname}</html:link>

What I was hoping to do is use possibly use <html:link> and pass in some
parameters without actually adding
the "id" part to the to the href part, if you know what I mean. It seems
more object oriented if it's passed as parameters.. Or would <html:action>
do the trick? I just need an example somwhere.

Thanks.
 
B

blarkin13

i think you could do it this way:
- create a form around the link. its action is UserEdit.do
- instead of appending user.id to the query string, create a hidden
input field that has this value. name it correctly and you don't even
have to assign the value yourself. struts does it for you.
- when you click on the link, instead of linking, the form submits.

this is a little more work in your jsp file, but when you deal with
everything in your action, accessing this data would be easier.
 
D

Daniel Rohe

first possible solution:

<html:link action="/somedirectory/action/UserEdit" paramId="id"
paramName="user" paramProperty="id">${user.lastname}</html:link>

second possible solution:

<html:form action="/somedirectory/action/UserEdit">
<html:hidden name="user" property="id"/>
<html:submit />
</html:form>

In the first solutions you define a link to the action "UserEdit" with a
request parameter which name is "id" and the value is taken from the
property "id" of the bean with the name "user".
The second solution defines a form with a button and the same request
parameters.

Greetings
Daniel

Daniel said:
I know about the link tag and my tag would look like:
<html:link
href="/somedirectory/action/UserEdit.do?id=${user.id}">${user.lastname}</html:link>

What I was hoping to do is use possibly use <html:link> and pass in some
parameters without actually adding
the "id" part to the to the href part, if you know what I mean. It seems
more object oriented if it's passed as parameters.. Or would <html:action>
do the trick? I just need an example somwhere.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top