aspose file tools*
The moose likes Struts and the fly likes Cannot retrieve mapping for action 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 "Cannot retrieve mapping for action " Watch "Cannot retrieve mapping for action " New topic
Author

Cannot retrieve mapping for action

Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
I am trying to get some sample struts code I got off the web to run.
I am using the resin webserver. I copied the struts-blank.war over. bounced resin. renamed it to 'myproject'.

I am getting:



The instructions say to put this jsp in the top level directory under myproject.




Here is my struts-config.xml. it is in myproject/WEB-INF


here is the web.xml the tutorial said to use

Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
sorry for the double post. I put this in JSP forum also. I just noticed the struts forum.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Change

<html:form action="submit.do">

to

<html:form action="submit">

in your JSP.


Merrill
Consultant, Sima Solutions
Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
when do you use .do ?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
When you're specifying an action attribute inside a struts tag, as with <html:form> struts already knows you're referring to a Struts Action, so you don't want to append .do in this case.

When you call an action from the browser's URL line or from a non-struts tag, you're passing a URI to the App server that must be translated to a Struts action. The .do causes the URI to get referred to the struts ActionServlet where it can then call the appropriate Struts Action.

The answer to your question, then, is that you use the .do when calling an action from the URL line in the browser, or from a non-struts tag such as <a href="">.
[ January 19, 2006: Message edited by: Merrill Higginson ]
dnyan ginde
Ranch Hand

Joined: Jan 17, 2006
Posts: 68
I think it should work with "submit.do" too.
Amin Mohammed-Coleman
Greenhorn

Joined: Oct 18, 2004
Posts: 15
Make sure your SubmitAction class extends Action. Can we see your Action class?
Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
i get the exact same error when i remove .do
Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
here is my submitAction class



submitForm

Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
could it have something to do with not being able to find my struts-config.xml? I did copy the struts-blank.war file and rename it.

C:\resin-2.1.11\webapps\myproject\WEB-INF\struts-config.xml
Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
Here is my jsp after merrill's changes.

Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
i bounced the webserver and now it works.
Ryan G Johnson
Ranch Hand

Joined: Nov 11, 2004
Posts: 33
Merrill-- you said that the .do made struts look for my action class?

I have a submitAction.class file in: C:\resin-2.1.11\webapps\myproject\WEB-INF\classes\hansen\playground

is my mapping setup wrong in my struts-config.xml ?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
What I'm trying to get across is that passing a URI that ends in .do to the App Server causes the struts ActionServlet to be invoked. Here is the code in web.xml that makes this happen:



Once inside the Struts ActionServlet, Struts will then use the rest of the URI to determine which Action class to invoke. It does this by comparing the URI to the Action Mappings you've defined in struts-config.xml.

It's different, though, when you're using a Struts custom tag, such as <html:form>. The action atribute of this tag is expecting a Struts action mapping exactly as you have defined it in struts-config.xml. There is no action mapping for "/submit.do" in your xml file, and that's why it didn't work.

The principle here is that you use /myAction.do when passing a url in from the browser or from a link, and you use /myAction inside a Struts custom tag such as <html:form>

I'm a bit confused, though. You said it's working, right? If it's working, that means you set up your struts-config.xml file properly.
[ January 20, 2006: Message edited by: Merrill Higginson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot retrieve mapping for action