简体   繁体   English

IllegalStateException:BeanResult'getAppointment'的BindingResult和普通目标对象都不能用作请求属性

[英]IllegalStateException: Neither BindingResult nor plain target object for bean name 'getAppointment' available as request attribute

I m newbie to spring.I know my question is already answered here. 我是春天的新手。我知道我的问题已经在这里回答了。 but solution is not working for me. 但解决方案对我不起作用。 So I m posting my question here. 所以我在这里发布我的问题。 I m trying to handle multiple forms.I have 3 forms. 我正在尝试处理多种形式。我有3种形式。 1st form working properly. 第一种形式正常工作。 second form it is showing jasper exception. 第二种形式显示碧玉异常。

Category.java Category.java

public class Category {
    String category;
    String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }
}

MyController.java MyController.java

@Controller    
public class MyController {
    List<String> listOFDoc=new ArrayList<String>();


    @RequestMapping(value="/category", method = RequestMethod.GET)
    public ModelAndView category(){

        return new ModelAndView("Category","command",new Category());

    }
    @RequestMapping(value="/getDoc",method=RequestMethod.POST)
    public ModelAndView getDoc(@ModelAttribute("command")Category c,Model model){

    //  model.addAttribute("list", c.getCategory());
model.addAttribute(new TypeOfDoc());
        String type=c.getCategory();
        System.out.println(type);
        if(type.equalsIgnoreCase("dentist")){
            listOFDoc.add("rj");
            listOFDoc.add("c");
        }
        if(type.equalsIgnoreCase("ortho")){
            listOFDoc.add("w");
            listOFDoc.add("x");
        }
        model.addAttribute("name", new Category());
        model.addAttribute("listOfDoc", listOFDoc);
        return new ModelAndView("List", "getAppointment", new Category());
    }

/*  @RequestMapping(value="/getDoc")
    public ModelAndView listOfDoc(){

        return new ModelAndView("List","getAppointment",new TypeOfDoc());

    }*/
    @RequestMapping(value="/showAppointment",method=RequestMethod.POST)
    public String showAppo(@ModelAttribute("getAppointment")TypeOfDoc type,BindingResult results,ModelMap model){
        return "appointment";

    }

}

List.jsp List.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
 <%@ 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=ISO-8859-1">
<title>List OF doctors</title>
</head>
<%-- <body>
<c:forEach items="${listOfDoc}" var="doc">
<c:out value="${doc}"></c:out>
<br>
 </c:forEach> --%>

  <form:form method="POST" commandName="getAppointment" action="/Jmeter/appointment">
<form:select path="name">
<form:options items="${listOfDoc}"/>
</form:select>
<br>
</form:form>  
<input type="submit" value="submit">


</body>
</html>

Category.jsp: Category.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" 
           uri="http://java.sun.com/jsp/jstl/core" %>
 <%@ taglib prefix="h" 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=ISO-8859-1">
<title>Catogory</title>
</head>
<body>
<h:form method="POST" action="/Jmeter/getDoc.htm" commandName="command" ><!-- 
<select >
<option value="dentist"  label="dentist">
</option>
<option value="ortho"  label="ortho"></option>
</select> -->
<h:select path="category">

<h:option value="ortho" label="ortho"></h:option>
<h:option value="dentist" label="dentist"></h:option>
</h:select>
<br>
<input type="submit" value="submit">
</h:form>
</body>
</html>

Stacktrace 堆栈跟踪

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'getAppointment' available as request attribute
    org.springframework.web.servlet.support.BindStatus.<init>(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.SelectTag.writeTagContent(SelectTag.java:194)
    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.page.List_jsp._jspx_meth_form_005fselect_005f0(List_jsp.java:222)
    org.apache.jsp.WEB_002dINF.page.List_jsp._jspx_meth_form_005fform_005f0(List_jsp.java:187)
    org.apache.jsp.WEB_002dINF.page.List_jsp._jspService(List_jsp.java:139)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

You have a form 你有一个表格

 <form:form method="POST" commandName="getAppointment" action="/Jmeter/appointment">

Where is your action mapping. 您的动作映射在哪里。 , something like following. ,类似以下内容。 As the error says "Neither BindingResult nor plain target object for bean name 'getAppointment' available as request attribute", you must have this in your action class 由于错误显示“ Bean名称'getAppointment'的BindingResult和普通目标对象都不能用作请求属性”,因此您的操作类中必须具有此对象

@RequestMapping(value = "/appointment", method = RequestMethod.POST)
public String getAppointment(ModelMap map, HttpServletRequest request)
{
    map.addAttribute("getAppointment",
            yourAppointmentObject);
    //  do something
    return "Jmeter/";//some url
}

Neither BindingResult nor plain target object for bean name 'getAppointment' available as request attribute Bean名称“ getAppointment”的BindingResult和普通目标对象都不能用作请求属性

From the code you posted, it is apparent that the getAppointment object(TypeOfDoc) is not available when loading the List.jsp page. 从您发布的代码中可以看出,加载List.jsp页面时, getAppointment对象(TypeOfDoc)不可用。 To resolve this issue, you can simply add aa RequestMapping.GET method in the controller class which returns that object. 要解决此问题,您只需在控制器类中添加一个RequestMapping.GET方法即可返回该对象。

For form processing, you got to have a RequestMapping.GET method in the controller to load/pre-populate the form and RequestMapping.POST method to handle the form submission. 对于表单处理,您必须在控制器中具有RequestMapping.GET方法以加载/预填充表单,并具有RequestMapping.POST方法以处理表单提交。

For the form - <form:form method="POST" commandName="getAppointment" action="/Jmeter/appointment"> 对于表单- <form:form method="POST" commandName="getAppointment" action="/Jmeter/appointment">

To prepopulate the form data, you can use the method below in the controller. 要预填充表单数据,可以使用控制器中的以下方法。

@RequestMapping(value = "/appointment", method = RequestMethod.GET)
    public ModelAndView getAppoinymrny() {
        TypeOfDoc typeOfDoc = new TypeOfDoc();

        //your logic to add some data to typeOfDoc object so that it can be prepopulated in the form.

        ModelAndView mav = new ModelAndView("List", "getAppointment", typeOfDoc);
        return mav;
    }

Then when you submit the form, the below controller method will be called and you can do further processing.. 然后,在提交表单时,将调用以下控制器方法,然后可以进行进一步处理。

@RequestMapping(value="/appointment",method=RequestMethod.POST)
    public String showAppo(@ModelAttribute("getAppointment")TypeOfDoc type,BindingResult results,ModelMap model){

          //your logic
        return "appointmentSuccess";
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalStateException:Bean名称“ CityInfos”的BindingResult和普通目标对象都不能用作请求属性 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'CityInfos' available as request attribute java.lang.IllegalStateException: Bean 名称“ecole”的 BindingResult 和普通目标 object 都可用作请求属性 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'ecole' available as request attribute java.lang.IllegalStateException:BeanResult&#39;subscription&#39;的BindingResult和普通目标对象都不能用作请求属性 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'subscription' available as request attribute java.lang.IllegalStateException:BeanResult&#39;userData&#39;的BindingResult和普通目标对象都不能用作请求属性 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'userData' available as request attribute java.lang.IllegalStateException:BeanResult&#39;logpo&#39;的BindingResult和普通目标对象都不能用作请求属性 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'logpo' available as request attribute java.lang.IllegalStateException:Bean名称“会话”的BindingResult和普通目标对象都不能用作请求属性 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'session' available as request attribute Spring Webflow IllegalStateException:BeanResult的BindingResult和普通目标对象都不可用作请求属性 - Spring Webflow IllegalStateException: Neither BindingResult nor plain target object for bean name available as request attribute java.lang.IllegalStateException:BeanResult&#39;login&#39;的BindingResult和普通目标对象都不能用作请求属性 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'login' available as request attribute java.lang.IllegalStateException: BindingResult 和 bean 名称“category”的普通目标对象都不能用作请求属性 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'category' available as request attribute java.lang.IllegalStateException:Bean名称“ versetmonth”的BindingResult和普通目标对象都不能用作请求属性 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'versetmonth' available as request attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM