aspose file tools*
The moose likes Servlets and the fly likes Why servlet has 3 names, and not 2??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why servlet has 3 names, and not 2???" Watch "Why servlet has 3 names, and not 2???" New topic
Author

Why servlet has 3 names, and not 2???

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
With reference to HFSJ, why servlet has three names:

1] public URL
2] deployment name
3] actual class path

I mean, I am not getting the need of 2nd name. We can have just 2 name and solve all the problems like maintenance while transfering resources (servlet), security etc.

is something wrong??

Thanks.
[ September 27, 2005: Message edited by: rathi ji ]
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
The name is used to map URL patterns to the servlet. Say for example you want all *.getimage to map to a certain servlet as well as *.getpic:

<servlet>
<servlet-name>myImageServlet</servlet-name>
<servlet-class>za.co.imageServer.MyImageServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>myImageServlet</servlet-name>
<url-pattern>*.getimage</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>myImageServlet</servlet-name>
<url-pattern>*.getpic</url-pattern>
</servlet-mapping>

as multiple patterns per mapping is not supported like this:
<servlet-mapping>
<servlet-name>myImageServlet</servlet-name>
<url-pattern>*.getimage</url-pattern>
<url-pattern>*.getpic</url-pattern>
</servlet-mapping>


We're doomed!!<br />Yay!!!<br />No that's bad Girr!!<br />Yay!!!
Annie Smith
Ranch Hand

Joined: Mar 05, 2005
Posts: 172
Originally posted by rathi ji:
With reference to HFSJ, why servlet has three names:

1] public URL
2] deployment name
3] actual class path

I mean, I am not getting the need of 2nd name. We can have just 2 name and solve all the problems like maintenance while transfering resources (servlet), security etc.


I have never read HFSJ, but as much as I understand, the deployment name is required to bind the servlet object to the container - it is the name with which the servlet container will be able to associate the instances of the servlet. The public URL will provide for the mapping to the URLs which would request the servlet invocation. The actual class path would mean the fully-qualified class name for the servlet.


Cheers!<br /><b>Annie</b>
Annie Smith
Ranch Hand

Joined: Mar 05, 2005
Posts: 172
In short, the deployment name (as you mention) is analogous to the JNDI name (or directory listing).
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Scheepers de Bruin:

as multiple patterns per mapping is not supported like this:
<servlet-mapping>
<servlet-name>myImageServlet</servlet-name>
<url-pattern>*.getimage</url-pattern>
<url-pattern>*.getpic</url-pattern>
</servlet-mapping>
.

Yes, But can't we have like this:

<servlet-mapping>
<servlet-class>myImageServlet</servlet-class>
<url-pattern>*.getimage</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-class>myImageServlet</servlet-class>
<url-pattern>*.getpic</url-pattern>
</servlet-mapping>

No need for <servlet-name> tag.

What problems it may give??

Thanks.
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
What if you want to use two seperate configured instances (using init-param tags) of the SAME class to handle x URL patterns each?

Are you going to specify a set of <init-param>s for each pattern of each instance?

<servlet>
<servlet-name>myGIFservlet</servlet-name>
<servlet-class>za.co.imageServer.MyImageServlet</servlet-class>
<init-param>
<param-name>extension</param-name>
<param-value>.gif</param-value>
</init-param>
</servlet>

<servlet>
<servlet-name>myJPGServlet</servlet-name>
<servlet-class>za.co.imageServer.MyImageServlet</servlet-class>
<init-param>
<param-name>extension</param-name>
<param-value>.jpg</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>myGIFServlet</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>myJPGServlet</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>myJPGServlet</servlet-name>
<url-pattern>*.jpeg</url-pattern>
</servlet-mapping>
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Is this the only reason???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61225
    
  66

"Scheepers de Bruin",

You have already been asked on at least one other occasion to adjust your display name to conform to JavaRanch standards.

Visit the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Be aware that accounts with invalid display names are closed.

bear
Forum bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
I'm pretty sure it's not the only reason, but it's a good enough reason for me. In developing frameworks, it's always a good idea to make it as extensible as possible.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why servlet has 3 names, and not 2???