如何将JSP的查询请求在数据库中查到值在新的JSP页面一一展现出来?
建立个网页,需要实现查询功能,然后跳转到新的JSP页面,但是我用数据库的数据输入查询以后跳转到的新的JSP页面却不能把我查询到那个表给展现出来 我知道是JSP页面没有将servlets中的查询到的结果对象给解析出来 应该怎么写那个JSP页面。
这个是我的servlets
bmServlet.java
public class bmServlet extends HttpServlet {
public bmServlet() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException,
IOException {
//定义取得的值的编码格式
request.setCharacterEncoding("utf-8");
//取值。定义一个变量a 等于 YWFL 它的值通过request的getParameter方法获得
String a = request.getParameter("YWFL");
String b = request.getParameter("BMMC");
String c = request.getParameter("YWMSR");
System.out.println(a);
System.out.println(b);
System.out.println(c);
// response.setContentType("text/html");
// PrintWriter out = response.getWriter();
// out.println(a);
//定义sql的 SQL语句
String sql= "select * from b_lx_bm";
sql = sql+ " where YWFL = '"+a+"' and BMMC='"+b+"' and YWMSR='"+c+"'";
System.out.println(sql);
ArrayList rslist = zxSql(sql);
//设置返回对象
request.setAttribute("queryResult", rslist);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
try{
request.setAttribute("bmServlet", "updata");
getServletConfig().getServletContext().getRequestDispatcher("/updata.jsp").forward(request,response);
}catch(Exception e){
e.printStackTrace();
}
}
/*
* 取连接
*/
public Connection getOracleConnect() {
Connection ct = null;
try {
// 1,加载驱动程序
Class.forName("oracle.jdbc.driver.OracleDriver");
// 2,得到连接
ct = DriverManager.getConnection(
"jdbc:oracle:thin:@dbserver:1521:oracdb",
"scott", "tiger");
} catch (Exception e) {
e.printStackTrace();
} finally {
return ct;
}
}
public ArrayList zxSql(String sql) {
//sql="select * from b_lx_bm ";
Connection ct = null;