用Struts1做的一个项目。Struts-config.xml配置是:(有的东西省略了)
<form-bean name="newform" type="forms.tuangou.TuanGouForm" />
        <action path="/new" name="newform" input="newTuangou.jsp"
type="actions.tuangou.ActionNewCreate">
<forward name="success" path="houtai/index.jsp" />
<forward name="fail" path="fail.jsp" />
</action>
前台JSP页面:
<form id="login-user-form" method="post" class="validator"
action="../new.do" enctype="multipart/form-data">
<div class="wholetip clear">
<h3>
1、基本信息
</h3>
</div>
<div class="field">
<label>
城市及分类
</label>....Action中:
public ActionForward execute(ActionForm form, ActionMapping mapping,
HttpServletRequest request, HttpServletResponse response) {
ActionForward forward = null;
NewCreateDao dao = new NewCreateImp();
TuanGouForm forms = (TuanGouForm) form;
System.out.println("ActionNewCreat:form:"+form.toString());
System.err.println("ActionNewCreat:forms:city:"+forms.getCity());输出的结果是:
ActionNewCreat:form:forms.tuangou.TuanGouForm@f55759
ActionNewCreat:forms:city:null疑问:
ActionNewCreat:form:forms.tuangou.TuanGouForm@f55759说明ActionForm已经被实例化为我想要的TuanGouForm,但是为什么得不到前台JSP页面中的值?我在TuanGouForm中已经自动生成了set和get方法。

解决方案 »

  1.   

    好吧。刚才自己解决了这个问题。
    之所以ActionForm得不到数据是因为我在JSP页面的<Form>中是写了enctype="multipart/form-data"这句话,我原本的意思是想用SmartUpload上传文件的,但是写了这句话之后上传的数据都是以二进制的方式传递的,这就造成ActionForm得不到数据。那我该怎么才能上传数据?不用SmartUpload也可以