David parker
David parker

Reputation: 23

JSP Tomcat Bad Resources

We are deeper into our project, and have set up a basic web application with eclipse. Whenever we attempt to run the server, we get a 404 error like the following enter image description here

From my research, I have found I need some sort of web.xml file. Where should put this file what should be in it. How do I make it

Upvotes: 1

Views: 98

Answers (2)

developerwjk
developerwjk

Reputation: 8659

Putting JSPs under WEB-INF makes them inaccessible unless you map them in WEB.XML The purpose of WEB-INF is to hide things because users cannot download or access anything under WEB-INF. You only put JSPs under WEB-INF if you don't want the user to be able to go there by its real name (i.e. http://localhost/app/whatever.jsp) but want to map it to some specific url (i.e. http://localhost/app/somename/)

Mapping a JSP that is under WEB-INF to a URL cane be done with this in the WEB.XML

   <servlet>
     <servlet-name>somename</servlet-name> 
     <jsp-file>/WEB-INF/whatever.jsp</jsp-file>
   </servlet>
   <servlet-mapping>
     <servlet-name>somename</servlet-name>
     <url-pattern>/somename/*</url-pattern>
 </servlet-mapping> 

Of course, if you need to map another URL to the JSP but don't feel the need to disallow the user from going there by its .jsp filename, you can use a URL Rewriting filter for that. In that case, there is no point in putting it under WEB-INF.

Upvotes: 2

Cesar Loachamin
Cesar Loachamin

Reputation: 2738

Your problem is your trying to access a resource within the WEB-INF folder, that is not allowed and that is the reason you have this error, you must put the jsp under the WebContent folder or any folder under the WebContent folder. The WEB-INF\classes contains the .class files for your Java classes and it's not a good place to put any resource.

Since the 3.0 specification for servlets the web deployment descriptor (web.xml) is optional.

I hope this could help you to fix your problem

Upvotes: 3

Related Questions