Scr*_*e74 3 tomcat web.xml servlets spring-mvc
希望你能提供帮助,因为据我所知,这是正确的设置(但请证明我错了).
我的spring 3 mvc项目配置如下:
web.xml中
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/frontPage</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/myServlet-service.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
和myServlet-servlet.xml
<mvc:annotation-driven />
<context:component-scan base-package="my.path.to.controllers" />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
Run Code Online (Sandbox Code Playgroud)
我在WEB-INF(不是WEB-INF/views)中有一个index.jsp,除了说"Hello"之外什么也没做(我原本试图让它转发到/ frontPage).
现在,如果我输入控制器的url(localhost:8080/myServlet/frontPage),控制器就会工作并显示视图,但是当我第一次启动时,我得到的是404而不是index.jsp页面.我已经尝试为index.jsp添加一个前导斜杠,但这没有任何区别.
我必须在某个地方犯过一个小学生的错误,但我不能为我的生活看到哪里.谁有人能指出它?
Spring MVC 3.2 Tomcat 6在STS 2.9.1 servlet 2.5中运行
非常感谢.
Nil*_*lsH 12
该WEB-INF文件夹无法公开访问.因此,您必须将您的位置index.jsp放在可以访问的位置,例如在Web应用程序根文件夹中.
/mywebapp
/WEB-INF/
/index.jsp
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14310 次 |
| 最近记录: |