我在SERVLET里查询出数据库的结果集信息.需要把他们单独用表格显示在JSP里.请问该怎么做?最好有完整代码让我学习一下.
谢谢.
我在servlet里里的代码如下:
package go;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import dao.Sql;
public class PetsQueryServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
dao.Sql sql=new Sql();//实例化一个SQL对象
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
Connection conn=null;
HttpSession session=request.getSession();//得到session
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
conn=sql.getConn();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from KADANG");
session.setAttribute("rs",rs);//将结果集放进session
if(rs==null){
out.println("<script>alert('对不起,您查询的信息不存在!!');</script>");
return;
}
else{
request.getRequestDispatcher("solo.jsp");
}
} catch (Exception ex) {
System.out.println(ex.getStackTrace());
}
out.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
下面是JSP代码:(不知道怎样把RS用表格的形式显示出来.请指点一下.)
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>
PetsQuery
</title>
</head>
<body bgcolor="#ffffff">
<c:forEach var="ok" items="${requestScope.rs}">
</c:forEach>
</body>
</html>
<c:forEach var="prod" items="${requestScope.prouudct}">
${prod}
</c:forEach>
[此贴子已经被作者于2007-9-21 15:53:56编辑过]