Tomcat 启动时找不到 index.jsp

Tomcat not find the index.jsp when it starting

我有一个带有 spring 的 J2ee 应用程序。我已经在页面上应用了一些修改,但是现在,当我尝试启动服务器时,我有这个:

这是应用-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

     <bean id="lo4gjConfigurator" class="com.springmvcapp.log.LoggerFactory">
       <property name="logReInit">
        <value>true</value>
       </property>  
       <property name="fileName">
        <value>log4j.xml</value>
       </property> 
    </bean>

    <context:component-scan base-package="com.springmvcapp.controller" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean id="simpleUrlMapping" class="com.springmvcapp.security.AccessDecisionUrlMapping">
        <property name="alwaysUseFullPath" value="true" />
        <property name="mappings">
            <props>
                <prop key="/index.html">homeController</prop>
                <prop key="/registrazione.html">registrazioneController</prop>
            </props>
        </property>
    </bean>

    <bean id="homeController" class="com.springmvcapp.controller.HelloWorld">
        <property name="methodNameResolver">
            <bean
                class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
                <property name="defaultMethodName">
                    <value>loadPage</value>
                </property>
                <property name="paramName">
                    <value>method</value>
                </property>
            </bean>
        </property> 
    </bean>

    <bean id="registrazioneController" class="com.springmvcapp.controller.RegistrazioneController">
        <property name="methodNameResolver">
            <bean
                class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
                <property name="defaultMethodName">
                    <value>loadPage</value>
                </property>
                <property name="paramName">
                    <value>method</value>
                </property>
            </bean>
        </property> 
    </bean>


</beans>

这是web.xml:

<?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_2_5.xsd"
id="WebApp_ID" version="2.5">
  <display-name>SpringMVCApp</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>springmvcapp</servlet-name>
    <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvcapp</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>
</web-app>

这是 jsp 文件:

我不知道为什么 tomcat 找不到 index.jsp。

您的 index.jsp 位于目录 "WEB-INF" 中,url 无法访问该目录。将其移动到应用程序的根目录。

另一种选择是将第一个调用重定向到 spring 控制器。例如创建一个 index.html 并向其添加重定向,即:

<meta http-equiv="refresh" content="0; url=/app/">

您必须将 index.jsp 文件保存在 public 文件夹中,即 WebContent 文件夹中以便直接访问。