如何解决Spring MVC 2.0中的HTTP状态404 - /CustomerSales/WEB-INF/jsp/customersuccess.jsp

时间:2014-04-25 07:00:05

标签: spring spring-mvc

这是我的代码

我在WEB-INF文件夹中创建了web.xml文件

的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"
         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>SpringMVC</display-name>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

调度-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"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
        xmlns:p="http://www.springframework.org/schema/p">

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix"><value>/WEB-INF/jsp/</value></property>
        <property name="suffix"><value>.jsp</value></property>
    </bean>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

        <property name="interceptors">
            <list><ref local="localeChangeInterceptor"/></list>
        </property>

        <property name="urlMap">
            <map>
                <entry key="/customer.html">
                    <ref bean="customerController"/>
                </entry>
            </map>
        </property>

    </bean>

    <!-- <bean id="customerValidator" class="info.CustomerFormController"/> -->

    <bean id="customerController" class="info.CustomerController">
        <!-- <property name="sessionForm"><value>false</value></property> -->
        <property name="commandName"><value>customer</value></property>
        <property name="commandClass"><value>info.Customer</value></property>
        <!-- <property name="validator"><ref bean="customerValidator"/></property> -->
        <property name="formView"><value>customer</value></property>
        <property name="successView"><value>customersuccess</value></property>
    </bean>

    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="hl"/>
    </bean>

    <bean id="localeResolver" 
          class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>

</beans>   

的index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-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>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
</head>
<body>
<center><a href="customer.html">Customer Sales</a></center>
</body>
</html>

customer.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<form:form commandName="customer" method="post" name="customer">
    <table border="0">
        <tr>
            <td>Customer Address</td>
            <td><form:input path="customerAddress"/></td>
        </tr>
        <tr>
            <td>Invoice</td>
            <td><input type="file" name="invoice"/></td>
        </tr>

        <tr>
            <td colspan="2">
                <hr/>
            </td>
        </tr>

        <tr>
            <td>1</td>
            <td><form:input path="pid1"/></td>
            <td><form:input path="qt1"/></td>
            <td><form:input path="pp1"/></td>
            <td><form:input path="tot1"/></td>
        </tr>

        <tr>
            <td>2</td>
            <td><form:input path="pid2"/></td>
            <td><form:input path="qt2"/></td>
            <td><form:input path="pp2"/></td>
            <td><form:input path="tot2"/></td>
        </tr>

        <tr>
            <td>3</td>
            <td><form:input path="pid3"/></td>
            <td><form:input path="qt3"/></td>
            <td><form:input path="pp3"/></td>
            <td><form:input path="tot3"/></td>
        </tr>

        <tr>
            <td colspan="4"><input type="submit" value="Save"/></td>
        </tr>
    </table>
</form:form>

CustomerController.java

package info;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class CustomerController extends SimpleFormController {

    @Override
    public ModelAndView onSubmit(Object command) {
        Customer customer = (Customer) command;

        ModelAndView modelAndView = new ModelAndView(getSuccessView());
        System.out.println("controller" + getSuccessView());
        modelAndView.addObject("customer", customer);
        return modelAndView;
    }

}

Customer.java

public class Customer {

    private String customerAddress;
    private String invoice;
    private Integer pid1;
    private Integer qt1;
    private Double pp1;
    private Double tot1;
    private Integer pid2;
    private Integer qt2;
    private Double pp2;
    private Double tot2;
    private Integer pid3;
    private Integer qt3;
    private Double pp3;
    private Double tot3;

    //setters and getters
}

我在WEB-INF / jsp文件夹下创建了这个文件

customersuccess.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>

<html>
<head>
    <title>Customer Sales Display</title>
</head>
<body>
<center>
    <h3>Customer Sales Display</h3><br>
    <table>
        <tr>
            <td colspan="2" align="center"><font size="5">Customer Sales Information</font></td>
        </tr>
        <tr>
            <td>Customer Address:</td>
            <td><c:out value="${customer.customerAddress}"/></td>
        </tr>
        <tr>
            <td>Invoice</td>
            <td><c:out value="${customer.invoice}"/></td>
        </tr>
        <tr>
            <td>PID1</td>
            <td><c:out value="${customer.pid1}"/></td>
        </tr>

    </table>
    <a href="customer.html">Back</a>
</center>
</body>
</html>

我在WEB-INF \ jsp文件夹中创建了customer.jspcustomersuccess.jsp。我没有得到成功的看法。请帮我。

0 个答案:

没有答案