• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Annie Smith
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Annie Smith
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In short, the deployment name (as you mention) is analogous to the JNDI name (or directory listing).
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this the only reason???
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Scheepers de Bruin
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic