Thursday 15 August 2013

spring - request sent by the client was syntactically incorrect -



spring - request sent by the client was syntactically incorrect -

i have 2 similar web functions utilize spring framework, function 1 hits "request sent client syntactically incorrect" while function 2 works well. show 1 not work below in hope can help me.

function 1 jsp:

<form:form id="sform" action="dealmaintedit.htm" method="post" commandname="dmform"> <table border="1"> <tr><td><spring:message code="label.dealid"/></td> <td><form:input path="deal.dealid" readonly="true" size="6"/></td> </tr> <tr><td><spring:message code="label.code"/></td> <td><form:input path="deal.stkcode" maxlength="5" size="6"/> <form:errors path="deal.stkcode" cssclass="error"/></td> </tr> .....other fields skipped.... </table> <form:hidden path="mode"/> <form:hidden path="butt" value="save"/> <input form="sform" type="submit" value="<spring:message code="label.save"/>"/> </form:form>

function 1 dmform:

@component public class dealmaintform { private string mode; private string butt; @valid private deal deal; .....

function 1 controller:

@requestmapping(value = "/dealmaintedit.htm") public string dealmaintedit(@modelattribute("dmform") @valid dealmaintform form, @requestparam("butt") string butt, bindingresult result, map model) {

i have if (result.haserrors()) in controller didn't execute before hitting error.

function 1 deal:

public class deal implements serializable { private long dealid; private dealtype type; @notnull @min(1) @max(99999) private int stkcode; ......

the funny thing is, if there validation error, hits syntactically wrong error before reaching controller method. if input 2 stkcode works fine, if alter @min(1) in stkcode @min(5), input 2 in stkcode nail syntactically incorrect. other fields same.

my other web form works looks this. function 2 jsp:

<form:form action="stockmaint2edit.htm" method="post" commandname="smform"> <form:hidden path="mode"/> <form:hidden path="stk.id"/> <table border="1"> <tr> <td><spring:message code="label.code"/></td> <td><form:input path="stk.code"/><form:errors path="stk.code" cssclass="error"/></td> </tr> <tr> <td><spring:message code="label.name"/></td> <td><form:input path="stk.name" /><form:errors path="stk.name" cssclass="error"/></td> </tr> </table> <form:hidden path="butt" value="save"/> <input type="submit" value="<spring:message code="label.save"/>"/> </form:form>

function 2 smform

@component public class stockmaintform2 { private string mode; private string butt; @valid private stock stk; .....

function 2 controller

@requestmapping(value = "/stockmaint2edit.htm") public string stockmaintedit(@modelattribute("smform") @valid stockmaintform2 form, bindingresult result, map model) { if (result.haserrors()) { system.out.println("edit has errors"); list<fielderror> errlist = result.getfielderrors(); (fielderror fe : errlist) { ......

function 2 stock

public class stock implements serializable { private static final long serialversionuid = 1l; private long id; @notnull @min(1) @max(99999) private int code; @notblank private string name; ....

function 2 works validation error msg displayed correctly. no syntactically wrong error. compared them several times , still not able spot difference , cause of problem. please allow me know if should provide more info.

i guess causes error,

<form:hidden path="butt" value="save"/>

you can seek normal hidden field ,

<input type="hidden" name="butt" value="save"/>

in function 1 jsp .

as have used spring:form tag . butt not available explicitly in request. need model attribute or can create input field html tag. available in request.

spring jsp validation

No comments:

Post a Comment