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 send id from jsp to struts action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "send id from jsp to struts action" Watch "send id from jsp to struts action" New topic
Author

send id from jsp to struts action

bubu lina
Greenhorn

Joined: Aug 11, 2008
Posts: 28
Hello
i have problems in sendint the id of a html selected option to a struts action. i use javascript to get the parameter and show it in an alert. it shows the correct value.


the js code:

but now in the strut action action:


I don't get why on request the value() is null......
any ideas? thank you

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

i have problems in sending the id of a html selected option to a struts action

This is a little confusing. Are you using an AJAX request to send request parameters, if yes, then show us the code for making the ajax request. Also as per what you said, the value is correct in JS but is null in the action, is it correct??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
How are you submitting the form? Maybe there is a submit button in another form, which gets submitted instead of this!


OCJP 6 (93%)
bubu lina
Greenhorn

Joined: Aug 11, 2008
Posts: 28
i am using just javascript to get the selected option.
this being a struts app, i have declared a bean in struts.xml that connects the action to the view. so from the action page i send data to the view page and when the user selects something i want to sent back a value on request.
this should have been as easy as that but something i am missing.
i first used a function(already tested in other examples) to get the value from request :


and so to get the value from the view i used:

This worked with a spring project.
and now here it does not.
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
You have to submit the form for the selected value to be available on the server side...
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1447
    
    6

i send data to the view page and when the user selects something i want to sent back a value on request.


Are you actually sending the value? In what way is the form getting submitted? Neither there seems to be any submit button nor there seems to be any ajax call?


Swastik
bubu lina
Greenhorn

Joined: Aug 11, 2008
Posts: 28


and on change in the form this function is called:" onchange="getNrRows(this);"
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Is this the only form on your page..?
bubu lina
Greenhorn

Joined: Aug 11, 2008
Posts: 28
yes
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1447
    
    6

So, where is the form getting submitted? What about the action??

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1447
    
    6

your form is not getting submitted through submit click, so form action attribute is not going to help. You are submitting through js call, so here you need to specify the action.
bubu lina
Greenhorn

Joined: Aug 11, 2008
Posts: 28
i specified in the form the name of the action. "/test.do".
or you are saying something else?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1447
    
    6

You need to specify the action url, whatever it is.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1447
    
    6

See my js code above

document.forms[0].action="url where the form is to be submitted"
bubu lina
Greenhorn

Joined: Aug 11, 2008
Posts: 28
you were right. Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: send id from jsp to struts action
 
Similar Threads
Onchange problem
Need Help to disable a check box.
Using Ajax with Struts
raw HTML in Mozilla
how to get html select's value in the bean