是不是必须在每个JSP页面上写如下代码
Vector CLASSA_CODE = new Vector();
CLASSA_CODE.add(new LabelValueBean("d","e"));
pageContext.setAttribute("CLASSA_CODE",CLASSA_CODE);如果这么写了每次进入这个页的时候都要执行他,那么如果在页面上有若干个文本框和若干个下拉列表,第二次再进入这个页的时候文本框的值会被保留,但是下拉列表的值就被还原了,请问怎么做才能不还原.

解决方案 »

  1.   

    从数据库读出的数据是放在集合里吧
    可以用struts的迭代标签去读啊,然后显示在下拉列表里
    或者是用EL表达式去迭代
      

  2.   

    利用STRUTS标签:<html:select/>
    具体用法如下:
    <html:select name="testForm" property="select01">
    <html:optionsCollection name="testForm" property="testList"  value="KEY" label="NAME"/>
    </html:select>在<html:select> 中: 
    name - 表单名称
    property - 回调取值变量名称<html:optionsCollection>中:
    name="testForm": name - 表单名称
    property="testList": property - 一个类型为java.util.List的变量,存储的是下拉列表要显示的值和名称的LIST
    value="KEY": value - 下拉列表的value值
    label="NAME":label - 下拉列表的label值一般做法:
    将下拉列表里的label和value放在hashmap里,然后加到list中,这样利用标签就能自动回显。
      

  3.   

    在action里把从数据库读出的数据放到一个集合里
    然后把这个集合传给view,通过struts的迭代标签显示为下拉列表 
      

  4.   

    html:select+html:option后者是用来显示默认第一行的,当然也可以设为'empty'
      

  5.   

    把列表中的数据放到list中
    然后用request中的setAttribute()方法传到jsp页面上
    在页面上接收。最后在循环输出就可以了
      

  6.   

    如果放到LIST里面,然后传给页面能不能保留上次选的值不变.
      

  7.   

    在ACTION中的代码
    HashMap hmp = new HashMap();
    hmp.put("labe1", "aa");
    hmp.put("labe2", "bb");
    hmp.put("labe2", "cc");
    List testList = new ArrayList();
    testList.add(hmp);
    request.setAttribute("testCollection", testList);
    return mapping.findForward("success");
    页面中的代码是
    <html:select name="testCollection" property="param1">
    <html:optionsCollection name="testCollection" property="testList"  value="value" label="label"/>
    </html:select> 
    错误信息
    org.apache.jasper.JasperException: An exception occurred processing JSP page /test2.jsp at line 1310: </head>
    11: <body>
    12: <html:form  action="/test2/sample.do?method=display" method="post">
    13: <html:select name="testCollection" property="param1">
    14:  <html:optionsCollection name="testCollection" property="testList"  value="value" label="label"/>
    15: </html:select> 
    16: </html:form>
    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)请问哪里不对呢