还是把怎样servlet的结果集在JSP里以表格的方式显示的问题.在JSP里有错误.捣鼓了半天还是没搞出来.真的晕倒了!拜托大家帮忙看一下.....
谢谢.
下面是servlet:
package ta;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class Servlet1 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
DB sql=new DB();
//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();
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
conn=sql.getConn();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from MOKA");
session.setAttribute("date",rs);
if(rs==null){
out.println("<script>alert('对不起,您查询的信息不存在!!');</script>");
return;
}
else{
request.getRequestDispatcher("jsp1.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:里面提示getAttribute有错.
错误为:incomplitabletypesfound:java.lang.object,required:java.sql.ResultSet
表格错误显示为:提示要抛出异常.不明白,JSP要跑异常吗?
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.sql.*" %>
<%!
ResultSet rs = null;
%>
<% rs=request.getAttribute("date");%>
<html>
<head>
<title>
ok
</title>
</head>
<body bgcolor="#ffffff">
<table>
<tr>
<td><%= rs.getString(1) %></td>
<td><%= rs.getString(2) %></td>
<td><%= rs.getString(3) %></td>
</tr>
</table>
</body>
</html>
[此贴子已经被作者于2007-9-21 21:55:02编辑过]