Spring mvc Spring 3.0 MVC问题--请求的资源()不可用
我正在尝试使用Spring3.1JAR学习SpringMVC,在我的浏览器中收到以下错误消息Spring mvc Spring 3.0 MVC问题--请求的资源()不可用,spring-mvc,Spring Mvc,我正在尝试使用Spring3.1JAR学习SpringMVC,在我的浏览器中收到以下错误消息 HTTP Status 404 - /list_cars.html -------------------------------------------------------------------------------- type Status report message /list_cars.html description The requested resource (/list
HTTP Status 404 - /list_cars.html
--------------------------------------------------------------------------------
type Status report
message /list_cars.html
description The requested resource (/list_cars.html) is not available.
当我单击index.jsp(下面的源代码)中的链接时出错
Spring3.0MVC教程
carList.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head><title>Car List</title></head>
<body>
<h1>Car List</h1>
<c:forEach items="${carList}" var="car">
${car.brand.name} ${car.model}: ${car.price}
<br />
</c:forEach>
</body>
</html>
汽车清单
汽车清单
${car.brand.name}${car.model}:${car.price}
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>Spring3MVC</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
Spring3MVC
index.jsp
春天
org.springframework.web.servlet.DispatcherServlet
1.
春天
*.html
spring-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 name="/list_cars.html" class="springmvc.web.CarListController"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
文件“list\u cars.html”在哪里
如果您试图获取“carsList.jsp”,则需要更改链接
我建议您看看spring示例项目,这些项目可以找到
我已经从spring-servlet.xml中删除了prefix语句,并将jsp移到了/WEB-INF之外。我还更改了index.jsp中的链接。现在调用了carList.jsp,这是正确的,但是没有从控制器返回任何内容。因为这是一个单独的问题,所以需要一个单独的线程。
<?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 name="/list_cars.html" class="springmvc.web.CarListController"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>