spring mvc 求助,请高人指点 Neither BindingResult nor plain target object for bean name 'command' available as request attribute

itservant 2008-11-15 02:57:57
web-config.xml

<bean id="SBrandController"
class="UEngine.Younext.Controller.SBrandController">
<property name="commandClass"><value>UEngine.Younext.PO.BrandForm</value></property>
<property name="cnUtil"><ref bean="CnUtil"/></property>
<property name="sessionUtil"><ref bean="SessionUtil"/></property>
<property name="userGlobalCheck"><ref bean="UserGlobalCheck"/></property>
<property name="brandDAO"><ref bean="BrandDAO"/></property>
<property name="brandAdd" value="brandAdd"/>
<property name="brandMdy" value="brandMdy"/>
<property name="brandList" value="brandList"/>
<property name="redirectPage" value="login.do"/>
</bean>


SBrandController.java

public class SBrandController extends SimpleFormController {
CnUtil cnUtil;
SessionUtil sessionUtil;
UserGlobalCheck userGlobalCheck;
IBrandDAO brandDAO;
String brandAdd,brandMdy,brandList,redirectPage;

public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException exception)
throws Exception {
BrandForm brandForm = (BrandForm)command;
System.out.println("s start");
if(!this.getUserGlobalCheck().checkOnlineUser(request)){
return new ModelAndView(new RedirectView(this.getRedirectPage()));
}

int userViewID = 0;

if(cnUtil.RidNull(brandForm.getBrandName()).length() > 50 || cnUtil.RidNull(brandForm.getBrandName()).length() <= 0){
System.out.println("e01");
return findModelAndView(brandForm.getSMethod(), exception, "品牌信息的合法长度为1 - 25个字符!");
}
if(cnUtil.RidNull(brandForm.getSMethod()).equalsIgnoreCase("add")){
if(this.getBrandDAO().existSameBrandByUIDAndBName(userViewID, cnUtil.RidNull(brandForm.getBrandName()))){
System.out.println("e02");
return findModelAndView(brandForm.getSMethod(), exception, "您所添加的品牌已存在!");
}
}
if(cnUtil.RidNull(brandForm.getSMethod()).equalsIgnoreCase("mdy") && brandForm.getBrandID() <= 0){
return findModelAndView(brandForm.getSMethod(), exception, "数据处理出错!如有任何问题请与管理员联系!!");
}
System.out.println("s 01");

Brand brandInfo = new Brand();
if(cnUtil.RidNull(brandForm.getSMethod()).equalsIgnoreCase("mdy")){brandInfo.setBrandid(new Integer(brandForm.getBrandID()));}
brandInfo.setBrandname(cnUtil.RidNull(brandForm.getBrandName()));
brandInfo.setUserid(new Integer(userViewID));
this.getBrandDAO().saveBrandInfo(brandInfo);
System.out.println("s 02");

return new ModelAndView(this.getBrandList());
}

public ModelAndView findModelAndView(String fromUrl, BindException exception, String errorCode){
exception.rejectValue("brandName", "no_brandName", errorCode);
if(cnUtil.RidNull(fromUrl).equalsIgnoreCase("mdy")){
return new ModelAndView(this.getBrandMdy(), exception.getModel());
}else{
return new ModelAndView(this.getBrandAdd(), exception.getModel());
}
}

public CnUtil getCnUtil() {
return cnUtil;
}

public void setCnUtil(CnUtil cnUtil) {
this.cnUtil = cnUtil;
}

public SessionUtil getSessionUtil() {
return sessionUtil;
}

public void setSessionUtil(SessionUtil sessionUtil) {
this.sessionUtil = sessionUtil;
}

public UserGlobalCheck getUserGlobalCheck() {
return userGlobalCheck;
}

public void setUserGlobalCheck(UserGlobalCheck userGlobalCheck) {
this.userGlobalCheck = userGlobalCheck;
}

public IBrandDAO getBrandDAO() {
return brandDAO;
}

public void setBrandDAO(IBrandDAO brandDAO) {
this.brandDAO = brandDAO;
}

public String getBrandAdd() {
return brandAdd;
}

public void setBrandAdd(String brandAdd) {
this.brandAdd = brandAdd;
}

public String getBrandMdy() {
return brandMdy;
}

public void setBrandMdy(String brandMdy) {
this.brandMdy = brandMdy;
}

public String getRedirectPage() {
return redirectPage;
}

public void setRedirectPage(String redirectPage) {
this.redirectPage = redirectPage;
}

public String getBrandList() {
return brandList;
}

public void setBrandList(String brandList) {
this.brandList = brandList;
}
}


BrandForm.java
public class BrandForm {
private int brandID;
private String brandName;
private String sMethod;

public int getBrandID() {
return brandID;
}
public void setBrandID(int brandID) {
this.brandID = brandID;
}
public String getBrandName() {
return brandName;
}
public void setBrandName(String brandName) {
this.brandName = brandName;
}
public String getSMethod() {
return sMethod;
}
public void setSMethod(String method) {
sMethod = method;
}
}


brandAdd.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/younext.css">
<title>younext</title>
</head>

<body>
<form name='form' action='sbrand.do' method='post'>
<spring:bind path="command.*">
<font color="red"> <b>${status.errorMessage}</b> </font>
</spring:bind>
<table cellpadding="2" cellspacing="1" border="0" width="300" class="border" align="left">
<tr class="title">
<td><strong>品牌--增加</strong>
<input type='text' name='sMethod' value='add'>
<input type='text' name='brandID' value='0'>
</td>
</tr>
<tr class="tdbg">
<td>

</td>
</tr>
<tr class="tdbg">
<td>名称:</td>
</tr>
<tr>
<td class="tdbg">
<spring:bind path='command.brandName'>
<input type='text' name='${status.expression}' value='${status.value}'>
</spring:bind>
</td>
</tr>
<tr class="tdbg">
<td align="center"><input type='submit' value='添加'></td>
</tr>
</table>
</form>
</body>
</html>


以上为源码

运行时总是出现
type Exception report

message

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

exception

javax.servlet.ServletException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute



请哪位高人指点下
...全文
2682 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
kevihu 2009-02-13
  • 打赏
  • 举报
回复
不能直接訪問jsp,但有時候,是忘記配置了~
如忘記加:
/supplyOriginalform.html=supplyOriginalFormController
這樣的話supplyOriginalform.html就直接到jsp了.

51,411

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧