Spring 表单Sumbit操作导致get请求

Spring 表单Sumbit操作导致get请求,spring,model-view-controller,Spring,Model View Controller,我有一个简单的表单,点击accpet按钮,它的类型会导致GET requet而不是POST请求。这会导致页面显示两次,但当您再次单击“接受”按钮时,表单会生成POST请求。这主要发生在IE8和Chrome上 当前配置: <%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@taglib prefix="spring" uri="http://www.springframework.

我有一个简单的表单,点击accpet按钮,它的类型会导致GET requet而不是POST请求。这会导致页面显示两次,但当您再次单击“接受”按钮时,表单会生成POST请求。这主要发生在IE8和Chrome上

当前配置:

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

<title><spring:theme code="company"/><spring:theme code="title.companySetup.terms&conditions"></spring:theme></title>
<%-- <title><spring:message  code="userRegistration.addNewEmployer.title"></spring:message></title> --%>

 <!-- CONTENT START -->
    <div class="canvasWrapper">
        <div class="canvas" role="main">
            <div class="contentWrapper clearfix">
            <c:choose>
                <c:when test="${whitelabellingfolder == 'ABC'}">
                <h1>Welcome to </h1>
                </c:when>

                <c:when test="${whitelabellingfolder == 'PQR'}">
                <h1 style="color:#6a2c91">Welcome to  <i style="color:#6a2c91">BOND</i></h1>
                </c:when>
                <c:when test="${whitelabellingfolder == 'XYZ'}">
                <h1>Welcome to </h1>
                </c:when>
                <c:when test="${whitelabellingfolder == 'LMN'}">
                <h1>Welcome to </h1>
                </c:when>
                <c:when test="${whitelabellingfolder == 'QWE'}">
                <h1>Welcome to </h1>
                </c:when>
                <c:when test="${whitelabellingfolder == 'POI'}">
                <h1>Welcome to </h1>
                </c:when>
                <c:otherwise>
                <h1>Welcome to Nothing</h1>
                </c:otherwise>
            </c:choose>

              <h2>Terms and Conditions</h2>

                   <spring:message code="${whitelabellingfolder}.termsAndContion.body"></spring:message>

                     <form:form method="Post" commandName="userForm" >       
                     <form:errors path="*" cssClass="formError" element="div" />                                                                                        
                        <div class="ruler"></div>
                        <div class="navHolder clearfix">
                            <!-- <script type="text/javascript">
                                document.write('<div class="floatLeft"><input type="button" class="btnBlue" value="Print this page" onClick="window.print()"></div>');
                            </script>  -->
                            <div class="floatRight"><input class="btnBlue" name="accpet" type="submit" value="Accept" /></div>                        
                            <div class="floatRight"><input class="btnBlue" name="decline" type="submit" value="Decline" /></div>
                        </div>

                </form:form> 

          </div>
        </div>
    </div>
    <!-- CONTENT END -->
    <!-- FOOTER START -->
    <div class="footerWrapper2">
        <div class="footerCanvasWrapper">
            <div class="footerCanvas">&nbsp;
            </div>
            <div class="footerLinks">
            </div>
        </div>
    </div>
    <!-- FOOTER END -->

控制器中的内容太多,我看不到在哪里加载模型以初始化表单。尝试构建一个最小的可验证的完整示例…将
method=“Post”
更改为
method=“Post”
,会发生什么?
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.theme.SessionThemeResolver;
import org.springframework.web.util.WebUtils;



@Controller
@RequestMapping("/TNC.html")
public class TNCControllerAnn {

    private String className = "TNCControllerAnn";

    @Autowired
    private AppService appService;

    @RequestMapping(method = RequestMethod.GET)
    public String formbacking(@RequestHeader(value="Accept") String accept,
            @RequestHeader(value="Accept-Language") String acceptLanguage,
            @RequestHeader(value="User-Agent", defaultValue="foo") String userAgent,HttpServletRequest request,
            HttpServletResponse response) {

        CMULogger.enter(className, "formBackingObject >> In the get method");
        String employerID = request.getHeader(UIConstant.EMP_ID);
        CMULogger.debug(className, " ** employerID: " + employerID);

        request.getSession().setAttribute(UIConstant.SELECTED_MODULE, "tnc");

        String requestURL = request.getRequestURL().toString();
        if (!requestURL.endsWith("/")) {
            requestURL = requestURL.concat("/");
        }
        request.getSession().setAttribute(GlobalConstants.REQUEST_URL, requestURL);

        CMULogger.debug(className, " ** Request_URL: " + request.getSession().getAttribute(GlobalConstants.REQUEST_URL));

        ServiceContext serviceContext = new ServiceContext();
        UserContext userContext = new UserContext(employerID, "", "", "", "", "", "", "", "");
        serviceContext.setUserContext(userContext);

        RegistrationSetupAppResponse appResponse = null;
        try {
            appResponse = registrationAppService.getThemeChange(serviceContext);
        } catch (ApplicationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        AdviserDTO adviserDTO = appResponse.getAdviserDTO();
        String companyAgencyCode = adviserDTO.getCoLegalAgencyCode();
        Boolean isBranded = adviserDTO.isBrandedAccessRequired();
        String requestURI = "/";
        if (!isBranded) {
            companyAgencyCode = "sam";
        } else {
            requestURI = "/" + adviserDTO.getBrandingURL() + "/";
        }
        request.getSession().setAttribute(GlobalConstants.REQUEST_URI, requestURI);
        request.getSession().setAttribute("whitelabellingfolder", companyAgencyCode);
        WebUtils.setSessionAttribute(request, SessionThemeResolver.THEME_SESSION_ATTRIBUTE_NAME, companyAgencyCode);

        CMULogger.exit(className, "formBackingObject");
        return "termsnCondition";

    }

    @RequestMapping(method = RequestMethod.POST)
    public String onSumbit(HttpServletRequest request, HttpServletResponse response){
        CMULogger.enter(className, "onSubmit >> In the post method");
        String redirectTo = GlobalConstants.REDIRECT;
        if (request.getParameter("accpet") != null) {
            String cnUserID = request.getHeader(UIConstant.CNUSER_ID);
            String email = request.getHeader(UIConstant.EMAIL);

            if ((email == null) || (cnUserID == null)) {
                String message = "Mandatory Field email or cnUserID is missing";
                CMULogger.error(className, "Exception in creating context", message);
               // throw new ApplicationException(message);
            }
            ServiceContext conext = new ServiceContext();
            UpdateTNCDTO updateTNCDTO = new UpdateTNCDTO();
            UpdateTNCRequest updateTNCRequest = new UpdateTNCRequest();

            updateTNCDTO.setCnUserID(cnUserID);
            updateTNCDTO.setEmail(email);
            updateTNCRequest.setUpdateTNCDTO(updateTNCDTO);

            try {
                 CMULogger.error(className, "Error******Error**** Before updating DB");
                registrationAppService.updateTNC(conext, updateTNCRequest);
                CMULogger.error(className, "Error******Error**** AFter updating DB");
            } catch (ApplicationException ae) {
                 CMULogger.error(className, "Error******Error**** Ocuured during updating DB");
                /*errors.reject("", ae.getMessage());
                try {
                    return showForm(request, errors, this.getFormView());
                } catch (Exception e) {
                    CMULogger.error(className, e.getMessage());
                }*/
            }
            CMULogger.debug(className, "******" + PropertyReader.getEnvBasedProperty(GlobalConstants.TNC_ACCEPTED_URL));
            String requestURI = (String) request.getSession().getAttribute(GlobalConstants.REQUEST_URI);
            redirectTo =
                    PropertyReader.getEnvBasedProperty(GlobalConstants.TNC_ACCEPTED_URL)
                            + ((requestURI.equals("/")) ? "" : requestURI.substring(0, (requestURI.length() - 1)));

        } else if (request.getParameter("decline") != null) {
            CMULogger.debug(className, "User declined T&C");
            StringBuilder strbuilder = new StringBuilder();
            strbuilder.append(redirectTo);
            strbuilder.append(PropertyReader.getEnvBasedProperty(GlobalConstants.LOGOFF_URL));
            String requestURI = (String) request.getSession().getAttribute(GlobalConstants.REQUEST_URI);
            strbuilder.append("?advisor=" + ((requestURI.equals("/")) ? "" : requestURI.substring(1, (requestURI.length() - 1))));
            redirectTo = strbuilder.toString();
        }
        CMULogger.debug(className, "User is redirected to following url:" + redirectTo);
        CMULogger.exit(className, "onSubmit");
        //return "redirect:" + redirectTo;`enter code here`
        return redirectTo;


    }

    public AppService getAppService() {
        return appService;
    }

    public void setAppService(
            AppService appService) {
        this.appService = appService;
    }


}