jsp下拉列表框默认显示查询的一条数据
比如jsp页面下拉菜单中有“一班”、“二班”、“三班”等选项,我从数据库查询的数据是“三班”,怎样在下拉菜单中默认显示“三班”...
比如jsp页面下拉菜单中有“一班”、“二班”、“三班”等选项,我从数据库查询的数据是“三班”,怎样在下拉菜单中默认显示“三班”
展开
2016-02-16 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
jsp下拉列表框默认显示查询的一条数据可以给select标签赋值,只取其中的一条数据即可。
import java.util.ArrayList;
import java.util.Iterator;
public class Test{
ArrayList list;
// constructor; builds some sample data.
public Test(){
this.list = new ArrayList();
this.list.add(new String[]{"1", "January"});
this.list.add(new String[]{"2", "February"});
this.list.add(new String[]{"3", "March"});
this.list.add(new String[]{"4", "April"});
this.list.add(new String[]{"5", "May"});
this.list.add(new String[]{"6", "June"});
this.list.add(new String[]{"7", "July"});
this.list.add(new String[]{"8", "August"});
this.list.add(new String[]{"9", "September"});
this.list.add(new String[]{"10", "October"});
this.list.add(new String[]{"11", "November"});
this.list.add(new String[]{"12", "December"});
}
[B]
/**
* @return The months of the year as HTML Option tags.
* @param The number of the selected month as a string.
*/
public String getMonthAsOptions(String selectedMonth){
StringBuffer sb = new StringBuffer();
for(Iterator i = this.list.iterator(); i.hasNext(); ){
String[] m = (String[])i.next();
String monthNumber = m[0];
String monthText = m[1];
sb.append("<option value=\"");
sb.append(monthNumber);
sb.append("\"");
if(monthNumber.equals(selectedMonth))
sb.append(" selected");
sb.append(">");
sb.append(monthText);
sb.append("</option>\n");
}
return sb.toString();
}
[/B]
// main method for testing and debugging only
public static void main(String[] args){
String selectedMonth = "4";
if(args.length > 0)
selectedMonth = args[0];
Test test = new Test();
System.out.println(test.getMonthAsOptions(selectedMonth));
}
}
import java.util.ArrayList;
import java.util.Iterator;
public class Test{
ArrayList list;
// constructor; builds some sample data.
public Test(){
this.list = new ArrayList();
this.list.add(new String[]{"1", "January"});
this.list.add(new String[]{"2", "February"});
this.list.add(new String[]{"3", "March"});
this.list.add(new String[]{"4", "April"});
this.list.add(new String[]{"5", "May"});
this.list.add(new String[]{"6", "June"});
this.list.add(new String[]{"7", "July"});
this.list.add(new String[]{"8", "August"});
this.list.add(new String[]{"9", "September"});
this.list.add(new String[]{"10", "October"});
this.list.add(new String[]{"11", "November"});
this.list.add(new String[]{"12", "December"});
}
[B]
/**
* @return The months of the year as HTML Option tags.
* @param The number of the selected month as a string.
*/
public String getMonthAsOptions(String selectedMonth){
StringBuffer sb = new StringBuffer();
for(Iterator i = this.list.iterator(); i.hasNext(); ){
String[] m = (String[])i.next();
String monthNumber = m[0];
String monthText = m[1];
sb.append("<option value=\"");
sb.append(monthNumber);
sb.append("\"");
if(monthNumber.equals(selectedMonth))
sb.append(" selected");
sb.append(">");
sb.append(monthText);
sb.append("</option>\n");
}
return sb.toString();
}
[/B]
// main method for testing and debugging only
public static void main(String[] args){
String selectedMonth = "4";
if(args.length > 0)
selectedMonth = args[0];
Test test = new Test();
System.out.println(test.getMonthAsOptions(selectedMonth));
}
}
展开全部
/**假设查找出来的是其他资产
返回回来传到的参数是:message
**/
<select>
<%
if(message="其他资产")
out.println("<option selected='selected'>message</option>");
else
out.println("<<option >固定资产</option>");
%>
<select>
原理就是输出的结果在out.print的时候加个selected='selected'就可以了。楼主给分吧!!!!!
返回回来传到的参数是:message
**/
<select>
<%
if(message="其他资产")
out.println("<option selected='selected'>message</option>");
else
out.println("<<option >固定资产</option>");
%>
<select>
原理就是输出的结果在out.print的时候加个selected='selected'就可以了。楼主给分吧!!!!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以在<option>里用jstl 的el表达式判断来选择
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<select>
<option>一班</option>
<option>二班</option>
<option selected="selected">三班</option>
</select>
<option>一班</option>
<option>二班</option>
<option selected="selected">三班</option>
</select>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询