jQuery in Action, 3rd edition
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Why sometimes servlets have got .do extension (why this) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Why sometimes servlets have got .do extension (why this)" Watch "Why sometimes servlets have got .do extension (why this)" New topic

Why sometimes servlets have got .do extension (why this)

Tom Kowalski
Ranch Hand

Joined: Feb 17, 2009
Posts: 72
Hi, I have read HF three times, but I haven`t find an answer to this question: Why sometimes servlets have got extension .do - Even in HF, at the beginning of the book, a few of the servlets have got this extension. Now I open this site: https://www.suntrainingcatalogue.com/eduserv/chooseLocale.do and here is also this extension. So why .do ? :

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63542

It's a rather silly tradition from Struts 1.

[Asking smart questions] [About Bear] [Books by Bear]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
Why not? Does it matter?

Most of the time .do indicates that the Struts framework was used. It makes it easy to map all *.do requests to the Struts controller servlet. You wouldn't want to map *.jsp to the Struts servlet, because then you couldn't have any Struts-free .jsp pages; so something else is used.

Another reason might be backwards compatibility. Maybe a site was formerly implemented in Cold Fusion, resulting in lots of *.cf URLs that are all over the place. Instead of breaking all those URLs, you simply map *.cf to the JspServlet (in addition to *.jsp), and -presto!- all your *.cf pages can now contain JSP code instead of Cold Fusion code.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
let's say you have a web app, and one part of it is public to the whole world, the other part is only for registered users. ..

you could declare a security constraint that acts upon all urls that are mapped to /rootPath/secure

instad though, you could achieve the same goal by using a predefined extension for the secured part of you web app, something like <url-pattern>*.secure</url-pattern>

now, as for .do, do is a common extension for the Struts web framework.

The struts framework processes all it's request thru something called a front controller, to centralize navigation.

how it achieves this is by a simple filter that is invoked for every url that ends in .do

so in general, it is a common way to identifiy or dedicate or certain area or requirement in your web app.

as an example, imagine you offer a download service that offers short text documents for download.
You want to offer the text docs for direct download, but also in zip format,

so what you would do is create a filter that maps to urls that end in .zip which then wraps up the response into a ZipOutputStream.
this also encapsulates other code, since all you do is create a filter without touching further business classes

JDBCSupport - An easy to use, light-weight JDBC framework -
Tom Kowalski
Ranch Hand

Joined: Feb 17, 2009
Posts: 72
Thanks for the reply, I am grateful.
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
Would the servlets mapped to *.A and those mapped to *.B share the same ServletConfig or ServletContext ?


Experience and talent are independent of age
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
context yes - since the servlet context is one per web app ...

servlet config depends

if you have one servlet with two mappings, then it has the same ServletConfig

If you declare the same servlet in two different <servlet> tags, they get their own servlet config, as well as they each have their own instance ...
I agree. Here's the link: http://aspose.com/file-tools
subject: Why sometimes servlets have got .do extension (why this)
It's not a secret anymore!