Java 单击按钮上的Spring MVC重置表单

Java 单击按钮上的Spring MVC重置表单,java,spring-mvc,Java,Spring Mvc,我已经发布了我的视图和控制器,请查看一下。请帮助我解决在按钮点击后重置所有字段的问题 package com.lv.rs.accessautomation.view.controller; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springf

我已经发布了我的视图和控制器,请查看一下。请帮助我解决在按钮点击后重置所有字段的问题

package com.lv.rs.accessautomation.view.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.lv.rs.accessautomation.business.service.AccessService;
import com.lv.rs.accessautomation.common.constants.ViewConstants;
import com.lv.rs.accessautomation.common.util.ViewUtils;
import com.lv.rs.accessautomation.common.vo.ResUserVO;
import com.lv.rs.accessautomation.view.form.UserDetailsForm;

/**
 * @author tp50148
 *
 */
@Controller
public class AutomationController {

    @Autowired
    private AccessService accessService;

    @RequestMapping(value = ViewConstants.ACCESS_REQUEST, method = RequestMethod.POST)
    public String doActions(@ModelAttribute UserDetailsForm userDetailsForm, BindingResult result, @RequestParam String action, Map<String, Object> map,Model model){

        try {
            ResUserVO resuser  = null;
            switch(action.toLowerCase()){

            case ViewConstants.SEARCH_USER:
                resuser = accessService.getEquoteUser(userDetailsForm.getUserId().toUpperCase());
                if(resuser != null) 
                {
                    map.put("existingData", true);
                    ViewUtils.getInstance().setExistingUSer(ViewConstants.TRUE);
                    ViewUtils.getInstance().setExistingAppUser(ViewConstants.E_QUOTE);
                } else {
                    map.put("existingData", false);
                    ViewUtils.getInstance().setExistingUSer(ViewConstants.FALSE);
                }
                map.put("existingUser", resuser);
                map.put("printersMap", ViewUtils.getInstance().getPrinterList()); 

                break;


            case ViewConstants.SEARCH_QUOTE:
                resuser = accessService.getEquoteUser(userDetailsForm.getQuoteId().toUpperCase());
                if(resuser != null) 
                {
                    String printerName = ViewUtils.getInstance().getPrinterDetails().get(resuser.getPrinterId());
                    ViewUtils.getInstance().setQuoteUserId(resuser.getUserId());
                    ViewUtils.getInstance().setPrinterId(resuser.getPrinterId());
                    ViewUtils.getInstance().setSamQuoteId(resuser.getWindowId());
                    map.put("printersMap", ViewUtils.getInstance().getPrinterList());
                    map.put("printerName", printerName);
                }
                map.put("existingData", ViewUtils.getInstance().getExistingUSer());
                map.put("existingQuoteUser", resuser);
                break;

            case ViewConstants.SEARCH_CLAND:
                accessService.getClanadUser(userDetailsForm.getClanadId().toUpperCase());
                break;

            case ViewConstants.SAVE_USER:
                boolean save = false;
                if((ViewUtils.getInstance().getExistingAppUser() != null && ViewUtils.getInstance().getExistingAppUser().equals(ViewConstants.E_QUOTE)) || userDetailsForm.isQuoteAccess())
                     save = accessService.saveUser(userDetailsForm);
                break;

            case ViewConstants.DELETE_USER:
                if(ViewUtils.getInstance().getExistingAppUser().equals(ViewConstants.E_QUOTE)) {
                    accessService.deleteUser(userDetailsForm);
                }
                break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ViewConstants.ACCESS_VIEW;
    }

}
包com.lv.rs.accessautomation.view.controller;
导入java.util.Map;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Controller;
导入org.springframework.ui.Model;
导入org.springframework.validation.BindingResult;
导入org.springframework.web.bind.annotation.ModelAttribute;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.bind.annotation.RequestParam;
导入com.lv.rs.accessautomation.business.service.AccessService;
导入com.lv.rs.accessautomation.common.constants.ViewConstants;
导入com.lv.rs.accessautomation.common.util.ViewUtils;
导入com.lv.rs.accessautomation.common.vo.ResUserVO;
导入com.lv.rs.accessautomation.view.form.UserDetails表单;
/**
*@tp50148
*
*/
@控制器
公共级自动控制器{
@自动连线
私人访问服务;
@RequestMapping(值=ViewConstants.ACCESS\u请求,方法=RequestMethod.POST)
公共字符串doActions(@ModelAttribute UserDetailsForm UserDetailsForm,BindingResult,@RequestParam字符串操作,映射映射,模型模型){
试一试{
resuser=null;
开关(action.toLowerCase()){
case viewstants.SEARCH\u用户:
resuser=accessService.GetEqoteUser(userDetailsForm.getUserId().toUpperCase());
如果(resuser!=null)
{
map.put(“existingData”,true);
ViewUtils.getInstance().setExistingUSer(ViewConstants.TRUE);
ViewUtils.getInstance().setExistingAppUser(ViewConstants.E_QUOTE);
}否则{
map.put(“existingData”,false);
ViewUtils.getInstance().setExistingUSer(ViewConstants.FALSE);
}
map.put(“existingUser”,resuser);
put(“PrinterMap”,ViewUtils.getInstance().getPrinterList());
打破
case viewstants.SEARCH_QUOTE:
resuser=accessService.GetEqoteUser(userDetailsForm.getQuoteId().toUpperCase());
如果(resuser!=null)
{
字符串printerName=ViewUtils.getInstance().getPrinterDetails().get(resuser.getPrinterId());
ViewUtils.getInstance().setQuoteUserId(resuser.getUserId());
ViewUtils.getInstance().setPrinterId(resuser.getPrinterId());
ViewUtils.getInstance().setSamQuoteId(resuser.getWindowId());
put(“PrinterMap”,ViewUtils.getInstance().getPrinterList());
map.put(“printerName”,printerName);
}
put(“existingData”,ViewUtils.getInstance().getExistingUSer());
地图放置(“现有报价器”,resuser);
打破
case viewstants.SEARCH\u CLAND:
getClanadUser(userDetailsForm.getClanadId().toUpperCase());
打破
case viewstants.SAVE_用户:
布尔保存=假;
if((ViewUtils.getInstance().getExistingAppUser()!=null&&ViewUtils.getInstance().getExistingAppUser().equals(ViewConstants.equote))| | userDetailsForm.isQuoteAccess())
save=accessService.saveUser(userDetailsForm);
打破
案例ViewConstants.DELETE_用户:
if(ViewUtils.getInstance().getExistingAppUser().equals(ViewConstants.equote)){
accessService.deleteUser(userDetailsForm);
}
打破
}
}捕获(例外e){
e、 printStackTrace();
}
返回viewstants.ACCESS\u视图;
}
}
观点:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<HTML>
<HEAD>
<TITLE>Retirement Solutions - Access Management | Home</TITLE>
<link href="style/style.css" rel="stylesheet">
<script type="text/javascript"
    src="<c:url value="scripts/accesscontrol.js" />"></script>
</HEAD>

<body onload="validateTable();" onunload="">
    <form:form action="accessrequest" method="post" commandName="userDetailsForm">
        <table id="maintable" align="left" border="0" cellpadding="1"
            cellspacing="1" style="height: 100%; width: 100%;">
            <tbody>
                <tr>
                    <td colspan="2">
                        <table align="left" border="0" cellpadding="1" cellspacing="1"
                            style="width: 100%;">
                            <tbody>
                                <tr>
                                    <td align='left' width="10%"><input type="image"
                                        src="images/LV.gif" align="left" onclick="return false" /></td>
                                    <td align="center" class="bannerhead" width="90%"><font
                                        class="personal_note"><b>Retirement Solutions -
                                                Access Management</b></font></td>
                                </tr>
                            </tbody>
                        </table>

                        <p>&nbsp;</p>
                    </td>
                </tr>
                <tr height="1%">
                    <td colspan="2" align="left" class="hearderbar">Add/Edit User</td>
                </tr>
                <tr>
                    <td width="50%">
                        <table id="userDetailsMainTable" class="tableborder" align="right"
                            border="1">
                            <tbody>
                                <tr>
                                    <td class="hearderbar">User Details</td>
                                </tr>

                                <tr>
                                    <td>

                                        <table id="userDetailsTable" align="center" border="0"
                                            cellpadding="1" cellspacing="1" height="328" width="470">
                                            <tbody>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td width = 100%>
                                                        <div class="authentication">Application Access</div>
                                                    </td>
                                                    <td class="fieldlabel" align='center' width='2%'>:</td>
                                                    <td class="authentication"><form:checkbox path="quoteAccess" onclick="validateTable()" />E-quote</td>
                                                    <td class="authentication"><form:checkbox path="clanadAccess" onclick="validateTable()" />Clanad</td>
                                                </tr>
                                                <tr>
                                                    <td class="mandataory">*</td>
                                                    <td class="fieldlabel"><form:label path="userId">UserID</form:label></td>
                                                    <td class="fieldlabel" align='center' width='15%'>:</td>
                                                    <td><form:input path="userId" size="22" class="fieldlabel"/></td>
                                                    <td><input name="action" type="submit"
                                                        class="aamButton" value="SearchUser"
                                                        onmouseover="this.style.background='#3F5201'"
                                                        onmouseout="this.style.background='#9dce2c'"
                                                        onclick="return searchExistingUser();" /></td>
                                                </tr>
                                                <tr>
                                                    <td class="mandataory">*</td>
                                                    <td class="fieldlabel"><form:label path="firstName">First Name</form:label></td>
                                                    <td class="fieldlabel" align='center' width='15%'>:</td>
                                                    <td class="fieldlabel"><form:input path="firstName" size="22" class="fieldlabel" value = "${existingUser.firstname}"/></td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td class="mandataory">*</td>
                                                    <td class="fieldlabel"><form:label path="lastName">Last Name</form:label></td>
                                                    <td class="fieldlabel" align='center' width='15%'>:</td>
                                                    <td class="fieldlabel"><form:input path="lastName" size="22" class="fieldlabel" value = "${existingUser.lastname}"/></td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td class="fieldlabel"><form:label path="email">E-Mail</form:label></td>
                                                    <td class="fieldlabel" align='center' width='15%'>:</td>
                                                    <td class="fieldlabel"><form:input path="email" size="22" class="fieldlabel" value = "${existingUser.email}"/></td>
                                                    <td class="fieldlabel">@lv.com</td>

                                                </tr>
                                                <tr>
                                                    <td class="mandataory">*</td>
                                                    <td class="fieldlabel">Printer</td>
                                                    <td class="fieldlabel" align='center' width='15%'>:</td>
                                                    <td class="fieldlabel" width = '100%'>
                                                    <form:select path="printer" style="width: 170px;">  
                                                      <c:forEach items="${printersMap}" var="theObject" >
                                                       <option value="${theObject.printerId}" class="fieldlabel" <c:if test="${theObject.printerId == existingUser.printerId}">selected</c:if>>
                                                       ${theObject.printerName}</option>
                                                     </c:forEach>
                                                     </form:select>
                                                 </td>


                                                    <%-- <form:option value="-" class="fieldlabel" label="Select an Printer "></form:option> 
                                                    <form:options items="${printersMap}" class="fieldlabel"/>
                                                    </form:select>
                                                 </td>--%>




                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td class="fieldlabel"><form:label path="telephone">Telephone</form:label></td>
                                                    <td class="fieldlabel" align='center' width='15%'>:</td>
                                                    <td class="fieldlabel"><form:input path="telephone" size="22" class="fieldlabel" value = "${existingUser.telephone}"/></td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td class="fieldlabel">Activate</td>
                                                    <td class="fieldlabel" align='center' width='15%'>:</td>
                                                    <td class="fieldlabel">
                                                    <%-- <input type="radio" path="activate" value="Y" <c:if test="${(existingUser.active eq 'Y') or (existingUser.active == null)}">checked</c:if>>Yes --%>
                                                     <form:radiobutton path="activate" value="y" />Yes 
                                                    </td>
                                                    <td class="fieldlabel">
                                                   <%--  <input type="radio" path="activate" value="N" <c:if test="${existingUser.active eq 'N'}">checked</c:if>>No --%>
                                                    <form:radiobutton path="activate" value="N" />No
                                                    </td>

                                                </tr>
                                                <tr>
                                                    <td height="10%" colspan="5"></td>
                                                </tr>
                                                <tr>
                                                    <td colspan="5" align="center" rowspan="1"
                                                        style="vertical-align: middle;"><input name="action" type="submit"
                                                        value="Save/update" class="aamButton"
                                                        onmouseover="this.style.background='#3F5201'"
                                                        onmouseout="this.style.background='#9dce2c'"
                                                        onclick="return saveUser(${existingData});" /> 
                                                        <input name="action" type="submit" value="Delete"
                                                        class="aamButton"
                                                        onmouseover="this.style.background='#3F5201'"
                                                        onmouseout="this.style.background='#9dce2c'"
                                                        onclick="return deleteUser();"/> 
                                                        <input type="button"
                                                        value="Reset" class="aamButton"
                                                        onmouseover="this.style.background='#3F5201'"
                                                        onmouseout="this.style.background='#9dce2c'"
                                                        onclick="this.form.reset();" /></td>

                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                        </table>
                        <p>&nbsp;</p>
                    </td>
                    <td width="25%">
                        <table id="empty" height="20%" width="90%">
                            <tr></tr>
                            <td>&nbsp;</td>
                        </table>
                        <table height="60%" width="70%">
                            <tr>
                                <td width="100%">
                                    <table id="quoteTable" align="left" class="tableborder"
                                        border="1" style="vertical-align: middle;" cellpadding="1"
                                        cellspacing="1">
                                        <tbody>
                                            <tr>
                                                <td class="hearderbar">Sample E-quote User</span></td>
                                            </tr>
                                            <tr>
                                                <td style="text-align: center; vertical-align: middle;">
                                                    <table align="right" border="0" cellpadding="1"
                                                        cellspacing="1" width=400px;>
                                                        <tbody>
                                                            <tr>
                                                                <td class="fieldlabel"><form:label path="quoteId">Enter user ID</form:label></td>
                                                                <td><form:input path="quoteId" size="22" class="fieldlabel"/></td>
                                                                <td><input name="action" class="aamButton"
                                                                    type="submit" value="SearchQuote"
                                                                    onmouseover="this.style.background='#3F5201'"
                                                                    onmouseout="this.style.background='#9dce2c'" onclick=" return searchQuoteUser();"/></td>
                                                            </tr>
                                                            <tr>
                                                                <td class="fieldlabel"><form:label path="quoteFname">First Name</form:label></td>
                                                                <td><form:input path="quoteFname" size="22" readonly="true" class="fieldlabel" value = "${existingQuoteUser.firstname}"/></td>
                                                                <td>&nbsp;</td>
                                                            </tr>
                                                            <tr>
                                                                <td class="fieldlabel"><form:label path="quoteLname">Last Name</form:label></td>
                                                                <td><form:input path="quoteLname" size="22" readonly="true" class="fieldlabel" value = "${existingQuoteUser.lastname}"/></td>
                                                                <td>&nbsp;</td>
                                                            </tr>
                                                            <tr>
                                                                <td class="fieldlabel"><form:label path="quotePrinter">Printer</form:label></td>
                                                                <td><form:input path="quotePrinter" size="22" readonly="true" class="fieldlabel" value = "${printerName}"/></td>

                                                                <td>&nbsp;</td>
                                                            </tr>
                                                        </tbody>
                                                    </table>

                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>


                                    <table id="clanadTable" align="left" class="tableborder"
                                        border="1" cellpadding="1" cellspacing="1">
                                        <tbody>
                                            <tr>
                                                <td class="hearderbar">Sample Clanad User</span></td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <table align="center" border="0" cellpadding="1"
                                                        cellspacing="1" width=400px>
                                                        <tbody>
                                                            <tr>
                                                                <td class="fieldlabel"><form:label path="clanadId">Enter user ID</form:label></td>
                                                                <td><form:input path="clanadId" size="22" class="fieldlabel"/></td>
                                                                <td><input name="action" class="aamButton"
                                                                    type="button" value="SearchClanad"
                                                                    onmouseover="this.style.background='#3F5201'"
                                                                    onmouseout="this.style.background='#9dce2c'"
                                                                    onclick="searchClanadUser();" /></td>
                                                            </tr>
                                                            <tr>
                                                                <td class="fieldlabel"><form:label path="clanadFname">First Name</form:label></td>
                                                                <td><form:input path="clanadFname" size="22" readonly="true" class="fieldlabel"/></td>
                                                                <td>&nbsp;</td>
                                                            </tr>
                                                            <tr>
                                                                <td class="fieldlabel"
                                                                    style="text-align: left; vertical-align: middle;">
                                                                    <form:label path="clanadLname">Last Name</form:label></td>
                                                                <td><form:input path="clanadLname" size="22" readonly="true" class="fieldlabel"/></td>
                                                                <td>&nbsp;</td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                    <p>&nbsp;</p>

                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </tbody>
        </table>

    </form:form>
</body>
</html>

退休解决方案-访问管理|家庭
退休解决方案-
访问管理

添加/编辑用户 用户详细信息 应用程序访问 : 电子报价 克兰德 * 用户ID :
document.getElementById("myForm").reset();
document.forms[0].reset();
<input 
type="button"
value="Reset" 
class="aamButton"
onmouseover="this.style.background='#3F5201'"
onmouseout="this.style.background='#9dce2c'"
onclick="this.form.reset();" />
<form:button type="reset" class="btn btn-danger btn-lg btn-block">
    RESET
</form:button>