This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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 ]
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 ?
Joined: Feb 15, 2005
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 ]