【问题标题】:Spring MVC :- Form Submission (HTTP Status 400 - The request sent by the client was syntactically incorrect.)Spring MVC :- 表单提交(HTTP 状态 400 - 客户端发送的请求在语法上不正确。)
【发布时间】:2016-09-02 06:35:32
【问题描述】:

在我的 jsp 页面中有两个表单,每个表单都有一个提交按钮...我想将表单 1 发送到我的控制器,该控制器由两个图像和几个表单字段组成。

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>             

【问题讨论】:

  • 请把你所有的jsp代码。
  • 可能是他们在您的错误中提到了行号。!那么你能分享一下他们在哪一行显示这个错误吗?
  • @JekinKalariya 我在帖子中添加了我的jsp页面的一部分。一旦我点击提交,它就会显示“客户端发送的请求在语法上不正确”
  • @ojuskulkarni 它没有显示任何特定的错误行号。它没有到达控制器方法.....
  • 我认为你应该使用@RequestParam("schoolObject") 而不是@ModelAttribute(schoolObject)

标签: spring jsp spring-mvc spring-form


【解决方案1】:

由于您的 jsp 不包含任何带有名称 image 的标签,因此通过添加带有名称 image 的标签来更正您的 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>      

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 2015-12-02
    相关资源
    最近更新 更多