Reputation: 703
I am sure I am making some crazy mistake but unable to figure it out. I just installed Tomcat 7.0 and deployed "app" that just consists couple of JSPs (simple test). However, when I run tomcat and try to access the pages, I can only access JSP if I put it in "welcome-file-list" and can not access it any other way. Could someone help as I am unable to figure out what am I doing wrong.
Here is the webapp structure -
sampleapp -
/META-INF
/javascripts
/stylesheets
/WEB-INF
web.xml
/lib
/classes
/jsp
/test1.jsp
/test2.jsp
Here is the web.xml. It really doesn't have anything except for the welcome-file-list -
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>sampleapp</display-name>
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/WEB-INF/jsp/test1.jsp</welcome-file>
</welcome-file-list>
</web-app>
In this example, I have welcome-file set to test1.jsp so when I run tomcat and access default app as http://localhost:8080/sampleapp
, it loads the content of test1.jsp successfully. However, if I try to access the path for test2.jsp I am unable to do so. Similarly, if I set welcome file to be test2.jsp, I can access it by simply accessing http://localhost:8080/sampleapp
but when I try to explicitly access test1.jsp or test2.jsp, it returns 404 error.
Could anyone help figure out whats going wrong?
Upvotes: 0
Views: 1772
Reputation: 5157
Since your project is not in a standart Java Web Project format you cant access.Firstly you need to put your web content outside of WEB-INF folder.Something like a WebContent folder and then define a context for your folder in your web.xml.
Upvotes: 0
Reputation: 691685
The WEB-INF directory is inaccessible from the outside. If you want the JSPs to be accessible from the outside, you must put them outside of WEB-INF.
Upvotes: 3