У меня очень простой крет.Он состоит из компонента, представляющего данные формы.У меня есть поле с длинным значением.В JSP я пишу это: <form:hidden path="id"/>
.Когда я отправляю форму, я получаю сообщение об ошибке HTTP Status 400.
Короче, когда отправка длинного значения, пружина mvc не может преобразовать его в long для создания объекта формы.
поток прост: пользователь нажимает кнопку «Редактировать над электронной компанией».Контроллер через службу извлекает компанию, затем отображается представление, и, наконец, пользователь отправляет изменения ... но когда длинное значение передается, я получил ошибку.
Отладочная информация говорит мне об этом:
DefaultHandlerExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
вот код:
мой бин формы:
public class CompanyForm {
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@NotBlank
private String name;
@NotBlank
private String addressStreet;
@NotBlank
private String addressCity;
@NotBlank
private String addressState;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddressStreet() {
return addressStreet;
}
public void setAddressStreet(String addressStreet) {
this.addressStreet = addressStreet;
}
public String getAddressCity() {
return addressCity;
}
public void setAddressCity(String addressCity) {
this.addressCity = addressCity;
}
public String getAddressState() {
return addressState;
}
public void setAddressState(String addressState) {
this.addressState = addressState;
}
}
мой контроллер:
@RequestMapping(value={"edit/{companyId}"})
public String edit(@PathVariable Long companyId, Model model){
CompanyForm form = new CompanyForm();
if(companyId!=null){
Company company = companyService.find(companyId);
if(company!=null)
modelMapper.map(company, form);
}
model.addAttribute("form", form);
return "company/edit";
}
@RequestMapping(value={"new"})
public String edit(Model model){
return this.edit(null, model);
}
@RequestMapping(value="save", method={RequestMethod.POST})
public String save(@ModelAttribute("form") @Valid CompanyForm companyForm, BindingResult result){
if(result.hasErrors())
return "company/edit";
Company company;
if(companyForm.getId()!=null)
company = companyService.find(companyForm.getId());
else
company = new Company();
modelMapper.map(companyForm, company);
companyService.save(company, getLoggedUser());
return "redirect:list";
}
мой jsp:
<form:form method="post" action="save" modelAttribute="form" cssClass="form-horizontal" >
<fieldset>
<form:hidden path="id"/>
++++ others fields +++
<div class="form-actions">
<input type="submit" value="Guardar" class="btn btn-primary btn-large"/>
</div>
</fieldset>
</form:form>
отладочная информация
2012-02-17 18:17:45 AntPathRequestMatcher [DEBUG] Checking match of request : '/companies/edit/save'; against '/resources/**'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 1 of 10 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2012-02-17 18:17:45 HttpSessionSecurityContextRepository [DEBUG] Obtained a valid SecurityContext from SPRING_SECURITY_CONTEXT: 'org.springframework.security.core.context.SecurityContextImpl@bcc22d3c: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@bcc22d3c: Principal: ar.com.held.auth.UserDetails@1421801; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 93B19E8B81EBB7F4BFEECF4FFFC46593; Granted Authorities: COMPANY_OWNER'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 2 of 10 in additional filter chain; firing Filter: 'LogoutFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 3 of 10 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 4 of 10 in additional filter chain; firing Filter: 'DefaultLoginPageGeneratingFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 5 of 10 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 6 of 10 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 7 of 10 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
2012-02-17 18:17:45 AnonymousAuthenticationFilter [DEBUG] SecurityContextHolder not populated with anonymous token, as it already contained: 'org.springframework.security.authentication.UsernamePasswordAuthenticationToken@bcc22d3c: Principal: ar.com.held.auth.UserDetails@1421801; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 93B19E8B81EBB7F4BFEECF4FFFC46593; Granted Authorities: COMPANY_OWNER'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 8 of 10 in additional filter chain; firing Filter: 'SessionManagementFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 9 of 10 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 10 of 10 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
2012-02-17 18:17:45 AntPathRequestMatcher [DEBUG] Checking match of request : '/companies/edit/save'; against '/companies/*'
2012-02-17 18:17:45 FilterSecurityInterceptor [DEBUG] Public object - authentication not attempted
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save reached end of additional filter chain; proceeding with original chain
2012-02-17 18:17:45 DispatcherServlet [DEBUG] DispatcherServlet with name 'spring' processing POST request for [/Held/companies/edit/save]
2012-02-17 18:17:45 RequestMappingHandlerMapping [DEBUG] Looking up handler method for path /companies/edit/save
2012-02-17 18:17:45 RequestMappingHandlerMapping [DEBUG] Returning handler method [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]
2012-02-17 18:17:45 DefaultListableBeanFactory [DEBUG] Returning cached instance of singleton bean 'companyController'
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:17:45 ExceptionHandlerExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:17:45 ResponseStatusExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:17:45 DefaultHandlerExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:17:45 DispatcherServlet [DEBUG] Null ModelAndView returned to DispatcherServlet with name 'spring': assuming HandlerAdapter completed request handling
2012-02-17 18:17:45 DispatcherServlet [DEBUG] Successfully completed request
2012-02-17 18:17:45 ExceptionTranslationFilter [DEBUG] Chain processed normally
2012-02-17 18:17:45 SecurityContextPersistenceFilter [DEBUG] SecurityContextHolder now cleared, as request processing completed
2012-02-17 18:26:56 AntPathRequestMatcher [DEBUG] Checking match of request : '/companies/edit/save'; against '/resources/**'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 1 of 10 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2012-02-17 18:26:56 HttpSessionSecurityContextRepository [DEBUG] Obtained a valid SecurityContext from SPRING_SECURITY_CONTEXT: 'org.springframework.security.core.context.SecurityContextImpl@bcc22d3c: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@bcc22d3c: Principal: ar.com.held.auth.UserDetails@1421801; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 93B19E8B81EBB7F4BFEECF4FFFC46593; Granted Authorities: COMPANY_OWNER'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 2 of 10 in additional filter chain; firing Filter: 'LogoutFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 3 of 10 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 4 of 10 in additional filter chain; firing Filter: 'DefaultLoginPageGeneratingFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 5 of 10 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 6 of 10 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 7 of 10 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
2012-02-17 18:26:56 AnonymousAuthenticationFilter [DEBUG] SecurityContextHolder not populated with anonymous token, as it already contained: 'org.springframework.security.authentication.UsernamePasswordAuthenticationToken@bcc22d3c: Principal: ar.com.held.auth.UserDetails@1421801; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 93B19E8B81EBB7F4BFEECF4FFFC46593; Granted Authorities: COMPANY_OWNER'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 8 of 10 in additional filter chain; firing Filter: 'SessionManagementFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 9 of 10 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 10 of 10 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
2012-02-17 18:26:56 AntPathRequestMatcher [DEBUG] Checking match of request : '/companies/edit/save'; against '/companies/*'
2012-02-17 18:26:56 FilterSecurityInterceptor [DEBUG] Public object - authentication not attempted
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save reached end of additional filter chain; proceeding with original chain
2012-02-17 18:26:56 DispatcherServlet [DEBUG] DispatcherServlet with name 'spring' processing POST request for [/Held/companies/edit/save]
2012-02-17 18:26:56 RequestMappingHandlerMapping [DEBUG] Looking up handler method for path /companies/edit/save
2012-02-17 18:26:56 RequestMappingHandlerMapping [DEBUG] Returning handler method [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]
2012-02-17 18:26:56 DefaultListableBeanFactory [DEBUG] Returning cached instance of singleton bean 'companyController'
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:26:56 ExceptionHandlerExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:26:56 ResponseStatusExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:26:56 DefaultHandlerExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:26:56 DispatcherServlet [DEBUG] Null ModelAndView returned to DispatcherServlet with name 'spring': assuming HandlerAdapter completed request handling
2012-02-17 18:26:56 DispatcherServlet [DEBUG] Successfully completed request
2012-02-17 18:26:56 ExceptionTranslationFilter [DEBUG] Chain processed normally
2012-02-17 18:26:56 SecurityContextPersistenceFilter [DEBUG] SecurityContextHolder now cleared, as request processing completed