• 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

All about action servlet

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Guys
I am kinda new to struts.Well here is my doubt.We know that all the requests are handled by the action servlet.In order to achieve this,in web.xml,we do smthg like this:

<servlet-mapping>
<servlet-name>action</servlEt-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
This says that all the requests will be handled by the servlet named action,which is nothing but the action servlet.So,why only *.do??why not *.dont??Why not *.if??I mean is it a convention or is it somewhere casted in stone that it should be *.do only??If we can specify anything else also,other than do,then where shall we make the changes for the same in order for that to work??

Thanks
Anu
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anuj,
It's a convention - and in my opinion a poor one at that. I prefer the URLs not give away the implementation. What if I want to change away from Struts later. My users have URLs bookmarked. Now they don't make sense anymore.

If you want to change the pattern, it's easy to do - you just do it in the web.xml. I use a directory like "/a/*". (It's not really "a" - it's something with business meaning.)
 
Anuj Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:
If you want to change the pattern, it's easy to do - you just do it in the web.xml. I use a directory like "/a/*". (It's not really "a" - it's something with business meaning.)



Hi Jeanne,
Thank you so much for the reply.You said we can change it in web.xml.So where exactly in web.xml is it done?Which element is used for the same?Can you just quote a sample for me .Lets say now I want to do *.if,then where exactly in the web.xml will I specify?

Thanks
Anuj
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per my understanding, the .do extension is something created by the developer, therefore, you can use the extension you like . In the web.xml file you give both an internal name (which is obviously used internally only, not available for client requests) for each of your servlets and also a url pattern, which is what
the client will type to get the needed resource. The servlet itself obviously doesn't have a .do extension (it's a .class file), but the url pattern the client types does have a .do extension. Why? Because the developer mapped it this way in the web.xml. In short, the patterns mapped in the web.xml can have the extension YOU want them to have, or NO extension at all! I don't think the .do extension has particularly anything to do with struts.
 
Anuj Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rodrigo Bossini wrote:As per my understanding, the .do extension is something created by the developer, therefore, you can use the extension you like . In the web.xml file you give both an internal name (which is obviously used internally only, not available for client requests) for each of your servlets and also a url pattern, which is what
the client will type to get the needed resource. The servlet itself obviously doesn't have a .do extension (it's a .class file), but the url pattern the client types does have a .do extension. Why? Because the developer mapped it this way in the web.xml. In short, the patterns mapped in the web.xml can have the extension YOU want them to have, or NO extension at all! I don't think the .do extension has particularly anything to do with struts.



Hi All,
I read in the wrox publication's Jakarta struts book ,that the <html:form> tag evaluates the action value to .do.For example,if we give action=logon,and using <html:form>,then the html form tag evaluates the above action to logon.do.It basically appends .do extension to the action value.So thats why we give *.do in the web.xml,if using struts html:form tag in the struts application.
[size=24]Let me know if the book is correct .[size=24]
Thanks
Anuj
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.do is struts default extension which maps with the ActionServlets,
Source:
http://struts.apache.org/1.3.10/faqs/works.html

Note the extension .do in this URL. The extension causes your container (i.e. Tomcat) to call the ActionServlet, which sees the word "login" as the thing you want to do. The configuration is referenced, and your LoginAction is executed.



now you can't remove this .do but using some tricks (eg url rewrite) you can move around with .do extension.

Here is the master link for that:
http://www.lunatech-research.com/archives/2005/07/29/struts-urls
[Note: This things are suggested for the Struts perfectionist, so if you're thinking it for practice no problem]
 
Anuj Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sagar Rohankar wrote:.do is struts default extension which maps with the ActionServlets,
Source:
http://struts.apache.org/1.3.10/faqs/works.html

Note the extension .do in this URL. The extension causes your container (i.e. Tomcat) to call the ActionServlet, which sees the word "login" as the thing you want to do. The configuration is referenced, and your LoginAction is executed.



now you can't remove this .do but using some tricks (eg url rewrite) you can move around with .do extension.

Here is the master link for that:
http://www.lunatech-research.com/archives/2005/07/29/struts-urls
[Note: This things are suggested for the Struts perfectionist, so if you're thinking it for practice no problem]



In the struts.apache link,its mentioned" In the web.xml file, you configure the framework ActionServlet as the servlet that will handle all requests for a given mapping (usually the extension .do is used)."....its nowhere mentioned that .do is struts' default extension??
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anuj Singh wrote:....its nowhere mentioned that .do is struts' default extension??


If its not mention, dosen't mean the above statement is wrong, to be precise, I modify my statement like
.do is struts' default & fixed extension
 
reply
    Bookmark Topic Watch Topic
  • New Topic