• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dispatch Action Issue/Exception

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
Please do help !!! I am badly stuck and not able to move forward.

Thanks and Regards,
Sid.
 
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"/>
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try replacing your Parameter="Parameter" TO Parameter="method"

Just try this and then hit the URL....
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ashishk,
I already tried that. But unfortunately it didn't work. It gave the same exception.

Thanks and Regards,
Siddharth Bhargava.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
xx

 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic