Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.apache.jasper.JasperException: /WEB-INF/views/home.jsp (line: [25], column: [1]) Unable to find setter method for attribute: [commandName]

Tags:

I have created a spring form and want to submit this from and display another jsp page. When i run this project i get the below exception. can anyone help me to understand why i am getting this error.

org.apache.jasper.JasperException: /WEB-INF/views/home.jsp (line: [25], column: [1]) Unable to find setter method for attribute: [commandName]     org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)     org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:292)     org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:115)     org.apache.jasper.compiler.Generator$GenerateVisitor.evaluateAttribute(Generator.java:2998)     org.apache.jasper.compiler.Generator$GenerateVisitor.generateSetters(Generator.java:3218)     org.apache.jasper.compiler.Generator$GenerateVisitor.generateCustomStart(Generator.java:2404)     org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1894)     org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1544)     org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2389)     org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2441)     org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2447)     org.apache.jasper.compiler.Node$Root.accept(Node.java:470)     org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2389)     org.apache.jasper.compiler.Generator.generate(Generator.java:3657)     org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:256)     org.apache.jasper.compiler.Compiler.compile(Compiler.java:384)     org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)     org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)     org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)     javax.servlet.http.HttpServlet.service(HttpServlet.java:741)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)     org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:170)     org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:312)     org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1325)     org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069)     org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008)     org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)     org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)     org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870)     javax.servlet.http.HttpServlet.service(HttpServlet.java:634)     org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)     javax.servlet.http.HttpServlet.service(HttpServlet.java:741)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) 

JSP File :

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ page session="false" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <html> <head>     <title>Home</title>     <style> .error {     color: #ff0000; }  .errorblock {     color: #000;     background-color: #ffEEEE;     border: 3px solid #ff0000;     padding: 8px;     margin: 16px; } </style> </head> <body> <h2>Spring's form textbox example</h2>      <form:form method="POST" action="/customer" commandName="customer">         <form:errors path="*" cssClass="errorblock" element="div" />         <table>             <tr>                 <td>Username :</td>                 <td><form:input path="userName" />                 </td>                 <td><form:errors path="userName" cssClass="error" />                 </td>             </tr>             <tr>                 <td colspan="3"><input type="submit" />                 </td>             </tr>         </table>     </form:form>  </html> 

When i use simple html form then it works properly but same thing if i am doing it through spring form it gives the error.

Controller Class :

@Controller public class HomeController {       @RequestMapping("/")     public String welcomePage()     {         return "home";     }       @RequestMapping(value="/customer", method=RequestMethod.POST)     public ModelAndView submitForm(@RequestParam("userName") String name)     {                ModelAndView mv = new ModelAndView("success");         mv.addObject("userName", name);         return mv;     } } 
like image 1000
Swetamber Avatar asked Oct 28 '17 11:10

Swetamber


People also ask

What is nullpoiterexception in Jasper?

Hi, Normally this "NullPoiterException" is because of mission resource / input. To make it usefull error, perhaps Jasper team can come out with own error handling which will give a user-friendly message.

Why is my jspservlet not working in servletcontainer?

Or if the particular code line is in no way to be backtracked to your own code and is thus specific to the servletcontainer's own JspServlet, then it's likely a bug or misconfiguration. Update your question to include it so that we can assist you further with this.

How do I fix a JSP Index error in Tomcat?

Go to the Tomcat /work/Catalina/localhost folder, then open the folder matching the webapp context name, then open /org/apache/jsp/index_jsp.java file and read line 73. Backtrack this line to your own original index.jsp file in the web root and fix it accordingly.

What's wrong with my servlet?

What's actually happened is this: A compile time error occured when the container tried to compile the servlet source file (which it creates from your jsp file). Then it forgets what this error was and shows you this crappy message.


2 Answers

Which version of Spring MVC are you using? I had the same problem, with maven dependency which is,

group id : org.springframework artifact id : spring-webmvc version : 5.0.2.RELEASE

After version 5, commandName was removed, you should use modelAttribute, instead. I found it here, https://jira.spring.io/browse/SPR-16037

I simply changed the commandName with modelAttribute.

<form:form modelAttribute="goal"> 
like image 60
Oguz Avatar answered Oct 10 '22 15:10

Oguz


1...OLD WAY = commandName

<form:form action="index" commandName="todo"> 

2...NEW WAY = modelAttribute

  <form:form action="index" modelAttribute="todo"> 

commandName was the old way of doing it and in new applications you should be using modelAttribute

like image 27
chandra mohan Avatar answered Oct 10 '22 15:10

chandra mohan