这是什么错误?

whoopee 2004-08-25 07:22:54
我要实现一个文本计数器的查看,java文件Vote.java如下:
package test;

import java.io.*;

public class Vote
{
Vote(){}
public int n;
public String filePath = "";
private File voteFile;
private BufferedReader reader;
private PrintWriter pw;
public String systemMessage = "";
private String voteStr[] = new String[2];
public int voteNum[] = new int[2];
public void createFile() throws FileNotFoundException{
voteFile = new File(filePath);
if(!voteFile.exists()){
pw = new PrintWriter(new FileOutputStream(filePath));
for(int i=0;i<n;i++)
pw.println("0");
pw.close();
}
}
public void writeFile() throws FileNotFoundException{
pw = new PrintWriter(new FileOutputStream(filePath));
for(int i=0;i<n;i++)
pw.println(voteNum[i]);
pw.close();
}
public void readFile() throws FileNotFoundException{
reader = new BufferedReader(new FileReader(filePath));
for(int i=0;i<n;i++){
try{
voteStr[i] = reader.readLine();
}
catch(IOException e){
System.err.println(e);
voteStr[i] = "0";
}
voteNum[i] = Integer.parseInt(voteStr[i]);
try{
reader.close();
}
catch(IOException e){
systemMessage = e.toString();
}
}
}
}


/*

错误类型:
javax.servlet.ServletException: class test.Vote : java.lang.IllegalAccessException: Class java.beans.Beans can not access a member of class test.Vote with modifiers ""

*/
查看留言的jsp文件如下:display.jsp
<jsp:useBean id="voter" class="vote.vote" scope="request"/>
<%voter.readValue();%>
<p>支持人数:<%
=voter.agree;
%></p>
<p>反对人数:</p>
<%
=voter.object;
%>
报错如下:
exception

javax.servlet.ServletException: class test.Vote : java.lang.IllegalAccessException: Class java.beans.Beans can not access a member of class test.Vote with modifiers ""
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:673)
org.apache.jsp.Test.display_jsp._jspService(display_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.InstantiationException: class test.Vote : java.lang.IllegalAccessException: Class java.beans.Beans can not access a member of class test.Vote with modifiers ""
org.apache.jsp.Test.display_jsp._jspService(display_jsp.java:53)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

这是怎么回事哪?
...全文
54 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
shangqiao 2004-08-26
将构造子设为public试试
回复
cccer 2004-08-26
up
回复
whoopee 2004-08-25
怎么回事?总是贴这个代码?????

这次没错了!!!!

<jsp:useBean id="display" class="test.Vote" scope="request"/>
<%
display.n = 2;
display.filePath = "../webapps/ROOT/test/test.txt";
display.createFile();
display.readFile();
%>
<html>

agree <%=display.voteNum[0]%>
object <%=display.voteNum[1]%>
</html>
回复
whoopee 2004-08-25
哦,不好意思,贴错代码了!!!!!!!!!!!!!!

查看留言的jsp文件应为:
display.jsp
<jsp:useBean id="voter" class="vote.vote" scope="request"/>
<%voter.readValue();%>
<p>支持人数:<%
=voter.agree;
%></p>
<p>反对人数:</p>
<%
=voter.object;
%>
回复
jackkui 2004-08-25
还有你的Vote构造方法,应该是public
回复
yxh1981718 2004-08-25
把vote.vote改为test.vote就可以了
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-08-25 07:22
社区公告
暂无公告