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 Problem in struts DispatchAction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem in struts DispatchAction" Watch "Problem in struts DispatchAction" New topic
Author

Problem in struts DispatchAction

vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
Hi friends,

I am having problem with struts dispatch action.
In my form action, iam concatenating action path with additional parameter and using method as GET..
when i submit, the additional parameter is not going and my form parameters are going..

But using POST, I am able to send the additional parameter also..

can anyone tell me y this is happening?

Thanks in Advance,


Thanks
Vipul Kumar
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Hi vipul,

Can you please put some code you are trying?


Thanks,
Shailesh
vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
Thanks for your reply shailesh.

This is the form iam using. I am concatenating a string with the action attribute path,i.e.DispatchAction Method.
<form action="setValues.do?method=execute" method="get">
First Name:<input type="text" name="t1" value=""/>
Last Name:<input type="text" name="t1" value=""/>
Middle Name:<input type="submit" value="submit"/>
</form>

my struts-config.xml file
<struts-config>
<form-beans>
<form-bean name="myPath" type="com.spry.forms.ValueFB"/>
</form-beans>
<action-mappings>
<action name="myPath" path="/setValues" type="com.spry.actions.ValueDispatchAction" parameter="method"/>
</action-mappings>
</struts-config>

when i use method="get", i am getting dispatch action method not found..
but this problem resolved,when i used method="post"..

Actually what i need to know is the reason why the dispatch action method not found when i used method="get".

Please tell me..

Thanks in Advance,
vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
Any one please reply to the post..!
Vicky Vijay
Ranch Hand

Joined: Apr 23, 2008
Posts: 125
vipul,

which verion of struts you are using ?

Try using the Struts based tags..

html:form, html:text... etc



vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
I am using struts 1.2..
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Vipul,
There should not be any problem, could you please post the complete exception stack trace. Also verify the "security-constraint" specification in your deployment descriptor.


Have Fun with Java
little,little.. little by little makes a lot..
vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218



my form is



work on this sample form.....copy to to your html page...write a dispatch action with method "doWork" in it. configure doWork in struts-config.xml file...An ActionForm..

work on it ..You will be getting above stack trace...

For post form is working as expected..

I just want to know the reason..Already i am working on it..any suggestions are acceptable...

Thanks
BVR
vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
I debugged into RequestProcessor class.

In processActionPerform() which takes request, response, action, form, mapping as arguments DispatchAction execute() is called. In that method,

from mapping object got the parameter.



if mapping object is not there then response.sendError is done..

I got my paramter object as method.
when retrieving method value i am getting null..




here name , iam getting null value


This happens for form method="get" request only..

For Post request it is working fine...

Please tell me what is happening with get and post requests in DispatchAction...

i mean to say is





with get and post as method values and DispatchAction as the page controller.....
vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
After debugging into more, i found why the method value is not coming.

we assosciated method="doWork" as queryparameter to the form action..when we click on submit browser is creating its query parameter removing what we assosciated.

for the post it is working . here browser is adding form parameters to the body not to the url..for the post DispatchAction is not creating any problem..
For get problem is coming...

Why browser is removing the query parameter what we have attached..?
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Vipul, no tools to set it up
I am still sure about dispatch action, that it doesnt do something like that.
But after looking couple of times into the code posted, i realized that you are not using html:form. Just let us know if the result changes after using struts-html tag. I am expecting the same result - it should fail
If i remember properly, if the html form submission is of type GET, then it would take the 'action' mentioned and append '?' followed by appending the form data [anybody please correct me if I am wrong]
So the above submission would be something like 'doWork.do?method=doWork?&first=something'. Now if we give something like this to struts, I do not know how it would behave - we have to look into the implementation.
Since you already have a debug environment could you please check and see [by retrieving HttpServletRequest.getRequestURL()] if my understanding is correct/wrong.

Thank you in advance
vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
Shankar Tanikella wrote:
If i remember properly, if the html form submission is of type GET, then it would take the 'action' mentioned and append '?' followed by appending the form data [anybody please correct me if I am wrong]
So the above submission would be something like 'doWork.do?method=doWork?&first=something'


You are right shankar.

More over we no need to check the reqeust object. we can see the url in the browser address bar. As the request is a GET request you can see the whole query parameter in the address bar. there you won't find method=doWork parameter. Remaining form parameters will be available.




Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Good, so that answers our doubt
vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
YES..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in struts DispatchAction