java Spring MVC 和错误 400:SRVE0295E
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16570508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring MVC and Error 400: SRVE0295E
提问by opad
I have problem with simple MVC application.
我对简单的 MVC 应用程序有问题。
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>
Here is my controller:
这是我的控制器:
@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";
}
When I click Add button Error 400: SRVE0295E: Error reported: 400 appears, there is no information at server console. I assume it is realted to the setupForm() method which is displaying the form and crushing it to future submits. Can you please guide me with this?
当我单击添加按钮错误 400:SRVE0295E:错误报告:出现 400 时,服务器控制台上没有信息。我认为它与 setupForm() 方法有关,该方法显示表单并将其粉碎以供将来提交。你能指导我吗?
回答by lu_ko
Error 400: SRVE0295E occurs also when MVC cannot fill @ModelAttribute Form
with values from HTML form.
错误 400:SRVE0295E 也会在 MVC 无法填充@ModelAttribute Form
HTML 表单中的值时发生。
For example:
例如:
- class
Form
has primitive attributeint someCount
- your HTML form has
<input>
to assign value to this primitive attribute - user entered empty value (
null
) to this<input>
- 类
Form
具有原始属性int someCount
- 你的 HTML 表单必须
<input>
为这个原始属性赋值 - 用户
null
为此输入了空值 ( )<input>
You should not use primitive types such as int
, boolean
, float
and so on.
你不应该使用原始的类型,例如int
,boolean
,float
等等。
回答by Mark Chorley
The return statements from setupForm and addNewHoliday are different. I presume you want to return the same view name from both. As you can see the form in order to submit it, I assume that the addNewHoliday return value of "/dayoff" should in fact be "dayoff"
setupForm 和 addNewHoliday 的返回语句是不同的。我想您想从两者中返回相同的视图名称。如您所见,为了提交表单,我假设“/dayoff”的 addNewHoliday 返回值实际上应该是“dayoff”