我是 SpringFramework 的新手。我创建了一个扩展 SimpleFormController 的控制器。我还创建了一个命令类,它有几个String
字段和两个List<String>
字段。
该表单位于 PHP 生成的页面上,之前由 PHP 处理。我正在尝试将该处理移至 Java,因为这部分应用程序正在生成大型电子表格,PHP 无法再处理这些电子表格。
无论如何,表单不包含任何数字字段。不过,当我提交表单时,我得到了 NumberFormatException:
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NumberFormatException: For input string: ""
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
java.lang.NumberFormatException: For input string: ""
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:504)
java.lang.Integer.parseInt(Integer.java:527)
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:991)
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:924)
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:692)
org.springframework.validation.DataBinder.doBind(DataBinder.java:588)
org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:191)
org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:112)
org.springframework.web.servlet.mvc.BaseCommandController.bindAndValidate(BaseCommandController.java:394)
org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:266)
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
堆栈跟踪不包含我的任何类,我不知道如何调试它。
这是我的命令类:
public class ExportCommand {
private String ifs_login;
private String exp_sales_price_group_id_sp_ip_pl;
private List<String> exp_catalog_group;
private List<String> exp_vendor_no_pps;
private String exp_price_list_no_pl;
private String exp_contract;
private String exp_language_code_spl;
private String exp_active_ind_sp = ""; //those are checkboxes with "Y" as checked value, so I initialize them to empty strings if they are unchecked.
private String exp_desc = "";
private String exp_customs = "";
private String exp_ordered = "";
//here goes default getters and setters
}
这是我在 Chrome 开发人员工具中看到的表单:
ifs_test:MAGE
exp_sales_price_group_id_sp_ip_pl:MOLEX
exp_catalog_group[]:
exp_price_list_no_pl:MOLEX
exp_contract:VER
exp_language_code_spl:
...连同它的源形式:
ifs_test=MAGE&exp_sales_price_group_id_sp_ip_pl=MOLEX&exp_catalog_group%5B%5D=&exp_price_list_no_pl=MOLEX&exp_contract=VER&exp_language_code_spl=
编辑:
我的控制器如下所示:
public class ExportController extends org.springframework.web.servlet.mvc.SimpleFormController {
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
//....
}
}
我究竟做错了什么?