Java 从servlet转发请求和响应时停止执行jsp页面查询 在我的jsp页面中,有基于Id的select查询,这些值分配给文本框值 我有servlet页面,在servlet页面中,我更新了查询并将dsiplaying消息重定向到jsp页面 当我在jsp页面中从servlet重定向到jsp时,它再次在select query中执行jsp页面,这里id值为null,它显示所有文本框的null值。 如何在不执行id值为null的jsp select查询的情况下执行此操作
Jsp页面:Java 从servlet转发请求和响应时停止执行jsp页面查询 在我的jsp页面中,有基于Id的select查询,这些值分配给文本框值 我有servlet页面,在servlet页面中,我更新了查询并将dsiplaying消息重定向到jsp页面 当我在jsp页面中从servlet重定向到jsp时,它再次在select query中执行jsp页面,这里id值为null,它显示所有文本框的null值。 如何在不执行id值为null的jsp select查询的情况下执行此操作,java,jsp,servlets,Java,Jsp,Servlets,Jsp页面: <% Connection conn = null; Statement st; try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); SQLServerDataSource ds = new SQLServerDataSource(); connections conn = ds.getConnection(); st=conn.c
<%
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();
} %>
不要在jsp页面上执行代码片段。它是一个存放HTML数据的地方,而不是Java。在servlet中执行此操作,并使用
request.setAttribute()
向jsp提供数据。通过这一点,您可以决定在jsp页面上显示哪些内容。您好,@KarelG,这里我在页面加载时将一个页面重定向到另一个页面,只需为文本框赋值,就可以接收jsp页面(如页面加载)。你能告诉我在哪里用页面加载代替jsp页面吗谢谢
if(i>0)
request.setAttribute("message", "Successfully Updated!...");
request.getRequestDispatcher("Update.jsp").forward(request, response);