返回新的ModelAndView重定向由于某种原因不起作用

时间:2014-06-13 12:08:17

标签: forms spring-mvc redirect modelandview

我是Spring MVC框架的新手,我现在迫切需要帮助。

出于某种原因,我的重定向不起作用,它给我HTTP状态400,在控制台上没有错误,这就是为什么它很难调试。

方案: 我有两种形式。第一种形式是正确保存然后重定向到第二种形式,但是当我重复我的代码将其传递给第三种形式时,我得到一个http 400错误。我很确定我复制了我在第一张表格中使用的内容。

查看:

<form:form method="POST" commandName="kiosk"
                action="${pageContext.request.contextPath}/kiosk/kiosk-initial-info-save.html">
<div align="center">
    <br /> 
    <div id="addKioskContainer">
    <div class="datagrid1" align="center" style="width: 33%;">
        <table align="center">
            <thead>
                <tr>
                    <th colspan="4" style="text-align: left;">Initial Information</th>
                </tr>
            </thead>
        </table>
    </div>
    <div>
        <table>
            <tr>
                <td>
                    <h3 align="left">&nbsp;&nbsp;You are applying for <label style="color: blue;">Restructured Loan</label> in <label style="color: blue;">Eastwood.</label></h3>
                </td>
            </tr>
        </table>
    </div>
        <div id="initialInfoContainer">
            <table cellpadding="0" cellspacing="10">
                <tr>
                    <td style="font-size: 12px;" >
                        <b>Purpose of Loan: </b>
                    </td>
                    <td>
                        <form:input path="loanPurpose" size="40"></form:input>
                    </td>
                </tr>
            </table>
        </div>
        <br />
        <div id="applicantInfoContainer">
                <div class="datagrid2" align="center" style="width: 95%;">
                    <table align="center">
                        <thead>
                            <tr>
                                <th colspan="4" style="text-align: left;">Applicant's Information</th>
                            </tr>
                        </thead>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Last Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="appLastName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>First Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="appFirstName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Middle Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="appMiddleName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Birthdate: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="appBirthDate" size="20"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>w/ Comaker: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:checkbox path="withCoMaker"></form:checkbox>
                            </td>
                        </tr>
                    </table>
                </div>
        </div>
        <br />
        <div id="comakerInfoContainer">
                <div class="datagrid2" align="center" style="width: 95%;">
                    <table align="center">
                        <thead>
                            <tr>
                                <th colspan="4" style="text-align: left;">Comaker's Information</th>
                            </tr>
                        </thead>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Last Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="comakerLastName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>First Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="comakerFirstName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Middle Name: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="comakerMiddleName" size="40"></form:input>
                            </td>
                        </tr>
                        <tr>
                            <td style="font-size: 12px;" >
                                <b>Birthdate: </b><label style="color: red;">*</label>
                            </td>
                            <td>
                                <form:input path="comakerBirthDate" size="20"></form:input>
                            </td>
                        </tr>
                    </table>
                </div>
        </div>
        <br />
        <div align="center">
            <table>
                <tr>
                    <td align="center"><input type="submit" value="Next" id="btnProceedKiosk"/></td>
                    <td></td>
                </tr>

            </table>
        </div>
    </div>
</div>

控制器:

 @RequestMapping( value = "/kiosk-initial-info", method = RequestMethod.GET )
public ModelAndView initialInfoKioskPage()
{
    ModelAndView modelAndView = new ModelAndView( "kiosk-initial-info" );

    modelAndView.addObject( "kiosk", new Kiosk() );

    return modelAndView;
}

@RequestMapping( value = "/kiosk-initial-info-save", method = RequestMethod.POST )
public ModelAndView saveInitialInfo( @ModelAttribute
Kiosk kiosk )
{
    ModelAndView modelAndView = new ModelAndView( "kiosk-initial-info" );

    modelAndView.addObject( "kiosk", new Kiosk() );

    return new ModelAndView( "redirect:/kiosk/kiosk-initial-info.html" );
}

型号:

    package com.etel.kiosk.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table( name = "kioskmain" )
public class Kiosk
{

    @Id
    @GeneratedValue
    private Integer id;

    private String loanType;

    private String branch;

    private String loanPurpose;

    private String appLastName;

    private String appFirstName;

    private String appMiddleName;

    private Date appBirthDate;

    private Boolean withCoMaker;

    private String comakerLastName;

    private String comakerFirstName;

    private String comakerMiddleName;

    private Date comakerBirthDate;

    public Integer getId()
    {
        return id;
    }

    public void setId( Integer id )
    {
        this.id = id;
    }

    public String getLoanType()
    {
        return loanType;
    }

    public void setLoanType( String loanType )
    {
        this.loanType = loanType;
    }

    public String getBranch()
    {
        return branch;
    }

    public void setBranch( String branch )
    {
        this.branch = branch;
    }

    public String getLoanPurpose()
    {
        return loanPurpose;
    }

    public void setLoanPurpose( String loanPurpose )
    {
        this.loanPurpose = loanPurpose;
    }

    public String getAppLastName()
    {
        return appLastName;
    }

    public void setAppLastName( String appLastName )
    {
        this.appLastName = appLastName;
    }

    public String getAppFirstName()
    {
        return appFirstName;
    }

    public void setAppFirstName( String appFirstName )
    {
        this.appFirstName = appFirstName;
    }

    public String getAppMiddleName()
    {
        return appMiddleName;
    }

    public void setAppMiddleName( String appMiddleName )
    {
        this.appMiddleName = appMiddleName;
    }

    public Date getAppBirthDate()
    {
        return appBirthDate;
    }

    public void setAppBirthDate( Date appBirthDate )
    {
        this.appBirthDate = appBirthDate;
    }

    public Boolean getWithCoMaker()
    {
        return withCoMaker;
    }

    public void setWithCoMaker( Boolean withCoMaker )
    {
        this.withCoMaker = withCoMaker;
    }

    public String getComakerLastName()
    {
        return comakerLastName;
    }

    public void setComakerLastName( String comakerLastName )
    {
        this.comakerLastName = comakerLastName;
    }

    public String getComakerFirstName()
    {
        return comakerFirstName;
    }

    public void setComakerFirstName( String comakerFirstName )
    {
        this.comakerFirstName = comakerFirstName;
    }

    public String getComakerMiddleName()
    {
        return comakerMiddleName;
    }

    public void setComakerMiddleName( String comakerMiddleName )
    {
        this.comakerMiddleName = comakerMiddleName;
    }

    public Date getComakerBirthDate()
    {
        return comakerBirthDate;
    }

    public void setComakerBirthDate( Date comakerBirthDate )
    {
        this.comakerBirthDate = comakerBirthDate;
    }

}

DaoImpl

public void updateKiosk( Kiosk kiosk )
{
    Kiosk kioskToUpdate = getKiosk( kiosk.getId() );
    kioskToUpdate.setBranch( kiosk.getBranch() );
    kioskToUpdate.setLoanPurpose( kiosk.getLoanPurpose() );
    kioskToUpdate.setAppLastName( kiosk.getAppLastName() );
    kioskToUpdate.setAppFirstName( kiosk.getAppFirstName() );
    kioskToUpdate.setAppMiddleName( kiosk.getAppMiddleName() );
    kioskToUpdate.setAppBirthDate( kiosk.getAppBirthDate() );
    kioskToUpdate.setWithCoMaker( kiosk.getWithCoMaker() );
    kioskToUpdate.setComakerLastName( kiosk.getComakerLastName() );
    kioskToUpdate.setComakerFirstName( kiosk.getComakerFirstName() );
    kioskToUpdate.setComakerMiddleName( kiosk.getComakerMiddleName() );
    kioskToUpdate.setComakerBirthDate( kiosk.getComakerBirthDate() );
    getCurrentSession().update( kioskToUpdate );
}

你的答案将会有很大的帮助。感谢。

0 个答案:

没有答案