Java 应用程序类“org.springframework.web.servlet.support.BindStatus.”引发异常:141
我得到这个错误,应用程序类抛出异常Java 应用程序类“org.springframework.web.servlet.support.BindStatus.”引发异常:141,java,spring,Java,Spring,我得到这个错误,应用程序类抛出异常 org.springframework.web.servlet.support.BindStatus.:141 java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'luhnFormBean' available as request attribute at org.springframework.web.servlet
org.springframework.web.servlet.support.BindStatus.:141
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'luhnFormBean' available as request attribute
at org.springframework.web.servlet.support.BindStatus.(BindStatus.java:141)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
at org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
at org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:119)
at org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:89)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
at com.ibm._jsp._luhnCheck._jspx_meth_form_label_0(_luhnCheck.java:129)
at com.ibm._jsp._luhnCheck._jspx_meth_form_form_0(_luhnCheck.java:217)
at com.ibm._jsp._luhnCheck._jspService(_luhnCheck.java:98)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:101)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1240)
at [internal classes]
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:215)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1033)
at [internal classes]
请帮忙
代码如下所示:
@Controller
public class LuhnController {
private ILuhnCheckService luhnCheckService;
public void setLuhnCheckService(ILuhnCheckService luhnCheckService){
this.luhnCheckService = luhnCheckService;
}
@ModelAttribute("luhnFormBean")
@RequestMapping(value = "/validateLuhn",method = RequestMethod.POST)
public String validateLuhn(@ModelAttribute("luhnFormBean") LuhnFormBean luhnFormBean,Model model){
// LuhnFormBean luhnFormBean= new LuhnFormBean();;
System.out.println(luhnCheckService.validateLuhn(luhnFormBean.getCcNumber()));
return "luhnFormBean";
}
@ModelAttribute("luhnFormBean")
@RequestMapping(value = "/validateLuhn",method = RequestMethod.GET)
public ModelAndView validateLuhn() {
return new ModelAndView("/luhnCheck", "luhnFormBean", new LuhnFormBean());
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>example</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/Example-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Example</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Example</servlet-name>
<url-pattern>/web/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/jsp/home.jsp</welcome-file>
</welcome-file-list>
</web-app>
示例-Servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:component-scan base-package="example" />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
JSP
您的Spring控制器有很多问题 首先,在方法级别指定@modeldattribute。在方法级别,注释的目的是为控制器中的所有@RequestMapping方法共享表单bean的构造逻辑。像这样注释的方法的正确返回类型是表单类型LuhnFormBean。这里的情况并非如此 其次,@RequestMapping bean的返回类型是视图名称字符串或模型和视图ModelAndView。为什么validateLuhn方法返回字符串luhnFormBean?你有这样的看法吗
第三,同样的!方法validateLuhn,您在方法级别和参数级别定义了@ModelAttribute。参数的注释是指定将绑定到表单参数的表单bean,方法的注释是告诉Spring如何创建表单bean。同样的方法不能同时做这两件事。那没有道理 @sh0rug0ru-谢谢你的回答,但我已经更正了上面所说的所有内容,但我仍然面临着同样的错误,为什么我们会出现这个错误?请反映你在问题中所做的更改。此外,你的表格中有一个空白方法,你确实想发布,对吗?。指定的操作是验证,但指定的控制器未映射到该路径。
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Luhn Validation</title>
</head>
<body>
<div align="center">
<form:form method="" action="validate" modelAttribute="luhnFormBean">
<table border="0">
<tr>
<td><form:label path="ccNumber"><b> Card Number</b></form:label></td>
<td><form:input path="ccNumber" /></td>
</tr>
</table>
<input type="submit" value="Submit" />
</form:form>
</div>
</body>
</html>