开发者

Spring 3.0 MVC problem -- requested resource() is not available

开发者 https://www.devze.com 2023-03-30 04:58 出处:网络
I\'m trying to learn Spring MVC, using Spring 3.1 jars, and I\'m getting the following error message in my browser.

I'm trying to learn Spring MVC, using Spring 3.1 jars, and I'm getting the following error message in my browser.

HTTP Status 404 - /list_cars.html

--------------------------------------------------------------------------------

type Status report

message /list_cars.html

description The requested resource (/list_cars.html) is not available.

The error occurs when I click on the link in index.jsp (source below).

<%@ page language="java" contentType="text/html; charset=I开发者_如何学GoSO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Spring 3.0 MVC Tutorial</title>
</head>
<body>
<a href="/list_cars.html">Get Car List</a>
</body>
</html>

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>

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>

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>


Where is the file "list_cars.html"?

If you are trying to get the "carsList.jsp" then you need to change the link .

I suggest you look at the spring sample projects which can be found

Spring downloads page

0

精彩评论

暂无评论...
验证码 换一张
取 消