• Post Reply Bookmark Topic Watch Topic
  • New Topic

Three names for a servlet.  RSS feed

 
Pankaj Shet
Ranch Hand
Posts: 312
Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends,
I am planning to take SCWCD at the end of January.So I have started reading HFSJ.I am on the Chapter 2 page no.46 now.I am trying to understand the three names of the Servlets,but am not able to understand.
can anyone give the example for the same so that I can understand?

Second thing I am not able to understand is :
What do we mean by deployment of servlet?Why should one Deploy it?what is the purpose of deployment?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should ask questions in separate threads since it is easier for us to answer.

I'm not sure about the first question, you'll need to provide more information.

Servlets get 'deployed' since they exist inside a 'container'. The container, such as Tomcat, can run without any servlets, and when you deploy the servlet the container becomes aware of the Servlet and can make it behave properly.
 
Pranav Pal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pankaj Shet:

I am trying to understand the three names of the Servlets,but am not able to understand.
can anyone give the example for the same so that I can understand?


There are three names for a servlet:
(1)One that the client sees, i.e., the url of the servlet, which is specified in DD using <url-pattern> sub-element of <servlet-mapping> element.
(2)One which specifies the actual class name of the servlet (fully-qualified), which is specified in DD using <servlet-class> sub-element of <servlet> element.
(3)An internal name of the servlet which is used inside DD only to map between the <servlet> and the <servlet-mapping> elements. This name is specified in the DD using <servlet-name> sub-element of both <servlet> and <servlet-mapping> elements.

Example:
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so there aren't three names, there is the URL mapping, the class name, and a name the maps between the two.

This lets you have a Servlet class included multiple times (one for each servlet name) and then map a single servlet name to multiple URLs. 90% of the time you will have a servlet with one name, and a name with one URL mapping
 
Pankaj Shet
Ranch Hand
Posts: 312
Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your explainations,
I am mentioning what I have undersstod by looking at the book, and what you explained

name #1 i.e Register/RegisterMe is an
Html form,according to me which is stated as a public URL,it's not the name of the servlet?

After filling that form and submitting by HTTP GET or HTTP POST method it will go into container where DD or web.xml file lies.

After looking into the DD,it checks the <URL-Pattern> in the <Servlet Mapping>
then it checks the name #2 i.e EnrollServlet which is the Internal or alias name used inside <Servlet Name>sub-element of both <Servlet> and <Servlet Mapping>

and then looks for actual class name,in the <Servlet-Class>sub-element of <servlet>,name #3 i.e SignUpServlet.class is the name of the actual servlet on the server formed after compiling the java file.

this is how the Url is mapped to the actual servlet?

1 A Servlet has the path to the actual file,a file path name too.
this is not used anywhere?

2 Is enrollservlet i.e name #2 hide the actual Servlet as well as the the path to the actual servlet?

if enrollServlet hides the path to the actual servlet,then only flexibilty can be achieved?

if it hides only the actual servlet and not the the path to it,then flexibity cannot be achieved.

so the purpose of deployment is flexibilty?

Am I right?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!