当前位置 : 首页 » 互动问答 » 正文

org.apache.jasper.JasperException:/WEB-INF/views/home.jsp(line:[25],column:[1])无法找到属性的setter方法:[commandName]

分类 : 互动问答 | 发布时间 : 2018-04-27 16:00:34 | 评论 : 1 | 浏览 : 180 | 喜欢 : 0

我创建了一个spring表单,并希望从另一个jsp页面提交并显示。当我运行这个项目时,我得到下面的异常。任何人都可以帮助我理解为什么我得到这个错误。

 org.apache.jasper.JasperException:/WEB-INF/views/home.jsp(line:[25],column:[1])无法找到setter方法的属性:[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>主页</ TITLE>
    <风格>
.error {
    颜色:#ff0000;
}

.errorblock {
    颜色:#000;
    background-color:#ffEEEE;
    border:3px solid#ff0000;
    padding:8px;
    margin:16px;
}
</样式>
</ HEAD>
<BODY>
<h2> Spring的表单文本框例子</ h2>

    <form:form method =“POST”action =“/ customer”commandName =“customer”>
        <form:errors path =“*”cssClass =“errorblock”element =“div”/>
        <表>
            <TR>
                <td>用户名:</ 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:表单>

</ HTML>

当我使用简单的html表单时,它可以正常工作,但同样的事情,如果我通过弹簧形式做它会给出错误。

控制器类:

 @Controller
公共类HomeController {


    @RequestMapping( “/”)
    public String welcomePage()
    {
        回家”;
    }


    @RequestMapping(value =“/ customer”,method = RequestMethod.POST)
    public ModelAndView submitForm(@RequestParam(“userName”)字符串名称)
    {
        ModelAndView mv = new ModelAndView(“success”);
        mv.addObject(“userName”,name);
        返回mv;
    }
}

回答(1)

相关阅读: