Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How many sites are on one tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How many sites are on one tomcat" Watch "How many sites are on one tomcat" New topic
Author

How many sites are on one tomcat

Parth Twari
Ranch Hand

Joined: Jan 20, 2010
Posts: 163
I am confused with this URL in the question(from whizlab simulator):

which is valid mapping to servlet :

http://www.mysite.com/base.html

or

http://www.mysite.com/myapp/base.html

when
servlet-mapping url-pattern says-

*.html


this brings a big confusion in my mind-

I know only tomcat

What is a site on tomcat ?
a webapp is a site(http://www.mysite.com/) ?
or a group of webapps is a site (http://www.mysite.com/)?
how many sites can run on one tomcat?

whenever a url comes in must it point to a particular webapp then it will be valid or it be valid otherwise as well?


Parth Tiwari
| Pursuing Bachelor of Engineering | OSUM Club Leader | SCJP 6 | SCWCD 5 |...
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Apache Tomcat is a Java-based web server. A web server can host many web applications. If you consider the term "site" to mean "web application", then Tomcat can host many "sites."

The question about the URL is tricky. In practice, you would never have "*.html" as the value of servlet-mapping url-pattern because this would prevent you from efficiently serving static HTML pages.

The other tricky part of this question is you are not told how the domain name is mapped to the web application, so you wouldn't be able to see if "myapp" is needed or not. A domain name can be mapped in a few different ways.

These are a couple of good examples of problems with commercial online-testing for software development/design skills. In many cases, the Instructional Designers that create these tests don't have actual programming or software engineering experience. Surfing the web and asking forum questions to create a technical test is not the same as a seasoned expert creating a test.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1665
    
  25

Hi Marcus,

When we just consider that the domain-name mapping is not part of the exam we can say that the question is about everything behind the server (www.mysite.com)
so can /base.html point to a servlet or can /myapp/base.html map to a servlet. I would say it is the last option where myapp would be the context-root of the web-app.

Have a look at the following picture


Every web-app has to have a context-root, so the question is can the web-app have a context root of an empty String (or does it need a name like myapp). The answer might be found in the HttpServletRequest interface method String getContextPath().
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "".

It seems there is a possibility that this method returns an empty String, but how to create a servlet in the default (root) context I have no idea. Maybe this is only possible by the guys who make the web-container. This makes both answers possible.....

Regards,
Frits
Parth Twari
Ranch Hand

Joined: Jan 20, 2010
Posts: 163
Ok..
this makes it quite clear for me.

If we are hosting for example a web page .html in the context root of tomcat then we don't need to metion webapp name.

ex

http://localhost:8080/mypage.html

similarily a servlet could be hosted probably and that would result in a mapping like is mentioned in question.So both are true and possible mappings for the servlets.

thanks
Now, the other question ,
how many sites can run on one tomcat?


I wanted to know that in real world when some company is using Apche Tomcat as webserver\container then in that case what will be there site folder(s)?
they will only make one myapp and put it in webapps & use it as a site folder?
or they will get the whole webapps folder of tomcat and they can put myapp1, myapp2 etc?

Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1665
    
  25

Marcus,

Tomcat is not relevant to the SCWCD exam. Try to post this question on the Tomcat forum.

Kind Regards,
Frits
Parth Twari
Ranch Hand

Joined: Jan 20, 2010
Posts: 163
ok..

meanwhile i read this line in spec which says that servlet can be in default web application.

Servlets in a container that were not deployed as part of aWeb application are
implicitly part of a “default” Web application and have a default ServletContext.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1665
    
  25

Servlets in a container that were not deployed as part of a Web application are
implicitly part of a "default" Web application and have a default ServletContext.


ok, that statement confirms that we thought earlier: these Servlets come with the container.

Regards,
Frits
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
A Java-based web server has two parts: a servlet container and a JSP engine.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How many sites are on one tomcat