[英]Spring,form won't submit
我在Spring的jsp中使用表單,但是我很難用“ post”方法提交它。
我的表格如下所示:
<c:url var="action2" value="/saveConfig/try" />
<form:form name="formakonfig" id="formakonfig" action="${action2}" method="post" modelAttribute="seatingConfiguration">
<form:hidden path="mesto" id="mestoo" value=""></form:hidden>
<form:hidden path="restoran" id="restoranre" value=""></form:hidden>
<form:hidden path="reon" id="reonn" value=""></form:hidden>
<form:hidden path="raspolozivost" id="raspolozivostt" value=""></form:hidden>
</form:form>
<button type="submit" style="width: 152px; height: 25px; margin-top:-60px; margin-left:150px; position:fixed;">Sacuvaj konfiguraciju</button>
我的JavaScript文件,其中我對隱藏字段設置值"mesto"
, "restoran"
, "reon"
和"raspolozivost"
,里面$(document).ready
。
$("#mestoo").val(stringSadrzajaTabele);
$("#restoranre").val(vrednostSelekta());
$("#reonn").val(stringSadrzajaTabele);
$("#raspolozivostt").val("slobodno");
我也試圖訪問控制器(但我無法訪問它。)
@RequestMapping(value="/saveConfig/try",method=RequestMethod.POST)
public ModelAndView snimanjeKonfiguracije(@Valid SeatingConfiguration seatingConfiguration,BindingResult bindingResult,ModelMap model,HttpServletRequest request){
if (bindingResult.hasErrors()) {
return new ModelAndView("zaposleni","formErrors",bindingResult.getAllErrors());
}
model.addAttribute("workerRegistration", new WorkerRegistration());
model.addAttribute("restaurantRegistration", new RestaurantRegistration());
String temp1=seatingConfiguration.getMesto();
String temp2=seatingConfiguration.getRestoran();
String temp3=seatingConfiguration.getReon();
String temp4=seatingConfiguration.getRaspolozivost();
System.out.println(temp1);
System.out.println(temp2);
System.out.println(temp3);
System.out.println(temp4);
model.put("poruka", "Dodato!");
return new ModelAndView("zaposleni","model",model);
}
在Spring工作的人是否有耐心,看看可能出現的問題對我來說非常重要!:)謝謝!
在第一個代碼中,您的“提交”按鈕不在表單中,如果您不是通過js發送表單,則應為這種情況。 在表單元素內放置提交按鈕,如下所示:
<form:form name="formakonfig" id="formakonfig" action="${action2}" method="post" modelAttribute="seatingConfiguration">
<form:hidden path="mesto" id="mestoo" value=""></form:hidden>
<form:hidden path="restoran" id="restoranre" value=""></form:hidden>
<form:hidden path="reon" id="reonn" value=""></form:hidden>
<form:hidden path="raspolozivost" id="raspolozivostt" value=""></form:hidden>
<button type="submit" style="width: 152px; height: 25px; margin-top:-60px; margin-left:150px; position:fixed;">Sacuvaj konfiguraciju</button>
</form:form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.