JaySchrock
JaySchrock

Reputation: 251

Struts2 Tomcat, How does Tomcat know where the JSP's are to run?

Im learning Sturts2. Im running different tutorials over Eclipse... I noticed that some directory structures have the JSP's in a JSP folder under Web-inf, others have them just under Web-inf not in any sub folder. I've tried creating a JSP folder and moving my helloworld JSP's in a JSP folder just to see if its found at run time, in some cases yes, others no.. Curious how does Tomcat know where to find and run the JSP's? Is there some configuration file that points to the JSP's? thanks in advance.

Upvotes: 1

Views: 86

Answers (1)

Christopher Schultz
Christopher Schultz

Reputation: 20862

If you are using Struts and Tomcat, then whichever component is in charge at the time (Struts or Tomcat) decides where to look for the JSPs. Ultimately, every request boils down to a resource which can be found within the application's URL space. So all URLs will start with /contextPath and then have some additional information after that.

Typically, pages are referred to in code or configuration as being relative to the application's root. So, a request for /app/dir/file.jsp would result in the JSP file being located in /dir/file.jsp in whatever directory holds your application. It's up to you whether you put your files into /web relative to the application's root or in /WEB-INF.

Tomcat is careful not to allow remote clients to request files in /WEB-INF because that would represent a security vulnerability, but it does allow code within the application to forward requests to resources within that directory. This is why some applications like to put all JSP files into the /WEB-INF folder: it ensures that no remote client will ever directly-request a JSP file and perhaps cause a problem on the server by not providing some expected state beforehand.

Upvotes: 1

Related Questions