[Spring MVC] Neither BindingResult nor plain target object for bean name 'user' available

在学习Spring MVC的过程中,当使用了Spring中自带的标签时,就碰到了Neither BindingResult nor plain target object for bean name 'user' available as request attribute这个非法语句异常"BindingResult和Bean name'user'的普通目标对象都不可用作请求属性",其实意思就是没有找到对象请求绑定类。

HTTP Status 500 - An exception occurred processing JSP page /WEB-INF/jsp/user/useradd.jsp at line 17


type Exception report

message An exception occurred processing JSP page /WEB-INF/jsp/user/useradd.jsp at line 17

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/user/useradd.jsp at line 17

14: 
15: 
16:      
17:  用户编码: 
18: 
19:  用户名称: 
20:   
Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:465) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java:620) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)


root cause

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
	org.springframework.web.servlet.support.BindStatus.(BindStatus.java:144)
	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154)
	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:141)
	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:132)
	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:116)
	org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422)
	org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
	org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
	org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
	org.apache.jsp.WEB_002dINF.jsp.user.useradd_jsp._jspx_meth_fm_005finput_005f0(useradd_jsp.java:293)
	org.apache.jsp.WEB_002dINF.jsp.user.useradd_jsp._jspService(useradd_jsp.java:138)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286)
	org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.57 logs.


Apache Tomcat/7.0.57



贴上我出问题的代码useradd.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="fm" uri="http://www.springframework.org/tags/form" %>







Insert title here




     
用户编码: 

用户名称: 
 
用户密码: 

用户生日:
用户地址:
联系电话:
用户角色: 系统管理员 经理 普通用户

注: 如下代码非常重要,有这行代码才能正常使用spring的标签
<%@ taglib prefix="fm" uri="http://www.springframework.org/tags/form" %>
当我在服务器中运行会出现如下错误(相关的web.xml等已经配置好),经过我查阅众多资料,终于明白所谓的目标类找不到的问题了,只要在useradd.jsp加上代码:

推荐您阅读更多有关于“”的文章

你可能感兴趣的:([Spring MVC] Neither BindingResult nor plain target object for bean name 'user' available)