使用下面这个jsp的前 你需要写一个Stu类 生成set和get方法
Public Class Stu{ private int idprivate String namepublic void setId(int id){ this id=id} public int getId(){ return this id} public void setName(String name){ this name=name} public String getName(){ return this name} }
写个简单的servlet
public class gotoMall extends HttpServlet { public void doGet(HttpServletRequest request HttpServletResponse response) throws ServletException IOException { ArrayList<Stu>stus=new ArrayList<Stu>()Stu stu =new Stu()stu setId( )stu setName("aa")stu setId( )stu setName("bb")stus add(stu )stus add(stu )request setAttribute("stus" stus)request getRequestDispatcher("/WEB INF/admin/my jsp") forward(request response)} public void doPost(HttpServletRequest request HttpServletResponse response) throws ServletException IOException { this doGet(request response)} }
my jsp
lishixinzhi/Article/program/Java/JSP/201311/19829
jsp下拉框主要使用select和option标签进行创建,如下代码:
<html><body>
<span style="absolutemargin-top:-12px">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td align="left"><!-- 创建一个下拉框-->
<span style="position:absoluteborder:1pt solid #c1c1c1overflow:hiddenwidth:188pxheight:19pxclip:rect(-1px 190px 190px 170px)">
<select name="aabb" id="aabb" style="width:190pxheight:20pxmargin:-2px" onChange="changeF()">
<option value="" style="color:#c2c2c2">---请选择---</option>
<option value="闲人书库">闲人书库</option>
<option value="闲人BLOG">闲人BLOG</option>
<option value="<a href="http://www.ayinsky.com" target="_blank">闲人设计</a>"><a href="http://www.ayinsky.com" target="_blank">闲人设计</a></option>
<option value="闲人软件">闲人软件</option>
</select>
</span>
<span style="position:absoluteborder-top:1pt solid #c1c1c1border-left:1pt solid #c1c1c1border-bottom:1pt solid #c1c1c1width:170pxheight:19px">
<input type="text" name="ccdd" id="ccdd" value="可选择也可输入的下拉框" style="width:170pxheight:15pxborder:0pt">
</span>
</td>
</tr>
</table>
</span>
</body>
<script language="javascript">
function changeF()
{
// 从下面的赋值可以的值,你在action 中只要得到name =“ccdd” 的值就可以了。
document.getElementById('ccdd').value=document.getElementById('aabb').options[document.getElementById('aabb').selectedIndex].value
}
</script>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)