2013-05-15 104 views
1

我有簡單的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"/>&nbsp;&nbsp; 
     </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" />&nbsp;&nbsp; 
     </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()方法實現的,該方法顯示錶單並將其壓碎以備將來提交。你能指導我這個嗎?

+0

'/ dayoff.html'的行爲是否正確?你是否將'* .html'映射到你的控制器方法?您可能還想使用'method =「post」'來確保您使用了正確的控制器方法。 –

+0

Can [this](http://stackoverflow.com/questions/1483063/spring-mvc-3-and-handling-static-content-am-i-missing-something)help !!! – NINCOMPOOP

+0

是的,我的DispatcherServlet映射'* .html'文件。並且'method =「post」'不需要,因爲在我的html源代碼文件中,表單已經被聲明爲使用'method =「post」'。 – opad

回答

0

setupForm和addNewHoliday的返回語句不同。我認爲你想從兩個返回相同的視圖名稱。正如你可以看到,以提交的形式,我認爲「/ dayoff」的addNewHoliday返回值其實應該是「dayoff」

4

錯誤400:還當MVC不能與填充值@ModelAttribute Form發生SRVE0295E HTML表格

例如:Form

  • 類有原始屬性int someCount
  • HTML表單具有<input>到的值分配給該原始屬性
  • 用戶輸入空值(null)到這個<input>

您不應該使用原始類型,如int,boolean,float等。

+1

我有一個類似的錯誤,因爲我發送的RequestParam無效。在IE中失敗,但在Chrome中失敗。 – MattC