2
我想在第一個下拉列表中保留值。我應該如何保留從下拉列表中提交的值?我希望批量代碼參數值應該被選中。如何在提交後保留jsp下拉列表中的值
這是我的代碼,到目前爲止我嘗試過。
<%@page import="com.database.DatabaseConnection"%>
<%@page import="com.model.StudentRegOperation"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="">
<%
DatabaseConnection db (DatabaseConnection)getServletContext().getAttribute("connection");
Connection con=db.getConnection();
StudentRegOperation so=new StudentRegOperation();
so.setConnection(db);
Vector<String> data=so.showBatches();
Iterator<String> itr=data.iterator();
%>
<select name="batchCode" id="batchCode" onchange="this.form.submit()" >
<option>Batches</option>
<%
while(itr.hasNext())
{
%>
<option <%if(request.getParameter("batchCode")!=null){%> selected="selected" <%} %> > <%=itr.next() %></option>
<%
}
%>
</select>
<%
String batchCode=request.getParameter("batchCode");
if(batchCode!=null)
{
Vector<String> batches=so.showRegId(batchCode);
Iterator<String> itr2=batches.iterator();
%>
<br> <select name="regId" id="regId" onchange="this.form.submit()" >
<%
while(itr2.hasNext())
{%>
<option><%=itr2.next() %></option>
<%
}%>
</select>
<%
}
else
{
%>
<br><select ><option>Roll No</option></select>
<%
}
%>
</form>
</body>
</html>
我想第一選擇標記的那個值當我選擇任何選項 –
thankuu提交應保留,。我知道了 –
@MohitJindal wc ..請接受答案,如果它幫助.. –