| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 560 人关注过本帖
标题:再次向诸位请教.....(封贴)
取消只看楼主 加入收藏
uukkcc
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2007-7-24
收藏
 问题点数:0 回复次数:1 
再次向诸位请教.....(封贴)

还是把怎样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编辑过]

搜索更多相关主题的帖子: import java servlet JSP sql 
2007-09-21 17:41
uukkcc
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2007-7-24
收藏
得分:0 
好的.谢谢.
2007-09-21 21:45
快速回复:再次向诸位请教.....(封贴)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028085 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved