aspose file tools*
The moose likes Struts and the fly likes Struts2: Accessing a request Parameter from Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2: Accessing a request Parameter from Action " Watch "Struts2: Accessing a request Parameter from Action " New topic
Author

Struts2: Accessing a request Parameter from Action

Abdul Mujeeb Md
Greenhorn

Joined: Aug 25, 2008
Posts: 26
Hi,

I am using traditional Ajax and passing a hidden parameter to the Action, but when i try to retrieve this parameter value, it returns null.
What could be the reason for this?

Following code list the Ajax calling mechanism




When I try to retrieve the value for 'hdnLicenseNumber' it returns Null.

Thanks.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

What you are trying to do will not work. The AJAX request will not take any form values in the request. You might add the request parameter in the request URL like



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abdul Mujeeb Md
Greenhorn

Joined: Aug 25, 2008
Posts: 26
Thanks Ankit,

This works.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
how to get the request sent by ajax call in the action class?

I have written the below code:



but, on call of ajax function, nether setServletRequest nor execute method is getting called.

below is my ajax function in welcome.jsp file:



please let me know, where i am going wrong. thank you
Abdul Mujeeb Md
Greenhorn

Joined: Aug 25, 2008
Posts: 26
Hi,

Try to get the request Object this way:



Add this code in your Action.

Hope this works

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You haven't included any configuration information, so it's impossible to help.

Are you really not using a JavaScript library to handle the Ajax stuff? It's sooooo much easier and cleaner.
Abdul Mujeeb Md
Greenhorn

Joined: Aug 25, 2008
Posts: 26
David,

I haven't explored on it yet. Will catch on it soon.

vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
Newton,

i am not using any JavaScript library to handle the Ajax stuff. i just follow w3school site tutorial. please help me.

Abdul Mujeeb Md wrote:
Try to get the request Object this way:





i can try it. but first either setServletRequest or execute method should get call. in my case, action class is not getting called on sending request from the ajax method.

please help.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

David Newton wrote:You haven't included any configuration information, so it's impossible to help.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
hi newton,

please find below my configuration files:

struts.xml




web.xml

vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
newton,

had i provided all the required configuration infos? or something is missing. please tell me.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And the app context is "Simple"? If so, it's not immediately obvious to me what's wrong.

Try using the config-browser plugin to see what S2 thinks your configuration is, and turn up logging to see if there are any startup issues or errors during the request processing.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
on the tomcat console, below warning is coming:

WARNING: No configuration found for the specified action: 'HelloWorld.action' in
namespace: '/'. Form action defaulting to 'action' attribute's literal value.

but my HelloWorld action class is called and return SUCCESS. then opening welcome.jsp page. HelloWorld action class is not getting called from ajax function only.

if ajax is not able to call the action class because of above warning then how could i fix this warning.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts2: Accessing a request Parameter from Action