wood burning stoves 2.0*
The moose likes Servlets and the fly likes The server maintains one servlet instance per name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "The server maintains one servlet instance per name?" Watch "The server maintains one servlet instance per name?" New topic
Author

The server maintains one servlet instance per name?

Rakesh Mehra
Ranch Hand

Joined: Nov 20, 2007
Posts: 31
Help in understanding below highlighted in bold

Use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException
This method returns the servlet of the given name, or null if the servlet is not found. The specified name can be the servlet's registered name (such as "file") or its class name (such as "com.sun.server.webserver.FileServlet").
The server maintains one servlet instance per name, so getServlet("file") returns a different servlet instance than getServlet("com.sun.server.webserver.FileServlet")
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Where is the quote from?
Rakesh Mehra
Ranch Hand

Joined: Nov 20, 2007
Posts: 31
Originally posted by David O'Meara:
Where is the quote from?


Use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException
This method returns the servlet of the given name, or null if the servlet is not found. The specified name can be the servlet's registered name (such as "file") or its class name (such as "com.sun.server.webserver.FileServlet").
The server maintains one servlet instance per name, so getServlet("file") returns a different servlet instance than getServlet("com.sun.server.webserver.FileServlet").
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Originally posted by David O'Meara:
Where is the quote from?


Where is the quote from?
Rakesh Mehra
Ranch Hand

Joined: Nov 20, 2007
Posts: 31
Originally posted by David O'Meara:


Where is the quote from?


Help me in uderstanding below:

Use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException
This method returns the servlet of the given name, or null if the servlet is not found. The specified name can be the servlet's registered name (such as "file") or its class name (such as "com.sun.server.webserver.FileServlet"). The server maintains one servlet instance per name, so getServlet("file") returns a different servlet instance than getServlet("com.sun.server.webserver.FileServlet").
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41524
    
  53
What David is asking is where you copied that text from - a book, a web site, or someplace else?

As to your question, what do you think that sentence means? Tell us, and we'll chime in with comments.


Ping & DNS - my free Android networking tools app
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Maybe I'm being a bit slow, but I don't understand your question and I am, as Ulf suggests, asking for more information on the source to get some context on your question. Repeating your question is no more helpful than me repeating my request for more information.
Rakesh Mehra
Ranch Hand

Joined: Nov 20, 2007
Posts: 31
Originally posted by David O'Meara:


Where is the quote from?


Help me in uderstanding below:

Use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException
This method returns the servlet of the given name, or null if the servlet is not found. The specified name can be the servlet's registered name (such as "file") or its class name (such as "com.sun.server.webserver.FileServlet"). The server maintains one servlet instance per name, so getServlet("file") returns a different servlet instance than getServlet("com.sun.server.webserver.FileServlet").
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Originally posted by David O'Meara:
Repeating your question is no more helpful than me repeating my request for more information.
Rakesh Mehra
Ranch Hand

Joined: Nov 20, 2007
Posts: 31
Originally posted by David O'Meara:
Maybe I'm being a bit slow, but I don't understand your question and I am, as Ulf suggests, asking for more information on the source to get some context on your question. Repeating your question is no more helpful than me repeating my request for more information.


Chapter 11 of Java Servlet Programming

I'm reading a Chapter 11. Interservlet Communication which contains topic 11.1. Servlet Manipulation.i'm not able to uderstand it.
[ December 17, 2007: Message edited by: David O'Meara ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I had to edit your post, it contained a link to materials that are not free. I left the name of the book.

That book is almost 10 years old, and the current API for that class states the following:

getServlet(String name)
Deprecated. As of Java Servlet API 2.1, with no direct replacement.

This method was originally defined to retrieve a servlet from a ServletContext. In this version, this method always returns null and remains only to preserve binary compatibility. This method will be permanently removed in a future version of the Java Servlet API.

In lieu of this method, servlets can share information using the ServletContext class and can perform shared business logic by invoking methods on common non-servlet classes.


This means that the functionality you are refering to no longer exists officially and will be removed in a future version. Therefore you don't need to understand it!
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Howdy Rakesh Mehra,

David has clearly pointed out and i guess it helps. I think though its deprecated, it does NOT mean that it can be left without understanding.

But still what exactly you were NOT getting from the above pasted description?

As Ulf suggested, if you could let us know what you had thought on it, we could help you out in clearing the same.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Rakesh Mehra
Ranch Hand

Joined: Nov 20, 2007
Posts: 31
Originally posted by Raghavan Muthu:
Howdy Rakesh Mehra,

David has clearly pointed out and i guess it helps. I think though its deprecated, it does NOT mean that it can be left without understanding.

But still what exactly you were NOT getting from the above pasted description?

As Ulf suggested, if you could let us know what you had thought on it, we could help you out in clearing the same.





I'm trying to ubderstand the below highlighted bold line:

Use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException
This method returns the servlet of the given name, or null if the servlet is not found. The specified name can be the servlet's registered name (such as "file") or its class name (such as "com.sun.server.webserver.FileServlet"). The server maintains one servlet instance per name, so getServlet("file") returns a different servlet instance than getServlet("com.sun.server.webserver.FileServlet").


As i felt "one servlet instance per registered name".




Help me to clear my understanding on Servlet instance. I visualize servlet instance as below:

Suppose i register a servlet (eg. aaa.class) using following in deployment descriptor:
<servlet-class>aaa.class</servlet-class>
<servlet-name>demo</servlet-name>

so is it like: demo = new aaa();

[ December 17, 2007: Message edited by: David O'Meara ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Please don't provide a link to that resource, it is not free and legal.
I cannot stop you reading the book, even though it is 10 years old, but I can remove the links.

If you won't read our responses there is no point responding to your requests.


We want to help, but you are making this very frustrating for me. If you want help you will need to meet us half way.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Originally posted by Rakesh Mehra:
The server maintains one servlet instance per name, so "name" returns a different servlet instance than "com.sun.server.webserver.FileServlet"


OK, ignore the method name since it is not important to your query. Also, the method is deprecated and therefore should be avoided anyway.

When you write a Servlet class and deploy it, you provide a mapping in the web.xml file like this:



The servlet-class gets assigned a servlet-name, and the servlet-name gets matched to a url-pattern. This allows a servlet-class to have multiple servlet-names and a servlet-name to have multiple url-patterns.

But...

When you assign a class to a servlet-name, there is only a single instance of the Class created, and all requests to any URL that matches the pattern for that name all get passed to the one single Servlet instance. If your servlet maintains state (which is a bad thing) then all of those requests will share that state.

And...

Since you can map the servlet-class to multiple names, each of which will create a servlet Instance, then referring to the class matches multiple names, as stated in the text you highlighted.
Rakesh Mehra
Ranch Hand

Joined: Nov 20, 2007
Posts: 31
Originally posted by David O'Meara:


OK, ignore the method name since it is not important to your query. Also, the method is deprecated and therefore should be avoided anyway.

When you write a Servlet class and deploy it, you provide a mapping in the web.xml file like this:



The servlet-class gets assigned a servlet-name, and the servlet-name gets matched to a url-pattern. This allows a servlet-class to have multiple servlet-names and a servlet-name to have multiple url-patterns.

But...

When you assign a class to a servlet-name, there is only a single instance of the Class created, and all requests to any URL that matches the pattern for that name all get passed to the one single Servlet instance. If your servlet maintains state (which is a bad thing) then all of those requests will share that state.

And...

Since you can map the servlet-class to multiple names, each of which will create a servlet Instance, then referring to the class matches multiple names, as stated in the text you highlighted.



Thanks a lot
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

That's nice. Thank you David
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Hey we got a very nice bartender.

David, this is just to appreciate your patience here. Great job.
Thanks.
Rakesh Mehra
Ranch Hand

Joined: Nov 20, 2007
Posts: 31
Originally posted by David O'Meara:


OK, ignore the method name since it is not important to your query. Also, the method is deprecated and therefore should be avoided anyway.

When you write a Servlet class and deploy it, you provide a mapping in the web.xml file like this:



The servlet-class gets assigned a servlet-name, and the servlet-name gets matched to a url-pattern. This allows a servlet-class to have multiple servlet-names and a servlet-name to have multiple url-patterns.

But...

When you assign a class to a servlet-name, there is only a single instance of the Class created, and all requests to any URL that matches the pattern for that name all get passed to the one single Servlet instance. If your servlet maintains state (which is a bad thing) then all of those requests will share that state.

And...

Since you can map the servlet-class to multiple names, each of which will create a servlet Instance, then referring to the class matches multiple names, as stated in the text you highlighted.




Thanks a lot everybody ,helping me understand .
Rakesh Mehra
Ranch Hand

Joined: Nov 20, 2007
Posts: 31
Originally posted by David O'Meara:


OK, ignore the method name since it is not important to your query. Also, the method is deprecated and therefore should be avoided anyway.

When you write a Servlet class and deploy it, you provide a mapping in the web.xml file like this:



The servlet-class gets assigned a servlet-name, and the servlet-name gets matched to a url-pattern. This allows a servlet-class to have multiple servlet-names and a servlet-name to have multiple url-patterns.

But...

When you assign a class to a servlet-name, there is only a single instance of the Class created, and all requests to any URL that matches the pattern for that name all get passed to the one single Servlet instance. If your servlet maintains state (which is a bad thing) then all of those requests will share that state.

And...

Since you can map the servlet-class to multiple names, each of which will create a servlet Instance, then referring to the class matches multiple names, as stated in the text you highlighted.



Everybody Thanks a lot ....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The server maintains one servlet instance per name?