我有一个带弹簧的J2ee应用程序。我已在页面上应用了一些修改但现在,当我尝试启动服务器时,我有这个:
这是application-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。
答案 0 :(得分:2)
您的index.jsp位于“WEB-INF”目录中,url无法访问该目录。将其移至应用程序的根目录。
另一种选择是将第一个调用重定向到弹簧控制器。例如,创建一个index.html并添加一个重定向,即i.E。:
<meta http-equiv="refresh" content="0; url=/app/">
答案 1 :(得分:0)
您必须将index.jsp文件保存在公用文件夹中,即WebContent文件夹以便直接访问。