Jsp页面:
<%
Connection conn = null;
Statement st;
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
SQLServerDataSource ds = new SQLServerDataSource();
connections
conn = ds.getConnection();
st=conn.createStatement();
if(request.getQueryString() != null){
String Batch1=request.getQueryString();
String Id1=request.getParameter("Id");
String s ="select columns from Table where Id="+Id1+"and BatchID="+BatchId1+"";
st = conn.createStatement();
ResultSet res;
PreparedStatement prep = conn.prepareStatement(s);
res=prep.executeQuery();
String col1=null;
String col2=null;
while(res.next()){
TicketNum = res.getString("col1");
PatientName = res.getString("col2");
}
request.setAttribute("col1",col1);
request.setAttribute("col2",col2);
}
%>
<input type="text" id="txtBatchName" class="form-control" name="txtBatchName" value="<%=request.getParameter("Id")%>"/>
//same like that all text boxes
<%
}
catch(Exception e){
e.printStackTrace();
} %>
我的servlet重定向页面:
if(i>0)
request.setAttribute("message", "Successfully Updated!...");
request.getRequestDispatcher("Update.jsp").forward(request, response);