2016-09-02 141 views
0

有两种形式,每种在我的jsp页面都有一个提交按钮...我想将表单1发送给我的控制器它由两个图像和几个表单域组成。Spring MVC: - 表单提交(HTTP状态400 - 客户端发送的请求在语法上是不正确的。)

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 a Image</span> 
    <button class="waves-effect waves-light btn" type="submit" name="action">Submit</button> 
    </form:form>    
+0

请把你所有的jsp代码。 –

+0

可能是他们提到的错误行号。所以你可以请他们分享哪一行显示这个错误? –

+0

@JekinKalariya我在帖子中添加了jsp页面的部分内容。只要我点击提交它显示我“请求发送的客户端语法不正确” –

回答

0

由于JSP中不含有与名称,图像附加标签也名图像纠正你的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 a 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>  
相关问题