当jsp打开之后数据库中的数据立即加载到一个下拉菜单中
3个回答
2014-03-01
展开全部
可以先从servlet中获取数据库数据,然后反转到jsp页面;如下代码希望对你有所帮助:导航页面代码<script type="text/javascript">
function submitform(submitname){
document.firstform.flag.value=submitname;
document.firstform.submit();
}
</script>
</head>
<body> <form name="firstform" action="FirstServlet" method="post">
<input type="hidden" name="flag" value=""/>
<input type="button" name="addteacher" value="添加教师信息" onclick="submitform('addteacher')"/>
<input type="button" name="updateteacher" value="修改教师信息" onclick="submitform('updateteacher')"/>
<input type="button" name="deleteteacher" value="删除教师信息" onclick="submitform('deleteteacher')"/>
<input type="button" name="addstudent" value="添加学生信息" onclick="submitform('addstudent')"/>
<input type="button" name="updatestudent" value="修改学生信息" onclick="submitform('updatestudent')"/> servlet代码:String submitname=request.getParameter("flag");
System.out.println(submitname);
if("addstudent".equals(submitname)){
List<Teachers> list=new ArrayList<Teachers>();
list=tebo.selectAll();
request.setAttribute("teacherslist",list);
request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
}
if("updatestudent".equals(submitname)){
List<Teachers> list=new ArrayList<Teachers>();
list=tebo.selectAll();
request.setAttribute("teacherslist",list);
request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
}
if("deletestudent".equals(submitname)){
request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
}
if("addteacher".equals(submitname)){
request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
}
if("updateteacher".equals(submitname)){ request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
}
if("deleteteacher".equals(submitname)){ request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
} 返回到的jsp页面: ---------------------------------------------------------<br>
学生<br>
学生编号:<input type="text" name="studentnumber1" value=""/><br>
学生名称:<input type="text" name="studentname1" value=""/>选择授课教师:
<select name="option1">
<c:forEach items="${teacherslist}" var="teacher">
<option value="${teacher.teachernumber}">${teacher.teachername}</option>
</c:forEach>
</select><br>
<br>
function submitform(submitname){
document.firstform.flag.value=submitname;
document.firstform.submit();
}
</script>
</head>
<body> <form name="firstform" action="FirstServlet" method="post">
<input type="hidden" name="flag" value=""/>
<input type="button" name="addteacher" value="添加教师信息" onclick="submitform('addteacher')"/>
<input type="button" name="updateteacher" value="修改教师信息" onclick="submitform('updateteacher')"/>
<input type="button" name="deleteteacher" value="删除教师信息" onclick="submitform('deleteteacher')"/>
<input type="button" name="addstudent" value="添加学生信息" onclick="submitform('addstudent')"/>
<input type="button" name="updatestudent" value="修改学生信息" onclick="submitform('updatestudent')"/> servlet代码:String submitname=request.getParameter("flag");
System.out.println(submitname);
if("addstudent".equals(submitname)){
List<Teachers> list=new ArrayList<Teachers>();
list=tebo.selectAll();
request.setAttribute("teacherslist",list);
request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
}
if("updatestudent".equals(submitname)){
List<Teachers> list=new ArrayList<Teachers>();
list=tebo.selectAll();
request.setAttribute("teacherslist",list);
request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
}
if("deletestudent".equals(submitname)){
request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
}
if("addteacher".equals(submitname)){
request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
}
if("updateteacher".equals(submitname)){ request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
}
if("deleteteacher".equals(submitname)){ request.getRequestDispatcher("jsp/addstudent.jsp").forward(request, response);
} 返回到的jsp页面: ---------------------------------------------------------<br>
学生<br>
学生编号:<input type="text" name="studentnumber1" value=""/><br>
学生名称:<input type="text" name="studentname1" value=""/>选择授课教师:
<select name="option1">
<c:forEach items="${teacherslist}" var="teacher">
<option value="${teacher.teachernumber}">${teacher.teachername}</option>
</c:forEach>
</select><br>
<br>
2014-03-01
展开全部
这样就可以<%String[][] districts=ts.getAllDistrict();//从数据库查询的方法%><select name="District" style="width:150;height:22" onChange="change()">
<option value="">所有</option>
<%for(int i=0;i<districts.length;i++){//districts是二维数组
%>
<option value="<%=districts[i][0]%>" <%=District.equals(districts[i][0])?"selected":""%> ><%=districts[i][1]%></option>
<%
}%>
</select>
<option value="">所有</option>
<%for(int i=0;i<districts.length;i++){//districts是二维数组
%>
<option value="<%=districts[i][0]%>" <%=District.equals(districts[i][0])?"selected":""%> ><%=districts[i][1]%></option>
<%
}%>
</select>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-03-01
展开全部
楼主可否提供代码跟图作参考呢Q1341510526
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询