简体   繁体   中英

Tomcat finds welcome file but unable to find other JSPs

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?

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.

由于您的项目不是标准Java Web Project格式,因此您无法访问。首先,您需要将Web内容放置在WEB-INF文件夹之外。类似于WebContent文件夹,然后在web.xml中定义文件夹的上下文。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM