Topic: 这段程序哪里错了?('try' without 'catch' or 'finally')

  Print this page

1.这段程序哪里错了?('try' without 'catch' or 'finally') Copy to clipboard
Posted by: yangxg_a
Posted on: 2005-11-27 13:59

下面这段程序哪里错了啊?

<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.io.*" %>
<HTML>
<BODY BGCOLOR=cyan><FONT Size=4>
<%!
int number=0;
File file=new File("count.txt");
synchronized void countPeople()//计算访问次数的同步方法
{
if(!file.exists())
{
number++;
try{
file.createNewFile();
FileOutputStream Out=new FileOutputStream("count.txt");
DataOutputStream dataOut=new DataOutputStream(out);
dataOut.writeInt(number);
out.close();
dataOut.close();
}
catch(IOException ee){}
}
else
{
try{
FileInputStream in=new FileInputstream("count.txt");
DataInputStream dataIn=new DataInputStream(in);
number=dataIn.readInt();
number++;
in.close();
dataIn.close();
FileOutputStream out=new FileOutputStream("count.txt");
DataOutputStream dataOut=new DataOutputStream(out);
dataOut.writeInt(number);
out.close();
dataOut.close();
}
}
catch(IOException ee){}
}
}
%>
<%
countPeople();
%>
<P><P>您是第
  <%=number%>
个访问本站的客户。
</FONT>
</BODY>
</HTML>

错误提示是:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 5 in the jsp file: /Example2_3.jsp
Generated servlet error:
E:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\Example2_005f3_jsp.java:31: 'try' without 'catch' or 'finally'
try{
^

An error occurred at line: 5 in the jsp file: /Example2_3.jsp
Generated servlet error:
E:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\Example2_005f3_jsp.java:45: 'catch' without 'try'
catch(IOException ee){}
^

Generated servlet error:
E:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\Example2_005f3_jsp.java:49: 'class' or 'interface' expected
private static java.util.Vector _jspx_dependants;
^

Generated servlet error:
E:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\Example2_005f3_jsp.java:51: 'class' or 'interface' expected
public java.util.List getDependants() {
^

Generated servlet error:
E:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\Example2_005f3_jsp.java:111: 'class' or 'interface' expected
}
^

Generated servlet error:
E:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\Example2_005f3_jsp.java:112: 'class' or 'interface' expected
^

Generated servlet error:
E:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\Example2_005f3_jsp.java:8: org.apache.jsp.Example2_005f3_jsp should be declared abstract; it does not define getDependants() in org.apache.jsp.Example2_005f3_jsp
public final class Example2_005f3_jsp extends org.apache.jasper.runtime.HttpJspBase
^

An error occurred at line: 5 in the jsp file: /Example2_3.jsp
Generated servlet error:
E:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\Example2_005f3_jsp.java:22: cannot resolve symbol
symbol : variable out
location: class org.apache.jsp.Example2_005f3_jsp
DataOutputStream dataOut=new DataOutputStream(out);
^

An error occurred at line: 5 in the jsp file: /Example2_3.jsp
Generated servlet error:
E:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\Example2_005f3_jsp.java:24: cannot resolve symbol
symbol : variable out
location: class org.apache.jsp.Example2_005f3_jsp
out.close();
^

An error occurred at line: 5 in the jsp file: /Example2_3.jsp
Generated servlet error:
E:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\Example2_005f3_jsp.java:32: cannot resolve symbol
symbol : class FileInputstream
location: class org.apache.jsp.Example2_005f3_jsp
FileInputStream in=new FileInputstream("count.txt");
^
10 errors

  org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
  org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
  org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
  org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
  org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.

2.Re:这段程序哪里错了? [Re: yangxg_a] Copy to clipboard
Posted by: yangxg_a
Posted on: 2005-11-27 16:04

没人回答吗?自己顶。

3.Re:这段程序哪里错了? [Re: yangxg_a] Copy to clipboard
Posted by: yangxg_a
Posted on: 2005-11-27 18:55

这个论坛怎么好像一点人气都没有啊?~~~~~~

4.Re:这段程序哪里错了? [Re: yangxg_a] Copy to clipboard
Posted by: why
Posted on: 2005-11-27 23:56


else
{
try{
FileInputStream in=new FileInputstream("count.txt");
DataInputStream dataIn=new DataInputStream(in);
number=dataIn.readInt();
number++;
in.close();
dataIn.close();
FileOutputStream out=new FileOutputStream("count.txt");
DataOutputStream dataOut=new DataOutputStream(out);
dataOut.writeInt(number);
out.close();
dataOut.close();
}
// } -- bogus }, please check carefully!
catch(IOException ee){}
}
}


Please use [ code ] tag in the future.

5.Re:这段程序哪里错了? [Re: yangxg_a] Copy to clipboard
Posted by: why
Posted on: 2005-11-28 00:04

yangxg_a wrote:
没人回答吗?自己顶。

不到兩個小時便頂
這種行為要不得

如有再犯
立即砍帖

6.Re:这段程序哪里错了? [Re: why] Copy to clipboard
Posted by: yangxg_a
Posted on: 2005-11-28 09:53

why wrote:
不到兩個小時便頂
這種行為要不得

如有再犯
立即砍帖


呵呵,不好意思。我是急于解决这个问题,在线等的,见半天没人回复就急了。
看来是我太粗心了,小弟才开始自学JSP,以后还要多多讨教。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923