如何让页面提交了,但是让下拉框的值不改变
2013-08-09
展开全部
//TreeMap可以实现页面提交而下拉框不下刷新
public static void doQuery(QueryForm pQueryForm,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
TreeMap projectList = new TreeMap(); // 添加类型列表到对应的FORM
projectList = getProjecttypeList();
if(pQueryForm.getXksxbh()!=null&&pQueryForm.getXksxbh().length()>0){ //xksxbh是页面上下拉框的属性
pQueryForm.setXksxmc((String)projectList.get(pQueryForm.getXksxbh()));//xksxmc是要显示的值
}else{
pQueryForm.setXksxmc("");
}
CLog.println(projectList); //输出projectList里边的键值对
}
//写个静态方法把需要绑定下拉框的数据取出来存到actionForm里边去
public static TreeMap getProjecttypeList() throws //在actionForm里边建立一个TreepMap对象projecttypeList
Exception {
TreeMap tmDepartName = new TreeMap();
Connection Conn = null;
Statement Stmt = null;
try {
Conn = CDBManager.getConn();
Stmt = Conn.createStatement();
String sql = "select xksxbh,xksxmc from t_busiguidesys order by xksxbh"; // 查询出要的值
ResultSet rs = Stmt.executeQuery(sql);
while (rs.next()) {
tmDepartName.put(rs.getString(1), rs.getString(2)); // 把查询出来的数据以键值对存到TreeMap中
}
} catch (Exception e) {
throw e;
} finally {
if (Stmt != null) {
try {
Stmt.close();
} catch (Exception e) {
}
;
}
if (Conn != null) {
try {
Conn.close();
} catch (Exception e) {
}
;
}
}
return tmDepartName;
}
在actionForm里边加入3个属性
xksxbh //页面上下拉框的属性,重页面上获得.
xksxmc //页面上下拉框显示的值,
projectList //乘装查出来的数据
在界面上如果需要读出来用<bean:write name="SQueryForm" property="xksxmc"/>可以读出来 //name里边装的是在xml里边配置的form的别名
<html:select property ="xksxbh" styleClass="select" id="xksxbh" >
<html:option value="0">全部</html:option>
<html:optionsCollection property="projecttypeList" value="key" label="value"/>
</html:
public static void doQuery(QueryForm pQueryForm,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
TreeMap projectList = new TreeMap(); // 添加类型列表到对应的FORM
projectList = getProjecttypeList();
if(pQueryForm.getXksxbh()!=null&&pQueryForm.getXksxbh().length()>0){ //xksxbh是页面上下拉框的属性
pQueryForm.setXksxmc((String)projectList.get(pQueryForm.getXksxbh()));//xksxmc是要显示的值
}else{
pQueryForm.setXksxmc("");
}
CLog.println(projectList); //输出projectList里边的键值对
}
//写个静态方法把需要绑定下拉框的数据取出来存到actionForm里边去
public static TreeMap getProjecttypeList() throws //在actionForm里边建立一个TreepMap对象projecttypeList
Exception {
TreeMap tmDepartName = new TreeMap();
Connection Conn = null;
Statement Stmt = null;
try {
Conn = CDBManager.getConn();
Stmt = Conn.createStatement();
String sql = "select xksxbh,xksxmc from t_busiguidesys order by xksxbh"; // 查询出要的值
ResultSet rs = Stmt.executeQuery(sql);
while (rs.next()) {
tmDepartName.put(rs.getString(1), rs.getString(2)); // 把查询出来的数据以键值对存到TreeMap中
}
} catch (Exception e) {
throw e;
} finally {
if (Stmt != null) {
try {
Stmt.close();
} catch (Exception e) {
}
;
}
if (Conn != null) {
try {
Conn.close();
} catch (Exception e) {
}
;
}
}
return tmDepartName;
}
在actionForm里边加入3个属性
xksxbh //页面上下拉框的属性,重页面上获得.
xksxmc //页面上下拉框显示的值,
projectList //乘装查出来的数据
在界面上如果需要读出来用<bean:write name="SQueryForm" property="xksxmc"/>可以读出来 //name里边装的是在xml里边配置的form的别名
<html:select property ="xksxbh" styleClass="select" id="xksxbh" >
<html:option value="0">全部</html:option>
<html:optionsCollection property="projecttypeList" value="key" label="value"/>
</html:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询