This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusing Terms ??

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is my understanding of the following terms; Please correct me if i am wrong..

1. Document Root (represented as '/'): It is your web application directory when deployed in web container (eq Tomcat or Websphere Application Server)

2. Context Root : Is It Other name of Document Root OR is it folder above classes folder?

3. Absolute Path : The path with starts with / (/ being the document root). Example : In tomcat, suppose your application folder is "SV_Web_Application" that you have deployed under webapps, then by /Temp/login.html , we expect login.html to be present under <webapps>/Temp directory. but in case of calling a servlet (say from another servlet) if we say /servlet/AccountServlet, does in this case, the call (/servlet/AccountServlet) has only to do with <servlet-mapping> in web.xml and it does not mean that / represents <doc root> in this case.

4. Relative path : When we say request.getRequestDispatcher("../html/copyright.html"), what this path is relative to?
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Document Root:
It is your web application directory when deployed in web container (eq Tomcat or Websphere Application Server)

Not exactly. It is the top-level directory in your web application structure. It is more of a development time term. It is not a deployment time term.
Example: Your structure during development is SV_Web_Application with Temp folder as a sub folder and other files in it, then SV_Web_Application is the document root.

By the way, in Websphere you cannot deploy applications without creating a WAR or EAR file. Tomcat/WebLogic will allow you to deploy an application without the need to create an archive.

2. Context Root:
Is It Other name of Document Root OR is it folder above classes folder?

It is not the folder above classes folder. Classes folder resides inside WEB-INF folder, which in turn resides inside your document root.
Context root is a deployment time term.
After you are done with your coding, you deploy the application. You can either have the folder SV_Web_Application copied under webapps in Tomcat or deploy a war file you created with the contents inside SV_Web_Application.
By default, tomcat uses the name of the document root as the context name if you copy the entire document root folder along with its contents under webapps. But during deployment of a web module, we can specify the context name for the web module. This can be different from the document root name.

3. Absolute Path:
The path with starts with / (/ being the document root)

The path starts with Context Root. Of course, sometimes document root and context name are the same.

4. Relative Path:
When we say request.getRequestDispatcher("../html/copyright.html"), what this path is relative to.

Relative path is relative to current request. Say you are coding in a file inside <root>/pages/HelloWorld.jsp. Here, if you have a relative path ../html, it will navigate to root and then get inside html folder while serving the request.
[ March 11, 2007: Message edited by: Sunil Vasudevan ]
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sunil...wow..too good explanation
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunil,
Thanks for your reply.

Originally posted by Sunil Vasudevan:
1. Document Root:

Relative path is relative to current request. Say you are coding in a file inside <root>/pages/HelloWorld.jsp. Here, if you have a relative path ../html, it will navigate to root and then get inside html folder while serving the request.

[ March 11, 2007: Message edited by: Sunil Vasudevan ]



Suppose i have written this statement in a servlet: then where does ../ points to?

Can you please let me know in which book these terms are made clear. I read hanumant deshmukh book but in that these terms are not very clear..
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as servlets go, it depends on the URL pattern you have specified in web.xml.

Example:


Here, if you specify in your servlet:
RequestDispatcher dispatcher = request.getRequestDispatcher( "../test/test.jsp" );
it will be provide different behaviour for the above two mappings.

Case 1: You will invoke the servlet with:
http://localhost:8080/SV_Web_Application/test/HelloWorldServlet

For this request, it will interpret the page to a level above, which means context root and then inside "test" folder and forward to test.jsp.

Case 2:
http://localhost:8080/SV_Web_Application/HelloWorldServlet

This will not be able to find test.jsp as the servlet is already in the root level and cannot navigate one step back. Your dispatcher object will be null.


Regarding a good book, Hanumant is good. Also try out Heads First Servlets and JSP. And the best is to try out things hands on ourself. They clear your doubts better than any book can.

Of course for that you need to put in extra efforts...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic