我有簡單的MVC應用程序的問題。Spring MVC和錯誤400:SRVE0295E
dayoff.html
<div id="dayoff_operations" class="big_box_1">
<form:form modelAttribute="dayOff" enctype="multipart/form-data" action="/dayoff.html" >
<div style="width: 50%; float: left; margin-top: 0px ">
<form:label path="forDate" ><spring:message code="dayoff.fordate.label"/></form:label>
<form:input path="ax_forDate" id="datepicker" style="width:65px" readonly="readonly"/>
</div>
<div style="width: 50%; float: right; margin-top: 0px ">
<form:label path="toDate" ><spring:message code="dayoff.todate.label"/></form:label>
<form:input path="ax_toDate" id="datepicker2" style="width:65px" readonly="readonly" />
</div>
<div style="float: left">
<form:select cssClass="more" path="dayofftype" items="${dayoffTypes.list}" itemLabel="label" itemValue="value" htmlEscape="false" cssErrorClass="errorsField"/>
<form:errors path="dayofftype" cssClass="errors"/>
</div>
<input type="submit" name="add" value="Add"/>
</form:form>
這裏是我的控制器:
@Controller
@RequestMapping("/dayoff")
@SessionAttributes(types = {DayOff.class})
public class DaysOffController {
private Validator validator;
@Autowired
private ReloadableResourceBundleMessageSource messages;
@ModelAttribute("dayoffTypes")
public Map<String, Object> populateDayoffTypes(Locale locale) {
return Utils.createComboMap(DayoffType.values(), messages, locale);
}
@RequestMapping(method = RequestMethod.GET)
public String setupForm(Model model) {
model.addAttribute("dayOff", new DayOff());
model.addAttribute("cur_period",SessionManager.getCurrentPeriod());
return "dayoff";
}
@RequestMapping(method = RequestMethod.POST, params = "add")
public String addNewHoliday(@ModelAttribute DayOff dayOff, BindingResult result, ModelMap model) {
System.out.println("AAA");
return "/dayoff";
}
當我點擊添加按鈕錯誤400:SRVE0295E:錯誤報告:400次出現,還有在服務器控制檯上的任何信息。 我認爲它是通過setupForm()方法實現的,該方法顯示錶單並將其壓碎以備將來提交。你能指導我這個嗎?
'/ dayoff.html'的行爲是否正確?你是否將'* .html'映射到你的控制器方法?您可能還想使用'method =「post」'來確保您使用了正確的控制器方法。 –
Can [this](http://stackoverflow.com/questions/1483063/spring-mvc-3-and-handling-static-content-am-i-missing-something)help !!! – NINCOMPOOP
是的,我的DispatcherServlet映射'* .html'文件。並且'method =「post」'不需要,因爲在我的html源代碼文件中,表單已經被聲明爲使用'method =「post」'。 – opad