aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Deployment. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Deployment." Watch "Deployment." New topic
Author

Deployment.

Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 239

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?

please help me out?


PANKAJ SHET
B.Sc.(I.T.), S.C.J.P., S.C.W.C.D., PGDAC(CDAC)
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Well, two of the three names are extremely simple to understand because you are already familiar with them:
Name #3 is the actual servlet class name that you write and compile. This is no different than any normal Java code.
Name #1 is the URL name that someone types in their browser.

You wanted to know what deployment means. If you're writing software for a company, you'll likely be writing the code on your own computer where none of your users can access it. Eventually, you'll need to bundle up your code in a fancy package and move it to a production server so it can be run and accessed by your users. The process of moving your project code is what we call deployment. The person who does the deployment is called the deployer.

In many smaller companies, one of the software developers also acts as the deployer because the department doesn't have enough deployment work to justify having a full-time deployer. When a developer does many other non-code tasks like deployment we say he or she "wears many hats". It's quite common for a developer to wear many hats on a project.

Now think about the companies that have an official deployer person. He might not be a coder, but there's a chance he'll need to make changes to the applications anyway. How can he make changes without touching code? Well, there is a special file in Java web applications: web.xml - also called the Deployment Descriptor (or DD for short). This file allows the deployer to change certain things about the application (like what URL a servlet should be mapped to or how long an inactive session should live) without ever having to touch or compile Java code.

I talked about Name #3 and Name #1 from page 46. The deployer uses these two names in his DD file because he needs to put the two together. But the deployer also creates another name - kind of like a nickname - for the servlet. He says "Hello, Mr. FinancialAccountsCRUDManagementServlet.class - I need to use you a lot in my little deployment descriptor here... let me put a little entry in my DD so I can just give you an easier name. How about I call you Accounts?"

So that's Name #2: the deployer's nickname for the servlet. No one other than the deployer ever sees or cares about Name #2. It's his little secret.


A good workman is known by his tools.
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 239

Sir,
Thank you for your explaination,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> element of both <Servlet> and <Servlet Mapping>

and then looks for actual class name,in the <Servlet-Class> 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?
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 239

when i use netbeans to compile my servlet,it automatically deploys my Servlet which should not happen?
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

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?

No, if it says .html, it's the name of an HTML page. However, if the HTML page has a form, it's likely that the form tag's action attribute contains the #1 name of a servlet. When you submit the form, the URL in the browser will change to match that action attribute.

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.
Yes.

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> element of both <Servlet> and <Servlet Mapping>
and then looks for actual class name,in the <Servlet-Class> 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?

Yes. Very good.

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

A Servlet is a Java class. The Servlet may forward or redirect the request/response to a different servlet, JSP or other file. You may also, from the Servlet, write the complete response output through code within the Servlet. I'm not sure what you're trying to say.

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?

The servlet itself is always hidden because it's located within WEB-INF which hides everything from users. Now, Tomcat does have something called an invoker servlet that allows users to access servlets by classname: http://localhost:8080/myapp/servlet/full.class.name.MyServlet (more info here) but it's really not such a great idea to allow this in a production environment.

The primary purpose of the Deployment Descriptor is to gain flexibility.
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 239

this is the first line under the topic on page no. 46 of HFSJ says that
A Servlet has a file path name,obviously like classes/registeration/SignUpServlet.class(a path to the actual file)

now,looking at DD, i don't find anything indicating the "actual path of the servlet"i.e.classes/registeration/SignUpServlet.class It just says the class name.this still does'nt tell how the container uses that class name to find a specific servlet class file SignUpServlet.class.

i.e. we are putting SignUpServlet.class in the <Servlet-class> element but not the path to that class.i.e classes/registeration/SignUpServlet.class?
this was what i was trying to say....

and what do we mean by Invoker servlet??
where is this stored??
if i move my servlet code to any other location, how is it found??
using the same DD??
i.e How is this flexibility achieved??
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by Pankaj Shet:
now,looking at DD, i don't find anything indicating the "actual path of the servlet"i.e.classes/registeration/SignUpServlet.class

I'm not sure which DD you are looking at. There is one on page 48 that shows servlet-class of foo.Servlet1 which is a fully qualified class name.

Forget about Tomcat's invoker servlet for now, but come back to it near the end of your studies. After you understand everything then you will be able to figure out what the invoker servlet is and how it works. It won't make much sense now, but you may find it very interesting later.

If you move a servlet to a different package name, you typically will only have to update it in one place in the DD, within a servlet-class tag. IF it weren't for the special nickname of Name #2, you'd have to change it at many places in a complex DD. That's the flexibility.
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 239

The first line under this topic on page no. 46 of HFSJ says that

A Servlet has a file path name,obviously like classes/registeration/SignUpServlet.class(a path to the actual file)

I am talking about the example on page no 46.,if this example is deployed, according to this book,it will be as follows:-

<Servlet>
<Servlet-name>EnrollServlet</Servlet-name>
<Servlet-class>registration.SignUpServlet</Servlet-class>
</Servlet>
<Servlet Mapping>
<Servlet-name>EnrollServlet</Servlet-name>
<Url-Pattern>Register/RegisterMe</Url-Pattern>
</Servlet Mapping>


by looking at the above DD,i don't find anything indicating the "actual path of the servlet" i.e.classes/registeration/SignUpServlet.class It just says the fully qualified class name "registration.SignUpservlet".

This still does'nt tell how the container uses that class name to find a specific servlet class file SignUpServlet.class.

i.e. we are putting SignUpServlet.class in the <Servlet-class> element but not the path to that class.i.e classes/registeration/SignUpServlet.class?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

First of all, I think you should take some time to write the tags properly Which means writing them <servlet>, <servlet-name>, <servlet-class>, <servlet-mapping>, <url-pattern>.

i.e. we are putting SignUpServlet.class in the <Servlet-class> element but not the path to that class.i.e classes/registeration/SignUpServlet.class?

The servlet-class contains the fully qualified class name of the servlet. It's not a path. It will tell the container where to find the servlet. The container will look in your "WEB-INF/classes" directory (or in JARs in "WEB-INF/lib") and try to load your servlet. "registration.SignUpServlet" refers to a servlet in "WEB-INF/classes/registration/SignUpServlet.class".


[My Blog]
All roads lead to JavaRanch
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

For me the "fully classified class name" looks the "complete path to the actual class file from where the runtime environment starts looking at".

As such being a Web application, the class files are being located at "WEB-INF/classes" [means the "classes" directory inside the "WEB-INF" folder], it should start from that directory.

In the OS perspective, the class path is separated with "/" whereas when you specify it inside the application (be it inside a Java class or the DD), the separator is "." instead. That's why Marc has mentioned as "full.class.name.MyServlet" in his example.

In your case, the Servlet "SignUpServlet" is inside the "registration" package [which is inside "classes" directory of course!], in your web.xml file it IS just mentioned as "registration.SignUpServlet" -- which serves the purpose.

Does that help Pankaj?


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]
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 239

Thank you very much Marc sir,
you made my concept clear.,

Thank you Christoper verre madam/sir,
and Raghavan Muthu
for explaning me what i wanted.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

madam/sir

It's sir, sir
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Originally posted by Christophe Verre:

It's sir, sir


Hello Christophe, yet another confusion
Pankaj Shet
Ranch Hand

Joined: Sep 08, 2006
Posts: 239

hehehehehehehe!!!
actually I was not knowing this, that's why I said..
[ December 25, 2007: Message edited by: Pankaj Shet ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deployment.