jsp bean 无法运行的问题,请教高手。
这个是别人写的一个网页记数器的jsp和bean的应用。我拿来运行。
//counter.java 一个bean
import java.io.*;
public class counter extends Object {
private String currentRecord = null
private BufferedReader file;
private String path
public counter() {
}
public String ReadFile(String filePath) throws FileNotFoundException
{
path = filePath;
file = new BufferedReader(new FileReader(path));
String returnStr =null;
try
{
currentRecord = file.readLine();
}
catch (IOException e)
{
System.out.println("读取数据错误.");
}
if (currentRecord == null)
returnStr = "没有任何记录";
else
{
returnStr =currentRecord;
}
return returnStr;
}
public void WriteFile(String filePath,String counter) throws FileNotFoundException
{
path = filePath;
int Writestr = Integer.parseInt(counter)+1;
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(filePath));
pw.println(Writestr);
pw.close();
} catch(IOException e) {
System.out.println("写入文件错误"+e.getMessage());
}
}
}
/////// counter.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>
计数器演示程序
</TITLE>
</HEAD>
<BODY>
<!--创建并调用bean(counter)-->
<jsp:useBean id="counter" class="counter" scope="request">
</jsp:useBean>
<%
String cont=counter.ReadFile("/mywebcount.txt");
counter.WriteFile("/mywebcount.txt",cont);%>
您是第<font color="red"><%=cont%></font>位访问者
</BODY>
</HTML>
-------------
以上程序不复杂,我省略了注释,我现在出现的问题是。我将count.jsp 和mywebcount.txt 放到 .\mycon\jsp\ 下,编译后的webcounter放到 ..\mycon\WEB-INF\classes\下,然后运行tomcat4 ie中输入
http://localhost:8080/mycon/jsp/counter.jsp 显示错误。
description The server encountered an internal error () that prevented it from fulfilling this request.
org.apache.jasper.JasperException: /jsp/counter.jsp(7,26) equal symbol expected
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:428)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:126)
at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:169)
at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:136)
at org.apache.jasper.compiler.Parser.parsePageDirective(Parser.java:316)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:375)
.......
.........
请问是什么原因呢?我平时在
http://localhost:8080/mycon/servlet/xxxx 这样访问servlet一直都很正常。
平时的类都是放在..\mycon\WEB-INF\classes\ 下的。都没有什么问题。
我看过别的帖子,有的也有类似情况,有出主义在..\mycon\jsp\ 下建立一个 web=-inf\classes 的, 有的让 把bean 放到一个包里边的,比如 count.java 放到 mybean里边
jsp里边写成 <jsp:useBean id="counter" class="mybean.counter" scope="request">
.................等等,这些方法我都用过,没有效果。
请教高手,哪里错了,如何解决?