jsp - Spring MVC :- Form Submission (HTTP Status 400 - The request sent by the client was syntactically incorrect.) -
there 2 forms each having 1 submit button in jsp page ... want send form 1 controller consists of 2 images , few form fields.
controller.java
@requestmapping(value="/schooldetails",method=requestmethod.get) public modelandview getschooldetails(){ modelandview model = new modelandview(); school schools=new school(); map referencedata = new hashmap(); referencedata.put("schoolobject", schools); modelandview mav = new modelandview("schooldetails", referencedata); return mav; } @requestmapping(value="/addschooldetails",method=requestmethod.post) public string addschooldetails(@modelattribute("schoolobject") school school, @requestparam("image") multipartfile image,@requestparam("logo") multipartfile logo){ if(result.haserrors()){ return "schooldetails"; } object principal = securitycontextholder.getcontext().getauthentication().getprincipal(); customuser user=null; if (principal instanceof customuser) { user = ((customuser)principal); } return "schooldetails"; }
schooldetails.jsp
<form:form method="post" role="form" action="/genericapp/addschooldetails" enctype="multipart/form-data" modelattribute="schoolobject"> <div class="col s3" id="sname">school name :</div> <input id="form_text" name="schoolname" type="text" placeholder="school name"/> <div class="col s3" id="sname">email id :</div> <input id="form_text" name="email" type="email" placeholder="email id"/> <div class="col s3" id="sname">state :</div> <select name="state" id="state_id" > <option>state</option> <option>karnataka</option> </select> <div class="col s12 m4 l4" id="sname">upload school logo :</div> <input type="file" name="logo" id="fileupload" accept="image/x-png, image/gif, image/jpeg"/> <span class="button teal ">choose image</span> <button class="waves-effect waves-light btn" type="submit" name="action">submit</button> </form:form>
as jsp not contain tag having name image correct jsp file adding tag name image , below
<form:form method="post" role="form" action="/genericapp/addschooldetails" enctype="multipart/form-data" modelattribute="schoolobject"> <div class="col s3" id="sname">school name :</div> <input id="form_text" name="schoolname" type="text" placeholder="school name"/> <div class="col s3" id="sname">email id :</div> <input id="form_text" name="email" type="email" placeholder="email id"/> <div class="col s3" id="sname">state :</div> <select name="state" id="state_id" > <option>state</option> <option>karnataka</option> </select> <div class="col s12 m4 l4" id="sname">upload school logo :</div> <input type="file" name="logo" id="fileupload" accept="image/x-png, image/gif, image/jpeg"/> <span class="button teal ">choose image</span> <input type="file" name="image" id="image" accept="image/x-png, image/gif, image/jpeg"/> <button class="waves-effect waves-light btn" type="submit" name="action">submit</button> </form:form>
Comments
Post a Comment