我有这个控制器代码,它抛出上述错误。到昨天为止,一切正常,我不知道同事对该代码做了什么,今天我看到了错误:
Bean名称“ sideForm”的BindingResult或普通目标对象都不能用作请求属性
你能建议我在哪里寻找这种错误。我在POST或GET方法声明中犯了任何错误还是返回了错误的东西?
非常感谢你的帮助:)
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>
确保你的Spring表单提及modelAttribute="<Model Name"
。
例:
@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;
}
}
在你的JSP中:
<form:form modelAttribute="greeting" method="POST" action="greeting.html">
问题内容: 我在网上查看了几乎所有与该问题有关的答案,但在我的代码中找不到该问题。 这是我的JSP页面。 当我删除 工作正常。我可以与控制器通信。因此问题与这条线有关。 这是我的web.xml 这是我的servlet-context.xml 还有我的applicationContext.xml 我可能在XML文件中做错了。我对于这个spring是新来的-hibernate员工,请耐心等待。谢谢..
当我只留下表显示可用的比萨饼与链接“删除”,一切显示正常,删除也正常工作。 我想表单和控制器@modelAttribute有问题,但我找不到确切的问题,我在controller中添加了与表单相同的属性--“mypiza”,这应该可以工作(至少从我在Google上找到的东西来看)。 有人能告诉我们是什么阻碍了这个应用程序的工作,以及如何解决这个问题吗?如果需要其他配置文件,我可以提供它们。
我正在尝试使用Spring读取我在Twitter和Facebook上找到的状态,并将它们发布到SQLite数据库中。每当我尝试运行我的Spring项目时,我都会得到以下错误: 谢谢你,亚当·巴里
嘿,我是从Spring开始的,但是我发现了这个异常并且无法解决它这是我的jsp 这是我的控制器 这是个例外
公共类EcoleProvenance实现Serializable{ 这是我的控制器 我的html 任何时候,如果我逃跑,我会得到这个答案 2020-06-08 04:48:28.465错误11644--[nio-8080-exec-9]O.A.c.c.c.[.[/].[dispatcherServlet]:路径为[]的上下文中servlet[dispatcherServlet]的servlet.s
我一直试图提交一个html表单到spring boot,但无法使其工作。 我的pom.xml中有这个 我的application.properties文件中有以下内容: 我还有一个名为index.html的类似html文件,位于 但代码似乎无法识别taglib,因为我在web页面中看到了以下内容: 注意taglib是如何不被识别的,只是打印在页面的顶部? Whitelabel错误页面此应用程序没有