配置Spring MVC欢迎页面时出错
我已经配置了一个非常简单的SpringMVC项目,在该项目中,我在控制器中配置了欢迎页面,而不是index.jsp文件欢迎页面。但是我不知道为什么我在运行项目时尝试了所有的方法,错误是资源不可用 谁能帮忙吗 这是文件 Web.xml 代码似乎很正确。非常感谢你的帮助。谢谢配置Spring MVC欢迎页面时出错,spring,jsp,spring-mvc,welcome-file,Spring,Jsp,Spring Mvc,Welcome File,我已经配置了一个非常简单的SpringMVC项目,在该项目中,我在控制器中配置了欢迎页面,而不是index.jsp文件欢迎页面。但是我不知道为什么我在运行项目时尝试了所有的方法,错误是资源不可用 谁能帮忙吗 这是文件 Web.xml 代码似乎很正确。非常感谢你的帮助。谢谢 在运行应用程序时,流不会流向控制器,即使我在控制台中看不到任何内容欢迎页面必须是文件系统上的实际页面,它不能是对servlet的引用。因此,您必须使用index.jsp,然后重定向到servlet。除此之外,它还可以很好地与重
在运行应用程序时,流不会流向控制器,即使我在控制台中看不到任何内容欢迎页面必须是文件系统上的实际页面,它不能是对servlet的引用。因此,您必须使用index.jsp,然后重定向到servlet。除此之外,它还可以很好地与重定向一起工作,但不完全如此。它没有配置欢迎文件,并且由于
DispatcherServlet
被配置为默认servlet(它被映射到/),所有内容(如果没有其他内容可以处理它)都将通过它。由于DispatcherServlet
(/是映射到欢迎视图的mvc:view控制器)的配置,它可以工作。但是,在旧的servlet容器中,它可能(也可能会)失败(我们遇到了一些问题)。但事实上,它并不总是必须是一个文件。servlet容器(tomcat?)日志文件中是否有任何消息(例如异常)?您调用哪个url?
<?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>Pet Clinic</display-name>
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
<?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"
xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="com.petclinic.controller"/>
<!-- View Resolver Configured -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix">
<value>/WEB-INF/view/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
package com.petclinic.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class ClinicController {
@RequestMapping("/")
public String welcomeHandler(HttpServletRequest request)
{
System.out.println("Inside Controller");
System.out.println(request.getServletPath());
return "welcome";
}
}