我使用的是ssh框架 我在action层的时候把值放入了session中 我跳转到了指定的页面 我想把session中的值动态的添加到下拉列表框中 请问有什么方法,最好写出demo
解决方案 »
- 求S2SH对数据库进行增删改查的实例?
- 两个关于前端展现技术方面的问题
- sql
- 收集:JAVA线程在进行堵塞式写Socket时被挂起后的解决办法
- struts中的error问题!
- ant编译脚本的错误"Default target 'dist' does not exists in project"
- 在线急问:开发soap程序用jbulider好吗?
- 请高手们来讨论java存在缓冲溢出漏洞么?
- 大家可以帮我看看下面的程序为什么不能运行啊
- 有关myeclipse的struts2项目,启动tomcat服务器的问题,下面是日志信息
- 求教多表查询时候怎么理清思路,我脑子乱了
- 关于struts传递参数是乱码
方法很多。
1.struts标签
2.javascript
3.jquery-select.js
随便了。。
var obj=document.getElementById('testCaseName'); //你的select标签的ID
obj.options.add(new Option("","")); //如果第一个是空,则这么填,否则不要这行
<%
String[] testCaseLst = new String{"aa","bb"};//假设这里的testCaseLst 是你的session取出来的对象列表
if (testCaseLst!=null){
for (int i = 0; i < testCaseLst.length; i++) {
String existName=testCaseLst[i]; //这里分别取到label和value。
%>
obj.options.add(new Option("<%=existName%>","<%=existName%>"));
<%
}
}
%>
</script>
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
</head> <body>
<a href="Select_conn.action">select</a> <select name="selectid">
<%
if (session.getAttribute("abc") != null) {
String str = session.getAttribute("abc").toString();
String[] _str = str.split(",");
for (int i = 0; i < _str.length; i++) {
%>
<option><%=_str[i]%></option>
<%
}
}
%>
</select>
</body>
</html>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts> <package name="StrutsAction" namespace="/" extends="struts-default">
<action name="Select_*" class="com.xlh.struts.action.ConnectionAction"
method="{1}">
<result name="success">index.jsp</result>
</action>
</package></struts>package com.xlh.struts.action;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;public class ConnectionAction extends ActionSupport { String msg = "fail" ;
public String conn() {
ActionContext context = ActionContext.getContext() ;
HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST) ;
request.getSession().setAttribute("abc","a,b,d") ;
msg = "success" ;
return msg ;
}
}
想把你的Bean放入作用域
之后在页面显示
demo
<c:choose>
<c:when test="${requestScope.admin.roleID == 1}">
<select name="role">
<option title="role" value="1" selected="selected">--------------1-------------- </option>
<option title="role" value="2">--------------2--------------</option>
</select>
</c:when>
<c:otherwise>
<select name="role">
<option title="role" value="1" >--------------1--------------</option>
<option title="role" value="2" selected="selected">--------------2-------------- </option>
</select>
</c:otherwise>
</c:choose>
<%
if (session.getAttribute("abc") != null) {
String str = session.getAttribute("abc").toString();
String[] _str = str.split(",");
for (int i = 0; i < _str.length; i++) {
%>
<option><%=_str[i]%></option>
<%
}
}
%>
这种代码出现在页面是非常的不舒服。
O(∩_∩)O哈哈~