aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Why the folder WebContent is overlooked by the container while building URL for webapp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Why the folder WebContent is overlooked by the container while building URL for webapp?" Watch "Why the folder WebContent is overlooked by the container while building URL for webapp?" New topic
Author

Why the folder WebContent is overlooked by the container while building URL for webapp?

Eshan Kapoor
Ranch Hand

Joined: May 15, 2013
Posts: 37

In a simple dynamic web project, using eclipse, all the JSPs can be placed either under WebContent(name can be changed) or any sub folder in WebContent. Now, if my webapp name is, say ServletStarter, and my jsp is index.jsp, the URL would be - http://localhost:8080/ServletStarter/ or http://localhost:8080/ServletStarter/index.jsp
My question is, how the request is directly coming from webapp's name if in between "ServletStarter" and "index.jsp" there is a WebContent folder which actually has all the JSPs? Why the URL is not like - http://localhost:8080/ServletStarter/WebContent/ or http://localhost:8080/ServletStarter/WebContent/index.jsp
In Head First Servlets and JSP, from where I read, all the JSPs are put directly under the webapp in deployment environment and there is no WebContent folder(I guess that is so since they didn't use eclipse for coding).

Please help.

Thanks
Niraj Jha
Ranch Hand

Joined: Feb 20, 2013
Posts: 63

Yes you are right , It is the IDE(Eclipse) directory structure the default directory structure of any web application is like application-name -> WEB-INF ->.....
Eshan Kapoor
Ranch Hand

Joined: May 15, 2013
Posts: 37

But why the WebContent folder isn't in the URL?
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 761
    
    9
Eshan Kapoor wrote:But why the WebContent folder isn't in the URL?

Because it's not there at deployment time. Your server (e.g Tomcat) does not know anything about that folder. IT only knows about the war file which does not contain the WebContent folder.
Eshan Kapoor
Ranch Hand

Joined: May 15, 2013
Posts: 37

Straight from Eclipse Platform - http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Fccwebprj.html

WebContent folder

The mandatory location of all Web resources, including HTML, JSP, graphic files, and so on. If the files are not placed in this directory (or in a subdirectory structure under this directory), the files will not be available when the application is executed on a server. The Web content folder represents the contents of the WAR file that will be deployed to the server. Any files not under the Web content folder are considered development-time resources (for example, .java files, .sql files, and .mif files), and are not deployed when the project is unit tested or published.

So, in my war file, all the stuff comes directly from WebContent and only classes folder from the build folder(in eclipse), doesn't it?

E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 761
    
    9
Sometimes some jar files are added to the lib directory as well. It depends on how you setup your IDE and build process. e.g I use eclipse but also use a build tool. I don't have a WebContent folder at all but I have a webapp folder instead which serves a similar purpose.
Eshan Kapoor
Ranch Hand

Joined: May 15, 2013
Posts: 37

Yes, we can change the name of WebContent folder. Thanks E Armitage.
Eshan Kapoor
Ranch Hand

Joined: May 15, 2013
Posts: 37

Hey one more question! When we click on Run on Server, does eclipse take those files from WebContent folder(name may vary) assuming it is just like a war file and shows us the webapp we created? I am asking this because at that time we haven't created any war file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why the folder WebContent is overlooked by the container while building URL for webapp?
 
Similar Threads
Tomcat6 and Java Beans
JSP in a folder
creating website basic question
error 404 requested resource not found in Eclipse
Stripes 1.5 with eclipse 3.5 +tomcat 6