• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Eshan Kapoor
Ranch Hand
Posts: 39
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why the WebContent folder isn't in the URL?
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, we can change the name of WebContent folder. Thanks E Armitage.
 
Eshan Kapoor
Ranch Hand
Posts: 39
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic