throws IOException {}是什么东东呀?

qzfty 2003-06-09 09:03:17
qxdji.jsp页面:

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ include file="../session.jsp"%>
<html>
<head><title>缺陷登记
</title>
<link rel=stylesheet href="style.css" type="text/css">
<script language="JavaScript">
function newwin(url) {
var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450");
newwin.focus();
return false;
}
</script>
</head>
<body>
<script LANGUAGE="javascript">
function submit11()
{
self.location.replace("qxdji.jsp")
}
</script>
<jsp:useBean id="bbsBean" scope="page" class="firm.firm" />
<%
int pageLine=10;
int totalRec=0;
int totalSub=0;
int intPage=1;
if (request.getParameter("page")!=null)
intPage=Integer.parseInt(request.getParameter("page"));
try{
ResultSet countrs=null;
//指定参考行数
//取得总数
countrs=bbsBean.executeQuery("select count(*) as cnt from board");
if (countrs.next())
totalRec=countrs.getInt("cnt");
countrs.close();
bbsBean.closeStmt();
//取得主题数
countrs=bbsBean.executeQuery("select count(*) as cnt from board");
if (countrs.next())
totalSub=countrs.getInt("cnt");
countrs.close();
bbsBean.closeStmt();
}
catch(Exception e){
e.printStackTrace();
}
//取得每行的主题数量
int jtemp=totalRec/pageLine+1;
int totalSubPerPage=totalSub/jtemp;
//取得总页数
int intPageCount=0;
intPageCount=(totalSub/totalSubPerPage * 10 + 5)/10 ;
%>
<center><font color="blue"><h4>设备缺陷登记管理</h4></font>
<%
out.print("<table border='1' cellspacing='0' width='632' bgcolor='#d7e3b9' bordercolorlight='#green' bordercolordark='#ECF5FF'>");
out.print("<tr align='center' bgcolor='#c8cc98'>");
out.print("<td width='240'>标题</td>");
out.print("<td width='60'>发表人</td>");
//out.print("<td width='100'>发表时间</td>");
out.print("<td width='40'>状态</td>");
out.print("<td width='40'>管理</td>");
out.print("</tr>");
%>
<%
String serial;
String title;
String recorder;
//Date providedate;
ResultSet RS=bbsBean.executeQuery("select * from board where parent_no=0 order by serial_no DESC");
int i=0;
while (RS.next()) {
i++;//-----------------显示本级的帖子内容
if (i>(totalSubPerPage *(intPage-1)) && (i<=(intPage * totalSubPerPage))){
out.print("<tr><td>");
serial=RS.getString("serial_no");
title=RS.getString("title");
recorder=RS.getString("recorder");
//providedate=RS.getDate("time");
// showing(request,out,serial,title,recorder,providedate,"Subject");
showing(request,out,serial,title,recorder,"Subject");
//-----------------显示下一级的回复内容
ResultSet RS1 = bbsBean.executeQuery("select * from board where parent_no=" + serial + " order by serial_no");
while (RS1.next()) {
out.print("<tr><td>");
serial=RS1.getString("serial_no");
title=RS1.getString("title");
recorder=RS1.getString("recorder");
// providedate=RS1.getDate("time");
//showing(request,out,serial,title,recorder,providedate,"Re");
showing(request,out,serial,title,recorder,"Re");
}
RS1.close();
bbsBean.closeStmt();
//------------------------
}
}
RS.close();
bbsBean.closeStmt();
%>
<!--以下函数用于帖子内容显示 -->
<%!
void showing(HttpServletRequest request,JspWriter out,String serial,String title,String recorder, String ReSign)
throws IOException {
if(ReSign=="Subject"){
out.print("<a href=bbsAnswer.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
}
else{
out.print("<a href=bbsReply.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
}
out.print("</td><td align='center'>");
out.print(recorder);
out.print("</td></tr>");
}
%>
<!--以下用于帖子分页显示 -->
<%
out.print("<tr>");
out.print("<a href='qxdj.jsp '>缺陷登记</a> ");
if (intPage < 1 )
intPage=1;
out.print("<form method='POST' name=fPageNum action='qxdji.jsp'>");
out.print("<p align='left'>>>分页 ");
if (intPage<2)
out.print("<font color='999966'>首页 上一页</font> ");
else{
out.print("<a href='qxdji.jsp?page=1'>首页</a> ");
out.print("<a href='qxdji.jsp?page=" + (intPage-1) + "'>上一页</a> " );
}
if( intPage-intPageCount>=0 )
out.print("<font color='999966'>下一页 尾页</font>" );
else{
out.print("<a href='qzdji.jsp?page=" + (intPage+1)+ "'>下一页</a> <a href='qxdji.jsp?page=" + intPageCount + "'>尾页</a>");
}
out.print(" 页次:<strong><font color=red>"+intPage+"</font>/"+intPageCount+"</strong>页 " );
out.print(" 共<b>"+totalRec+"</b>条记录 <b>"+pageLine+"</b>条/页 " );
out.print(" 转到第<input type='text' name='page' size=2 maxlength=10 class=smallInput value="+intPage+">");
out.print("页<input class=buttonface type='submit' value='GO' name='cndok'></span></p></form>" );
out.print("</td>");
out.print("</tr>");
out.print("</table>");
out.print("</center>");
%>
</p>
</body>
</html>


---------------------------报错信息----------------------------------

Note: sun.tools.javac.Main has been deprecated.
D:\resin-2.1.6\doc\program\new\quexian\qxdji.jsp:107: Class _program._new._quexian.IOException
not found in throws.
throws IOException {
^
D:\resin-2.1.6\doc\program\new\quexian\qxdji.jsp:109: Exception java.io.IOException
must be caught, or it must be declared in the throws clause of this method.
out.print("<a href=bbsAnswer.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
^
D:\resin-2.1.6\doc\program\new\quexian\qxdji.jsp:133: Class _program._new._quexian.IOException
not found in try.
try {
^
3 errors, 1 warning
-------------------------------------------------------------------------

请高手指点。谢谢。。。。
...全文
163 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
CsnowerS 2003-06-10
  • 打赏
  • 举报
回复
你的rs1,rs2...不是全局变量,不在作用域内rs.close(),肯定会报没有定义的错误,方法1用biggie(飞碟) 的说法,方法2在对rs操作前定义变量,ResultSet rs1=null;ResultSet rs2=null;.....
biggie 2003-06-10
  • 打赏
  • 举报
回复
作用域问题
在{ 这里定义的东西,只对这内生效} 在外面不生效
所以你最后的rs2.rs3.rs4都会提示你没有定义的错误

解决方法
把你的rs2.rs3.rs4在你应用完成后的作用域内关闭掉就可以了,不用在最后关闭

在最后只把conn和stmt关掉就行
zuoyangguang 2003-06-10
  • 打赏
  • 举报
回复
rs是啥子玩艺儿啊
qzfty 2003-06-10
  • 打赏
  • 举报
回复
今天一开始的时候好使的。但我切换了到98然后又回到XP就不好使了。
qzfty 2003-06-10
  • 打赏
  • 举报
回复
我在IF语句之前加System.out.println("OK");但是调试信息和以前一样。还有我不知道控制台是什么?不好意思。我初级哦。呵呵。还有你说的换个方式。可以说的具体点吗?
biggie 2003-06-10
  • 打赏
  • 举报
回复
if (i>(totalSubPerPage *(intPage-1)) && (i<=(intPage * totalSubPerPage))){
在这句之前加一个
System.out.println("OK");
看一看控制台能不能打出来,如果能的话说明你sql3能取出值,如果不能的话,那就说明没取出值

如果显示ok那么注释掉showing(request,out,serial,title,recorder,"Subject");
试试是否正常,然后在找问题原因

--------题外话:你怎么能这么写程序呢?换个方式去写,这么写很拉圾,而且不容易查错
qzfty 2003-06-10
  • 打赏
  • 举报
回复
请再帮我分析一下,谢谢!
qzfty 2003-06-10
  • 打赏
  • 举报
回复
biggie(飞碟):你好!
我把问题从新说一下:

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ include file="../session.jsp"%>
<html>
<head><title>缺陷登记
</title>
<link rel=stylesheet href="style.css" type="text/css">
<script language="JavaScript">
function newwin(url) {
var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450");
newwin.focus();
return false;
}
</script>
</head>
<body>
<script LANGUAGE="javascript">
function submit11()
{
self.location.replace("qxdji.jsp")
}
</script>
<jsp:useBean id="bbsBean" scope="page" class="firm.firm" />
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=MyDatabase";
//pubs为你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

int pageLine=10;
int totalRec=0;
int totalSub=0;
int intPage=1;
if (request.getParameter("page")!=null)
intPage=Integer.parseInt(request.getParameter("page"));
try{
String sql="select count(*) as cnt from board";
ResultSet rs=stmt.executeQuery(sql);
//指定参考行数
//取得总数
if (rs.next())
totalRec=rs.getInt("cnt");
rs.close();
//取得主题数
String sql2="select count(*) as cnt from board";
ResultSet rs2=stmt.executeQuery(sql2);
if (rs2.next())
totalSub=rs2.getInt("cnt");
rs2.close();
}
catch(Exception e){
e.printStackTrace();
}
//取得每行的主题数量
int jtemp=totalRec/pageLine+1;
int totalSubPerPage=totalSub/jtemp;
//取得总页数
int intPageCount=0;
intPageCount=(totalSub/totalSubPerPage * 10 + 5)/10 ;
%>
<center><font color="blue"><h4>设备缺陷登记管理</h4></font>
<%
out.print("<table border='1' cellspacing='0' width='632' bgcolor='#d7e3b9' bordercolorlight='#green' bordercolordark='#ECF5FF'>");
out.print("<tr align='center' bgcolor='#c8cc98'>");
out.print("<td width='240'>标题</td>");
out.print("<td width='60'>发表人</td>");
//out.print("<td width='100'>发表时间</td>");
out.print("<td width='40'>状态</td>");
out.print("<td width='40'>管理</td>");
out.print("</tr>");
%>
<%
String serial;
String title;
String recorder;
//Date providedate;
String sql3="select * from board where parent_no=0 order by serial_no DESC";
ResultSet rs3=stmt.executeQuery(sql3);
int i=0;
while (rs3.next()) {
i++;//-----------------显示本级的帖子内容
if (i>(totalSubPerPage *(intPage-1)) && (i<=(intPage * totalSubPerPage))){
out.print("<tr><td>");
serial=rs3.getString("serial_no");
title=rs3.getString("title");
recorder=rs3.getString("recorder");
//providedate=RS.getDate("time");
// showing(request,out,serial,title,recorder,providedate,"Subject");
showing(request,out,serial,title,recorder,"Subject");
//-----------------显示下一级的回复内容
String sql4="select * from board where parent_no=" + serial + " order by serial_no";
ResultSet rs4=stmt.executeQuery(sql4);
while (rs4.next()) {
out.print("<tr><td>");
serial=rs4.getString("serial_no");
title=rs4.getString("title");
recorder=rs4.getString("recorder");
// providedate=RS1.getDate("time");
//showing(request,out,serial,title,recorder,providedate,"Re");
showing(request,out,serial,title,recorder,"Re");
}
rs4.close();
}
}
rs3.close();
%>
<!--以下函数用于帖子内容显示 -->
<%!

void showing(HttpServletRequest request,JspWriter out,String serial,String title,String recorder, String ReSign)
throws IOException {
try{
if(ReSign=="Subject"){
out.print("<a href=bbsAnswer.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
}
else{
out.print("<a href=bbsReply.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
}
out.print("</td><td align='center'>");
out.print(recorder);
out.print("</td></tr>");
}
catch(Exception e)
{System.out.println(e);}
}
%>
<!--以下用于帖子分页显示 -->
<%
out.print("<tr>");
if (intPageCount*pageLine<totalRec)
intPageCount++;
if (intPage>intPageCount )
intPage=intPageCount;
if (intPage < 1 )
intPage=1;
out.print("<form method='POST' name=fPageNum action='qxdjj.jsp'>");
out.print("<p align='left'>>>分页 ");
if (intPage<2)
out.print("<font color='999966'>首页 上一页</font> ");
else{
out.print("<a href='qxdjj.jsp?page=1'>首页</a> ");
out.print("<a href='qzdjj.jsp?page=" + (intPage-1) + "'>上一页</a> " );
}
if( intPage-intPageCount>=0 )
out.print("<font color='999966'>下一页 尾页</font>" );
else{

out.print("<a href='qzdjj.jsp?page=" + (intPage+1)+ "'>下一页</a> <a href='qxdjj.jsp?page=" + intPageCount + "'>尾页</a>");
}
out.print(" 页次:<strong><font color=red>"+intPage+"</font>/"+intPageCount+"</strong>页 " );
out.print(" 共<b>"+totalRec+"</b>条记录 <b>"+pageLine+"</b>条/页 " );
out.print(" 转到第<input type='text' name='page' size=2 maxlength=10 class=smallInput value="+intPage+">");
out.print("页<input class=buttonface type='submit' value='GO' name='cndok'></span></p></form>" );

out.print("</td>");
out.print("</tr>");
%>
</table></p>
<a href="javascript:window.close();">[关闭]</a>
</center>
<%
stmt.close();
conn.close(); %>
</body>
</html>

-------------------------------------------------------------------------------
java.lang.NullPointerException
at com.microsoft.jdbc.base.BaseResultSet.cancelPendingUpdates(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.next(Unknown Source)
at _program._new._quexian._qxdjj__jsp._jspService(D:\resin-2.1.6\doc\program\new\quexian\qxdjj.jsp:84)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:497)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:312)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:244)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:536)

-----------------------------------------------------------------------------

其中84行是: while (rs3.next()) {
qzfty 2003-06-09
  • 打赏
  • 举报
回复
biggie(飞碟):你好!
我把问题从新说一下:

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>


<%@ include file="../session.jsp"%>
<html>
<head><title>缺陷登记
</title>
<link rel=stylesheet href="style.css" type="text/css">
<script language="JavaScript">
function newwin(url) {
var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450");
newwin.focus();
return false;
}
</script>
</head>
<body>
<script LANGUAGE="javascript">
function submit11()
{
self.location.replace("qxdji.jsp")
}
</script>
<jsp:useBean id="bbsBean" scope="page" class="firm.firm" />
<%

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=MyDatabase";
//pubs为你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

int pageLine=10;
int totalRec=0;
int totalSub=0;
int intPage=1;
if (request.getParameter("page")!=null)
intPage=Integer.parseInt(request.getParameter("page"));
try{

String sql="select count(*) as cnt from board";
ResultSet rs=stmt.executeQuery(sql);

//指定参考行数
//取得总数
if (rs.next())
totalRec=rs.getInt("cnt");


//取得主题数
String sql2="select count(*) as cnt from board";
ResultSet rs2=stmt.executeQuery(sql2);
if (rs2.next())
totalSub=rs2.getInt("cnt");


}
catch(Exception e){
e.printStackTrace();
}
//取得每行的主题数量
int jtemp=totalRec/pageLine+1;
int totalSubPerPage=totalSub/jtemp;
//取得总页数
int intPageCount=0;
intPageCount=(totalSub/totalSubPerPage * 10 + 5)/10 ;
%>


<center><font color="blue"><h4>设备缺陷登记管理</h4></font>
<%
out.print("<table border='1' cellspacing='0' width='632' bgcolor='#d7e3b9' bordercolorlight='#green' bordercolordark='#ECF5FF'>");
out.print("<tr align='center' bgcolor='#c8cc98'>");
out.print("<td width='240'>标题</td>");
out.print("<td width='60'>发表人</td>");
//out.print("<td width='100'>发表时间</td>");
out.print("<td width='40'>状态</td>");
out.print("<td width='40'>管理</td>");
out.print("</tr>");
%>
<%
String serial;
String title;
String recorder;
//Date providedate;

String sql3="select * from board where parent_no=0 order by serial_no DESC";
ResultSet rs3=stmt.executeQuery(sql3);

int i=0;
while (rs3.next()) {
i++;//-----------------显示本级的帖子内容
if (i>(totalSubPerPage *(intPage-1)) && (i<=(intPage * totalSubPerPage))){
out.print("<tr><td>");
serial=rs3.getString("serial_no");
title=rs3.getString("title");
recorder=rs3.getString("recorder");
//providedate=RS.getDate("time");
// showing(request,out,serial,title,recorder,providedate,"Subject");
showing(request,out,serial,title,recorder,"Subject");
//-----------------显示下一级的回复内容

String sql4="select * from board where parent_no=" + serial + " order by serial_no";
ResultSet rs4=stmt.executeQuery(sql4);


while (rs4.next()) {
out.print("<tr><td>");
serial=rs4.getString("serial_no");
title=rs4.getString("title");
recorder=rs4.getString("recorder");
// providedate=RS1.getDate("time");
//showing(request,out,serial,title,recorder,providedate,"Re");
showing(request,out,serial,title,recorder,"Re");
}
//------------------------
}
}

%>
<!--以下函数用于帖子内容显示 -->
<%!
void showing(HttpServletRequest request,JspWriter out,String serial,String title,String recorder, String ReSign)
throws IOException {
try{

if(ReSign=="Subject"){
out.print("<a href=bbsAnswer.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
}
else{
out.print("<a href=bbsReply.jsp?serial=" + serial + " onClick=' return newwin(this.href);'>" + title + "</a>");
}
out.print("</td><td align='center'>");
out.print(recorder);
out.print("</td></tr>");
}catch(Exception e)
{System.out.println(e);}

}
%>
<!--以下用于帖子分页显示 -->
<%
out.print("<tr>");
if (intPageCount*pageLine<totalRec)
intPageCount++;
if (intPage>intPageCount )
intPage=intPageCount;
if (intPage < 1 )
intPage=1;
out.print("<form method='POST' name=fPageNum action='qxdjj.jsp'>");
out.print("<p align='left'>>>分页 ");

if (intPage<2)
out.print("<font color='999966'>首页 上一页</font> ");
else{
out.print("<a href='qxdjj.jsp?page=1'>首页</a> ");
out.print("<a href='admin_user.jsp?page=" + (intPage-1) + "'>上一页</a> " );
}


if( intPage-intPageCount>=0 )
out.print("<font color='999966'>下一页 尾页</font>" );
else{

out.print("<a href='admin_user.jsp?page=" + (intPage+1)+ "'>下一页</a> <a href='qxdjj.jsp?page=" + intPageCount + "'>尾页</a>");
}

out.print(" 页次:<strong><font color=red>"+intPage+"</font>/"+intPageCount+"</strong>页 " );
out.print(" 共<b>"+totalRec+"</b>条记录 <b>"+pageLine+"</b>条/页 " );
out.print(" 转到第<input type='text' name='page' size=2 maxlength=10 class=smallInput value="+intPage+">");
out.print("页<input class=buttonface type='submit' value='GO' name='cndok'></span></p></form>" );

out.print("</td>");
out.print("</tr>");

%>
</table></p>
<a href="javascript:window.close();">[关闭]</a>
</center>
<%
rs.close();
rs2.close();
rs3.close();
rs4.close();
stmt.close();
conn.close(); %>
</body>
</html>

----------------------------------报错信息------------------------------------

Note: sun.tools.javac.Main has been deprecated.
D:\resin-2.1.6\doc\program\new\quexian\qzdjj.jsp:186: Undefined variable
or class name: rs
rs.close();
^
D:\resin-2.1.6\doc\program\new\quexian\qzdjj.jsp:187: Undefined variable
or class name: rs2
rs2.close();
^
D:\resin-2.1.6\doc\program\new\quexian\qzdjj.jsp:189: Undefined variable
or class name: rs4
rs4.close();
^
3 errors, 1 warning

----------------------------------------------------------------------------

请帮我分析一下。谢谢!
qzfty 2003-06-09
  • 打赏
  • 举报
回复
楼上的可不可以具体点。55行:intPageCount=(totalSub/totalSubPerPage * 10 + 5)/10 ;
heyday 2003-06-09
  • 打赏
  • 举报
回复
不能除零
qzfty 2003-06-09
  • 打赏
  • 举报
回复
biggie(飞碟) :
我太崇拜你了。你就是我的偶像。这个问题解决了。但是有新的报错信息:

---------------------------------------------------------------------
java.lang.ArithmeticException: / by zero
at _program._new._quexian._qxdji__jsp._jspService(D:\resin-2.1.6\doc\program\new\quexian\qxdji.jsp:55)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:497)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:312)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:244)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:536)
------------------------------------------------------------------------------

还请你再帮我分析。谢谢你!!!!
luckyfanjian 2003-06-09
  • 打赏
  • 举报
回复
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
biggie 2003-06-09
  • 打赏
  • 举报
回复
错误1: 将<%@ page import="java.sql.*"%> 改为<%@ page import="java.sql.*,java.io.*"%> 说明:你需要导入java.io.*这个包,因为IOException在io包内

错误2.3:把你方法的内容都放在
try{
放这里
}catch(Exception e)
{System.out.println(e);}

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧