aspose file tools*
The moose likes Struts and the fly likes Dispatch Action Issue/Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Dispatch Action Issue/Exception" Watch "Dispatch Action Issue/Exception" New topic
Author

Dispatch Action Issue/Exception

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi Friends,
I have written a simple program to understand the concept of Dispatch action. I am getting an exception in it. Following is the code.

DispatchActionExample.java
==================




DispatchActionForm.java
================



struts-config.xml
===========



I am getting the following exception everytime.




Tried to google it and saw the explanations given but could not resolve the exception. Please do help !!!

Thanks in advance.

Thanks and Regards,
Sid.
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi Friends,
Please do help !!! I am badly stuck and not able to move forward.

Thanks and Regards,
Sid.
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

DispatchAction needs a request parameter with name "parameter" whose value should define what method to execute in your action class.

ex., when you submit a add form, the action of form should look like "action=/dispatchAction?parameter=add"

You can also try to have hidden variable in your form as <input type="hidden" name="parameter" value="add"/>


- Chinna
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi Chinna,
I am attaching the code snippet for "dispatchAction.jsp". I have done exactly as you have mentioned. Still I am getting this error.

dispatchAction.jsp



If I directly hit the jsp's for e.g. "Cal Add section" then the URL formed is as follows in the address bar.
[url]
http://localhost:8080/struts/dispatchAction.do?parameter=add[/url]

and it shows the correct jsp.


Thanks and Regards,
Sid.
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi All,
To narrow down the search when I hit the URL http://localhost:8080/struts/dispatchAction.jsp it is showing the page properly and links are also working. So i think the .jsp page is working fine. What I think is that there is some issue in name OR parameter attribute in the <action> tag.




Please guide me on how to solve this issue.

Thanks and Regards,
Sid.
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

You can try to debug the problem in these ways.

1) When you hit the link, what is the url you see on the browser ? And at the same time, you can use FireBug to see if any other request parameters are sent.

Or

2) You can change your action class from DispatchAction to normal action (org.apache.struts.action.Action), and print the request parameter map, and see what request parameters are coming in the request.
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi Chinna,

1) When I hit the link I see the following link in the browser : http://localhost:8080/struts/dispatchAction.do

2) I changed the action class from DispatchAction to Action and printed the requestParameter Map. Following is the code snippet.



Following is the output :

14:43:45,193 INFO [ComposableRequestProcessor] Initializing composable request processor for module prefix ''
14:43:45,209 INFO [CreateAction] Initialize action of type: com.example.dispatchaction.DispatchActionExample
14:43:45,209 INFO [STDOUT] In execute method ::
14:43:45,209 INFO [STDOUT] null
14:43:45,209 INFO [STDOUT] Query String ::: null


But my thinking is that in the first hit it has to show the jsp (dispatchAction.jsp) which has the links so why would there be some request parameter. First it ought to show the jsp then only when I click on the link then it would send the request parameter.

Please do comment.

Thanks and Regards,
Sid.
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Siddharth Bhargava wrote:
I am getting the following exception everytime.



Sorry I have to go back to your first post, as there is some confusion. When are you seeing this problem exactly ?
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi Chinna,
I get this exception when I hit the URL : http://localhost:8080/struts. The flow is like this : On hitting this URL it would look for index.jsp. In index.jsp I have written the following code :



so it gets redirected to the dispatchAction in strtus-config.xml where we have the following :



Then it goes to the action-mapping :



Here its giving an exception.

I think the issue is in the "name" or the "parameter" attribute.

The URL http://localhost:8080/struts/dispatchAction.jsp is also working and its showing the links and the links are working as expected.

I am really surprised why its giving the exception : javax.servlet.ServletException: Request[/dispatchAction] does not contain handler parameter named 'parameter'. This may be caused by whitespace in the label text.

Thanks and Regards,
Sid.



Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Problem is in your global forward.

Why are you not sending parameter from there. As I said, your Dispatch Action always expects a parameter called "parameter".

Change your global forward to


Change your action class to DispatchAction before you test, after above change
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi Chinna,
I changed my action to DispatchAction. It worked and its showing the add page. But what I want is the dispatchAction.jsp page which has all the links and when click on the link then it would show the page. Basic aim is this.




Isn't it this the way it should happen ?



Thanks and Regards,
Sid.
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

Siddharth Bhargava wrote:

Isn't it this the way it should happen ?


You can do it anyway you want. If you want your dispatchAction.jsp should be shown first, then put that page entry in welcome-file list of your web.xml.
ashishk sharma
Greenhorn

Joined: Oct 23, 2008
Posts: 11
You can try replacing your Parameter="Parameter" TO Parameter="method"

Just try this and then hit the URL....
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi ashishk,
I already tried that. But unfortunately it didn't work. It gave the same exception.

Thanks and Regards,
Siddharth Bhargava.
abhishek malviya
Greenhorn

Joined: Jun 13, 2011
Posts: 2
try following syntax in jsp and remove hardcoding in global forward

<input type="submit" name="parameter" value="Add" />

<input type="submit" name="parameter" value="Delete" />

it is working ..
abhishek malviya
Greenhorn

Joined: Jun 13, 2011
Posts: 2
xx

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi Abhishek,
I am not using buttons. I am using hyperlinks. On clicking on a particular hyperlink a particular page appears.

Thanks and Regards,
Siddharth Bhargava
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dispatch Action Issue/Exception