当柳上原的风吹向天际的时候...

真正的快乐来源于创造

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks

 在一个程序中,相对User这个领域对象的诸属性进行修改,用来容纳存储数据的ActionForm是这样写的:

public final class ModifyUserForm extends ActionForm {
    
private static final long serialVersionUID = -3447738664240089399L;

    
private User user;
    
    
public ModifyUserForm(){

    }


    
public void reset(ActionMapping mapping, HttpServletRequest request) {
    }


    
public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) 
{

        ActionErrors errors 
= new ActionErrors();

        
return (errors);

    }


    
public User getUser() {
        
return user;
    }


    
public void setUser(User user) {
        
this.user = user;
    }

}

结果,进行页面数据验证的JS能准确无误的进行前段验证,但Action中没有收到请求,验证完毕提交表单后出现下面的异常,

HTTP Status 500 -


type Exception report

message

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

exception

javax.servlet.ServletException: javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.heyang.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:35)

 

root cause

javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:469)
org.apache.struts.chain.commands.servlet.PopulateActionForm.populate(PopulateActionForm.java:50)
org.apache.struts.chain.commands.AbstractPopulateActionForm.execute(AbstractPopulateActionForm.java:60)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.heyang.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:35)

 

root cause

java.lang.IllegalArgumentException: No bean specified
org.apache.commons.beanutils.PropertyUtilsBean.getPropertyDescriptor(PropertyUtilsBean.java:751)
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:937)
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:467)
org.apache.struts.chain.commands.servlet.PopulateActionForm.populate(PopulateActionForm.java:50)
org.apache.struts.chain.commands.AbstractPopulateActionForm.execute(AbstractPopulateActionForm.java:60)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.heyang.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:35)

 

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.


Apache Tomcat/6.0.10

发生这个错误的原因应该是使用工具类commons beanutil向ActionForm中的属性user输入数据时发生了错误,解决这个问题也很简单,在ActionForm内部将属性user实例化即可,代码如下:

public final class ModifyUserForm extends ActionForm {
    
private static final long serialVersionUID = -3447738664240089399L;

    
private User user=new User();
    
    
public ModifyUserForm(){

    }


    
public void reset(ActionMapping mapping, HttpServletRequest request) {
    }


    
public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) 
{

        ActionErrors errors 
= new ActionErrors();

        
return (errors);

    }


    
public User getUser() {
        
return user;
    }


    
public void setUser(User user) {
        
this.user = user;
    }

}

posted on 2009-01-15 16:06 何杨 阅读(725) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: