Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2: Accessing a request Parameter from Action

 
Abdul Mujeeb Md
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Abdul Mujeeb Md
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit,

This works.
 
vikas sharmaa
Ranch Hand
Posts: 191
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Try to get the request Object this way:



Add this code in your Action.

Hope this works

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,

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

 
vikas sharmaa
Ranch Hand
Posts: 191
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:You haven't included any configuration information, so it's impossible to help.
 
vikas sharmaa
Ranch Hand
Posts: 191
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi newton,

please find below my configuration files:

struts.xml




web.xml

 
vikas sharmaa
Ranch Hand
Posts: 191
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
newton,

had i provided all the required configuration infos? or something is missing. please tell me.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 191
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic