Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring BindingResult和bean名称的普通目标对象都不能作为请求属性使用_Spring_Spring Mvc - Fatal编程技术网

Spring BindingResult和bean名称的普通目标对象都不能作为请求属性使用

Spring BindingResult和bean名称的普通目标对象都不能作为请求属性使用,spring,spring-mvc,Spring,Spring Mvc,各位专家, 我有一个抛出上述错误的控制器代码。直到昨天,它还可以正常工作,我不知道同事对此代码做了什么,今天我看到了错误: bean名称“sideForm”的BindingResult和普通目标对象都不能作为请求属性使用 你能建议我在哪里查找这种错误吗。我是否在POST或GET方法声明中出错或返回了错误的内容 非常感谢您的帮助:) package com.att.analytics.ui; 导入java.util.array; 导入java.util.Collection; 导入java.uti

各位专家, 我有一个抛出上述错误的控制器代码。直到昨天,它还可以正常工作,我不知道同事对此代码做了什么,今天我看到了错误:

bean名称“sideForm”的BindingResult和普通目标对象都不能作为请求属性使用

你能建议我在哪里查找这种错误吗。我是否在POST或GET方法声明中出错或返回了错误的内容

非常感谢您的帮助:)

package com.att.analytics.ui;
导入java.util.array;
导入java.util.Collection;
导入java.util.List;
导入javax.servlet.http.HttpServletRequest;
导入org.apache.log4j.Logger;
导入org.springframework.stereotype.Controller;
导入org.springframework.ui.ModelMap;
导入org.springframework.web.bind.annotation.ModelAttribute;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入com.si.myworld.business.AdminChart;
导入com.si.myworld.business.Chart;
导入com.si.myworld.dao.AdminChartSummaryData;
导入com.si.myworld.dao.BulletinData;
导入com.si.myworld.dao.ChartData;
@请求映射(“/index.html”)
@控制器
公共类索引控制器{
私有静态最终记录器log=Logger.getLogger(IndexController.class);
/**
*调用以最初加载页面(GET请求)
* 
*@param模型
*@返回
*/
@RequestMapping(method=RequestMethod.GET)
公共字符串getCharts(ModelMap模型){
图表=新图表();
图表。设定时间线(“每月”);
图表.设置开始日期(“mm/dd/yyyy”);
图表setEndDt(“mm/dd/yyyy”);
AdminChartSummaryData acsd=新的AdminChartSummaryData();
List List=acsd.getLandingChartDataList();
if(list.size()==4){
Chart chart1=新图表(list.get(0));
ChartChart2=新图表(list.get(1));
ChartChart3=新图表(list.get(2));
ChartChart4=新图表(list.get(3));
模型投入(“图表1”,图表1);
模型投入(“图表2”,图表2);
模型投入(“图表3”,图表3);
模型投入(“图表4”,图表4);
log.info(“图表1>>>”+图表1);
ChartData cd=新的ChartData();
字符串chartOneDatasource=cd.fetchChartDatasourceName(chart1
.getChartSubgroup());
字符串chartTwoDatasource=cd.fetchChartDatasourceName(chart2
.getChartSubgroup());
字符串chartThreeDatasource=cd.fetchChartDatasourceName(chart3
.getChartSubgroup());
字符串chartFourDatasource=cd.fetchChartDatasourceName(chart4
.getChartSubgroup());
String breadcrumbOne=chart1.getChartGroup()+“>>”
+chart1.getChartSubgroup();
字符串breadcrumbTwo=chart2.getChartGroup()+“>>”
+chart2.getChartSubgroup();
String breadcrumbThree=chart3.getChartGroup()+“>>”
+chart3.getChartSubgroup();
字符串breadcrumbFour=chart4.getChartGroup()+“>>”
+chart4.getChartSubgroup();
BulletinData bd=新BulletinData();
字符串bulletin=bd.getBulletinData();
模型放置(“侧形”,图表);
model.put(“chartOneDatasource”,chartOneDatasource);
model.put(“chartTwoDatasource”,chartTwoDatasource);
model.put(“chartThreeDatasource”,chartThreeDatasource);
model.put(“chartFourDatasource”,chartFourDatasource);
模型放置(“面包屑骨”,面包屑骨);
模型.put(“breadcrumbTwo”,breadcrumbTwo);
模型放置(“面包屑三”,面包屑三);
模型放置(“面包屑四”,面包屑四);
模型放置(“公告”,公告);
}
归还“土地”;
}
@RequestMapping(method=RequestMethod.POST)
公共字符串加载图表(HttpServletRequest请求、ModelMap模型、@ModelAttribute(“侧形”)图表){
字符串from_date=request.getParameter(“startDt”);
字符串to_date=request.getParameter(“endDt”);
图表.设置开始日期(自_日期起);
图表.setEndDt(截止日期);
ChartData cd=新的ChartData();
BulletinData bd=新BulletinData();
字符串bulletin=bd.getBulletinData();
AdminChartSummaryData acsd=新的AdminChartSummaryData();
List List=acsd.getLandingChartDataList();
if(list.size()==4){
Chart chart1=新图表(list.get(0));
ChartChart2=新图表(list.get(1));
ChartChart3=新图表(list.get(2));
ChartChart4=新图表(list.get(3));
模型投入(“图表1”,图表1);
模型投入(“图表2”,图表2);
模型投入(“图表3”,图表3);
模型投入(“图表4”,图表4);
字符串chartOneDatasource=cd.fetchChartDatasourceName(chart1
.getChartSubgroup());
字符串chartTwoDatasource=cd.fetchChartDatasourceName(chart2
.getChartSubgroup());
字符串chartThreeDatasource=cd.fetchChartDatasourceName(chart3
.getChartSubgroup());
字符串chartFourDatasource=cd.fetchChartDatasourceName(chart4
.getChartSubgroup());
model.put(“chartOneDatasource”,chartOneDatasource);
model.put(“chartTwoDatasource”,chartTwoDatasource);
model.put(“chartThreeDatasource”,chartThreeDatasource);
model.put(“chartFourDatasource”,chartFourDatasource);
String breadcrumbOne=chart1.getChartGroup()+“>>”
+chart1.getChartSubgroup();
字符串breadcrumbTwo=chart2.getChartGroup()+“>>”
+chart2.getChartSubgroup();
String breadcrumbThree=chart3.getChartGroup()+“>>”
+chart3.getChartSubgroup();
字符串breadcrumbFour=chart4.getChartGroup()+“>>”
+chart4.getChartSubgroup();
模型放置(“面包屑骨”,面包屑骨);
模型.put(“breadcrumbTwo”,breadcrumbTwo);
模型放置(“面包屑
package com.att.analytics.ui;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.si.myworld.business.AdminChart;
import com.si.myworld.business.Chart;
import com.si.myworld.dao.AdminChartSummaryData;
import com.si.myworld.dao.BulletinData;
import com.si.myworld.dao.ChartData;

@RequestMapping("/index.html")
@Controller
public class IndexController {

private static final Logger log = Logger.getLogger(IndexController.class);

/**
 * Called to load the page initially (GET request)
 * 
 * @param model
 * @return
 */
@RequestMapping(method = RequestMethod.GET)
public String getCharts(ModelMap model) {

    Chart chart = new Chart();
    chart.setTimeline("Monthly");
    chart.setStartDt("mm/dd/yyyy");
    chart.setEndDt("mm/dd/yyyy");

    AdminChartSummaryData acsd = new AdminChartSummaryData();
    List<AdminChart> list = acsd.getLandingChartDataList();

    if (list.size() == 4) {
        Chart chart1 = new Chart(list.get(0));
        Chart chart2 = new Chart(list.get(1));
        Chart chart3 = new Chart(list.get(2));
        Chart chart4 = new Chart(list.get(3));
        model.put("chart1", chart1);
        model.put("chart2", chart2);
        model.put("chart3", chart3);
        model.put("chart4", chart4);

        log.info("chart 1>>>>" + chart1);


        ChartData cd = new ChartData();

        String chartOneDatasource = cd.fetchChartDatasourceName(chart1
                .getChartSubgroup());
        String chartTwoDatasource = cd.fetchChartDatasourceName(chart2
                .getChartSubgroup());
        String chartThreeDatasource = cd.fetchChartDatasourceName(chart3
                .getChartSubgroup());
        String chartFourDatasource = cd.fetchChartDatasourceName(chart4
                .getChartSubgroup());

        String breadcrumbOne = chart1.getChartGroup() + ">>"
                + chart1.getChartSubgroup();
        String breadcrumbTwo = chart2.getChartGroup() + ">>"
                + chart2.getChartSubgroup();
        String breadcrumbThree = chart3.getChartGroup() + ">>"
                + chart3.getChartSubgroup();
        String breadcrumbFour = chart4.getChartGroup() + ">>"
                + chart4.getChartSubgroup();


        BulletinData bd = new BulletinData();
        String bulletin = bd.getBulletinData();

        model.put("sideForm", chart);



        model.put("chartOneDatasource", chartOneDatasource);
        model.put("chartTwoDatasource", chartTwoDatasource);
        model.put("chartThreeDatasource", chartThreeDatasource);
        model.put("chartFourDatasource", chartFourDatasource);

        model.put("breadcrumbOne", breadcrumbOne);
        model.put("breadcrumbTwo", breadcrumbTwo);
        model.put("breadcrumbThree", breadcrumbThree);
        model.put("breadcrumbFour", breadcrumbFour);

        model.put("bulletin", bulletin);
    }

    return "land";
}


@RequestMapping(method = RequestMethod.POST)
public String loadCharts(HttpServletRequest request, ModelMap model, @ModelAttribute("sideForm") Chart chart) {

    String from_date = request.getParameter("startDt");
    String to_date = request.getParameter("endDt");

    chart.setStartDt(from_date);
    chart.setEndDt(to_date);

    ChartData cd = new ChartData();

    BulletinData bd = new BulletinData();
    String bulletin = bd.getBulletinData();



    AdminChartSummaryData acsd = new AdminChartSummaryData();
    List<AdminChart> list = acsd.getLandingChartDataList();
    if (list.size() == 4) {
        Chart chart1 = new Chart(list.get(0));
        Chart chart2 = new Chart(list.get(1));
        Chart chart3 = new Chart(list.get(2));
        Chart chart4 = new Chart(list.get(3));
        model.put("chart1", chart1);
        model.put("chart2", chart2);
        model.put("chart3", chart3);
        model.put("chart4", chart4);


        String chartOneDatasource = cd.fetchChartDatasourceName(chart1
                .getChartSubgroup());
        String chartTwoDatasource = cd.fetchChartDatasourceName(chart2
                .getChartSubgroup());
        String chartThreeDatasource = cd.fetchChartDatasourceName(chart3
                .getChartSubgroup());
        String chartFourDatasource = cd.fetchChartDatasourceName(chart4
                .getChartSubgroup());

        model.put("chartOneDatasource", chartOneDatasource);
        model.put("chartTwoDatasource", chartTwoDatasource);
        model.put("chartThreeDatasource", chartThreeDatasource);
        model.put("chartFourDatasource", chartFourDatasource);

        String breadcrumbOne = chart1.getChartGroup() + ">>"
                + chart1.getChartSubgroup();
        String breadcrumbTwo = chart2.getChartGroup() + ">>"
                + chart2.getChartSubgroup();
        String breadcrumbThree = chart3.getChartGroup() + ">>"
                + chart3.getChartSubgroup();
        String breadcrumbFour = chart4.getChartGroup() + ">>"
                + chart4.getChartSubgroup();


        model.put("breadcrumbOne", breadcrumbOne);
        model.put("breadcrumbTwo", breadcrumbTwo);
        model.put("breadcrumbThree", breadcrumbThree);
        model.put("breadcrumbFour", breadcrumbFour);
    }
    return "land";
}


@ModelAttribute("timeline")
public Collection<String> populateTimeline() {
    return Arrays.asList("Daily", "Weekly", "Monthly", "Quarterly",
            "Annually", "12_Month_Rolling");
}
}
<form:form commandName="sideForm">
<div style="font-weight:bold; color:#000">Timeline</div>


<div style="margin:0 0 5px 0;"><form:select path="timeline" items="${timeline}" id="tm"/></div>

<div class="tofrom">From:</div>

<form:input path="startDt" id="from_date" size="7" maxlength="10" />

<div class="tofrom">To:</div>

<form:input path="endDt" id="to_date" size="7" maxlength="12" />

<input type="submit" value="Update Chart" />

</form:form>
@RequestMapping(method = RequestMethod.POST)
public String loadCharts(HttpServletRequest request, ModelMap model, @ModelAttribute("sideForm") Chart chart) 
...
@RequestMapping(method = RequestMethod.POST)
public String loadCharts(@ModelAttribute("sideForm") Chart chart, BindingResult bindingResult, HttpServletRequest request, ModelMap model) 
...
@Controller
@RequestMapping("/greeting.html")
public class GreetingController {

 @ModelAttribute("greeting")
 public Greeting getGreetingObject() {
  return new Greeting();
 }

 /**
  * GET
  * 
  * 
  */
 @RequestMapping(method = RequestMethod.GET)
 public String handleRequest() {
  return "greeting";
 }

 /**
  * POST
  * 
  * 
  */
 @RequestMapping(method = RequestMethod.POST)
 public ModelAndView processSubmit(@ModelAttribute("greeting") Greeting greeting, BindingResult result){
  ModelAndView mv = new ModelAndView();
  mv.addObject("greeting", greeting);  
  return mv;
 }
}
<form:form  modelAttribute="greeting" method="POST" action="greeting.html">
<form:form action="/securedArea" commandName="uploadItem" enctype="multipart/form-data"></form:form>
@RequestMapping("/securedArea")
@Controller
public class SecureAreaController {

@RequestMapping(method = RequestMethod.GET)
public String showForm(Model model) {
            UploadItem uploadItem = new UploadItem(); // declareing

            model.addAttribute("uploadItem", uploadItem); // adding in model
    return "securedArea/upload";
}

}
<html>
<body>
    <table>
        <tr><td><a href="Login.html">Login</a></td></tr>
    </table>
</body>
</html>
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">

    <property name="prefix">
        <value>/WEB-INF/jsp/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>
<bean id="urlMapping"
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="urlMap">
        <map>              
            <entry key="/Login.html">
                <ref bean="userController"/>
            </entry>
        </map>          
    </property>             
</bean>     
 <bean id="userController" class="controller.AddCountryFormController">     
       <property name="commandName"><value>country</value></property>
       <property name="commandClass"><value>controller.Country</value></property>        
       <property name="formView"><value>countryForm</value></property>
       <property name="successView"><value>countryForm</value></property>
   </bean>      
package controller;

import javax.servlet.http.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.mvc.SimpleFormController;


public class AddCountryFormController extends SimpleFormController
{

    public AddCountryFormController(){
        setCommandName("Country.class");
    }

    protected ModelAndView onSubmit(HttpServletRequest request,HttpServletResponse response,Object command,BindException errors){

            Country country=(Country)command;

            System.out.println("calling onsubmit method !!!!!");

        return new ModelAndView(getSuccessView(),"country",country);

    }

}
package controller;

public class Country
{
    private String countryName;

    public void setCountryName(String value){
        countryName=value;
    }

    public String getCountryName(){
        return countryName;
    }

}
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<body>
    <form:form commandName="country" method="POST" >
            <table>
                    <tr><td><form:input path="countryName"/></td></tr>
                    <tr><td><input type="submit" value="Save"/></td></tr>
            </table>
    </form:form>
</body>
<html>
*HTTP Status 500 - 
--------------------------------------------------------------------------------
type Exception report
message 
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/employe.jsp at line 12
9: <form:form method="POST" commandName="command"  action="/SpringWeb/addEmploye">
10:    <table>
11:     <tr>
12:         <td><form:label path="name">Name</form:label></td>
13:         <td><form:input path="name" /></td>
14:     </tr>
15:     <tr>
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:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause 
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
    org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
    org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
    org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
    org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:119)
    org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:89)
    org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
    org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
    org.apache.jsp.WEB_002dINF.jsp.employe_jsp._jspx_meth_form_005flabel_005f0(employe_jsp.java:185)
    org.apache.jsp.WEB_002dINF.jsp.employe_jsp._jspx_meth_form_005fform_005f0(employe_jsp.java:120)
    org.apache.jsp.WEB_002dINF.jsp.employe_jsp._jspService(employe_jsp.java:80)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.26 logs.*