Spring MVC報異常:org.springframework.web.util.NestedServletException: Request processing failed


 

 

在使用SpringMVC綁定基本類型(如String,Integer等)參數時,應通過@RequestParam注解指定具體的參數名稱,否則,當源代碼在非debug模式下編譯后,運行時會引發HandlerMethodInvocationException異常,這是因為只有在debug模式下編譯,其參數名稱才存儲在編譯好的代碼中。 

譬如下面的代碼會引發異常:

 
@RequestMapping(value = "/security/login", method = RequestMethod.POST)
public ModelAndView login(@RequestParam String userName, @RequestParam String password, 
    HttpServletRequest request) {
    ......................


如果使用Eclipse編譯不會在運行時出現異常,這是因為Eclipse默認是采用debug模式編譯的,但是如果使用Ant通過javac任務編譯的話就會出現異常,除非指定debug=”true”。出現的異常如同:


org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: 

Failed to invoke handler method [public org.springframework.web.servlet.ModelAndView com.mypackage.security.controller.LoginController.login(java.lang.String,java.lang.String,javax.servlet.http.HttpServletRequest)]; nested exception is java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.String], and no parameter name information found in class file either. 
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659) 
.......... 

org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public org.springframework.web.servlet.ModelAndView com.mypackage.security.controller.LoginController.login(java.lang.String,java.lang.String,javax.servlet.http.HttpServletRequest)]; nested exception is java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.String], and no parameter name information found in class file either. 
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171) 
.......... 


java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.String], and no parameter name information found in class file either. 
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.getRequiredParameterName(HandlerMethodInvoker.java:618) 
..........



最好的做法是通過@RequestParam注解指定具體的參數名稱,如,上面的代碼應該如此編寫(注意@RequestParam部分):
Java代碼  

@RequestMapping(value = "/security/login", method = RequestMethod.POST)    

public ModelAndView login(@RequestParam("userName") String userName,    @RequestParam("password") String password,   HttpServletRequest request) {    

   ......................  

我喜歡,駕馭着代碼在風馳電掣中創造完美!我喜歡,操縱着代碼在隨必所欲中體驗生活!我喜歡,書寫着代碼在時代浪潮中完成經典!每一段新的代碼在我手中誕生對我來說就象觀看剎那花開的感動!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 Spring MVC報異常:org.springframework.web.util.NestedServletException: Request processing failed error:org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException 成功解決 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException:報錯 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Current request is not a multipart request org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jboss.resteasy.plug org.springframework.web.util.NestedServletException : Handler processing failed; nested exception is java.lang.StackOverflowError 關於org.springframework.web.util.NestedServletException: Request processing failed; nested exceptio,org.eclipse.jgit.api.errors.TransportException: git@xx.git UnknownHostKey:xx RSA錯誤填坑 Tomcat服務org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: Java heap space org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: 報錯異常原因及解決
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM