jsp怎样获取下拉框的值
<%Serviceservice=newServiceImpl();List<TopicVo>lt=service.findTopic();for(inti=0;i<lt...
<%
Service service = new ServiceImpl();
List<TopicVo> lt =service.findTopic();
for(int i =0;i<lt.size();i++){
TopicVo t =lt.get(i);
%>
<label> 主题 </label>
<select name="ntid">
<option value='<%=t.getId() %>'><%=t.getName() %></option>
<%} %>
</select> 展开
Service service = new ServiceImpl();
List<TopicVo> lt =service.findTopic();
for(int i =0;i<lt.size();i++){
TopicVo t =lt.get(i);
%>
<label> 主题 </label>
<select name="ntid">
<option value='<%=t.getId() %>'><%=t.getName() %></option>
<%} %>
</select> 展开
展开全部
jsp获取下拉列表的值并显示:
参考例子:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
request.setCharacterEncoding("GB18030");//加上这一句解决的
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
//存放下来菜单对应值的数组
ArrayList nu = new ArrayList();
nu.add("一");
nu.add("二");
nu.add("三");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'testselect.jsp' starting page</title>
</head>
<body>
通过request.getParameter("number")方法取得下拉框选取的值
<form method=post action="testselect.jsp"> <!-- 提交给自身 -->
<select name=number>
<%
for (int i = 0; i < nu.size(); i++) {
out.print("<option>" + nu.get(i) + "</option>");
}
%>
</select>
<input type="submit" value="提交" name="submit">
</form>
</body>
<%
//取得提交的数字,并显示
String n = (String) request.getParameter("number");
out.print("选的值是:" + n);
%>
</html>
参考例子:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
request.setCharacterEncoding("GB18030");//加上这一句解决的
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
//存放下来菜单对应值的数组
ArrayList nu = new ArrayList();
nu.add("一");
nu.add("二");
nu.add("三");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'testselect.jsp' starting page</title>
</head>
<body>
通过request.getParameter("number")方法取得下拉框选取的值
<form method=post action="testselect.jsp"> <!-- 提交给自身 -->
<select name=number>
<%
for (int i = 0; i < nu.size(); i++) {
out.print("<option>" + nu.get(i) + "</option>");
}
%>
</select>
<input type="submit" value="提交" name="submit">
</form>
</body>
<%
//取得提交的数字,并显示
String n = (String) request.getParameter("number");
out.print("选的值是:" + n);
%>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |