struts表单提交多行数据_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > struts表单提交多行数据

struts表单提交多行数据

 2010/12/29 8:10:58  ymy131931  http://ymy131931.javaeye.com  我要评论(0)
  • 摘要:使用Struts提交多行数据以下是使用struts提交多行数据的例子,提交多行数据至SurveyListForm:提交页面form.jsp,用于提交两条数据,注意[]的使用:<FORMMETHOD=POSTACTION="survey.jui"><INPUTTYPE="text"NAME="surveys[0].checkPerson"><INPUTTYPE="text"NAME="surveys[1].checkPerson"><
  • 标签:数据 表单 struts
使用Struts提交多行数据
以下是使用struts提交多行数据的例子,提交多行数据至SurveyListForm:
提交页面form.jsp,用于提交两条数据,注意[]的使用:
<FORM METHOD=POST ACTION="survey.jui">
<INPUT TYPE="text" NAME="surveys[0].checkPerson">
<INPUT TYPE="text" NAME="surveys[1].checkPerson">

<INPUT TYPE="submit">

</FORM>

响应页面index.jsp(survey.jui),用于获得数据:
<logic:iterate id="survey" name="surveyListForm" property="surveys" indexId="index">

<html:text name="survey" property="checkPerson" indexed="true"/>

</logic:iterate>

struts-config.xml:
<form-beans>
  <form-bean name="surveyForm" type="com.fenet.insurance.crm.web.form.SurveyForm" />
  <form-bean name="surveyListForm" type="com.fenet.insurance.crm.web.form.SurveyListForm" />
</form-beans>

<action path="/survey" parameter="method" type="com.fenet.insurance.crm.web.action.SurveyAction"  name="surveyListForm" scope="request" validate="false">
  <forward name="method1" path="/index.jsp" />
</action>

SurveyAction:
public class SurveyAction extends Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        SurveyListForm sForm = (SurveyListForm)form;
        List list = sForm.getSurveys();
        for(int i=0; i<list.size(); i++){
            SurveyForm f = (SurveyForm)list.get(i);
            System.out.println(f.getCheckPerson());//后台打印多行数据         request.setAttribute("surveys", sForm);
        return mapping.findForward("method1"); }

SurveyListForm定义多行数据:
public class SurveyListForm extends BaseForm{

    private List surveys = new AutoArrayList (SurveyForm.class);

  
    public List getSurveys() {
        return surveys;
    }

  
    public void setSurveys(List surveys) {
        this.surveys = surveys;
    }

SurveyForm:
public class SurveyForm extends BaseForm{
    private String checkPerson;     public String getCheckPerson() {
        return checkPerson;   
    public void setCheckPerson(String checkPerson) {
        this.checkPerson = checkPerson; }

AutoArrayList,用于自动创建List里面的对象:
public class AutoArrayList extends ArrayList {
    private Class itemClass;
    public AutoArrayList(Class itemClass) {
        this.itemClass = itemClass;     public Object get(int index) {
        try {
            while (index >= size()) {
                add(itemClass.newInstance());         } catch (Exception e) {
            e.printStackTrace();         return super.get(index); }
发表评论
用户名: 匿名