Thursday, 15 May 2014

spring - Form Sumbit action resulting into get request -



spring - Form Sumbit action resulting into get request -

i have simple form on click of accpet button of type resulting requet rather post request. causing display of page twice , weired thing form generates post request when click on take button again. happening on ie8 , chrome.

current configuration :

<%@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 </h1> </c:when> <c:when test="${whitelabellingfolder == 'pqr'}"> <h1 style="color:#6a2c91">welcome <i style="color:#6a2c91">bond</i></h1> </c:when> <c:when test="${whitelabellingfolder == 'xyz'}"> <h1>welcome </h1> </c:when> <c:when test="${whitelabellingfolder == 'lmn'}"> <h1>welcome </h1> </c:when> <c:when test="${whitelabellingfolder == 'qwe'}"> <h1>welcome </h1> </c:when> <c:when test="${whitelabellingfolder == 'poi'}"> <h1>welcome </h1> </c:when> <c:otherwise> <h1>welcome nothing</h1> </c:otherwise> </c:choose> <h2>terms , 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 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 -->

controller----

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 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; seek { appresponse = registrationappservice.getthemechange(servicecontext); } grab (applicationexception e) { // todo auto-generated grab 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"); homecoming "termsncondition"; } @requestmapping(method = requestmethod.post) public string onsumbit(httpservletrequest request, httpservletresponse response){ cmulogger.enter(classname, "onsubmit >> in 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 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); seek { cmulogger.error(classname, "error******error**** before updating db"); registrationappservice.updatetnc(conext, updatetncrequest); cmulogger.error(classname, "error******error**** after updating db"); } grab (applicationexception ae) { cmulogger.error(classname, "error******error**** ocuured during updating db"); /*errors.reject("", ae.getmessage()); seek { homecoming showform(request, errors, this.getformview()); } grab (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 redirected next url:" + redirectto); cmulogger.exit(classname, "onsubmit"); //return "redirect:" + redirectto;`enter code here` homecoming redirectto; } public appservice getappservice() { homecoming appservice; } public void setappservice( appservice appservice) { this.appservice = appservice; } }

spring model-view-controller

No comments:

Post a Comment