帮我看一段代码,在JAVABEAN中读文件,结果总出错

win1357 2003-03-28 04:30:08
package readtext;

import java.awt.*;
import javax.swing.JPanel;
import java.io.*;

public class readfile extends JPanel {
private BorderLayout borderLayout1 = new BorderLayout();
String str = "";
String content = "";
private void setStr(){
str = content;
}
private String getStr(){
return str;
}
public readfile() {
try {
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
}

private void jbInit() throws Exception {
this.setLayout(borderLayout1);
File readFile = null;
try
{
readFile = new File("D:\\SoftWare\\init.ini");
FileInputStream is = new FileInputStream(readFile);

int size = is.available();
byte[] bytes = new byte[size];
is.read(bytes);
is.close();
content = new String(bytes);
}
catch(Exception e)
{
e.printStackTrace();

}
}
}
JSP中是这样的:
...................
<jsp:useBean id="readfile" scope="session" class="readtext.readfile" />
<jsp:setProperty name="readfile" property="str" />

<jsp:getProperty name="readfile" property="str" />

编译的结果是这样的:
"JspRead.jsp": org.apache.jasper.JasperException: Cannot find any information on property 'str' in a bean of type 'readtext.readfile'

...全文
7 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
max146 2003-03-28

private void setStr(String s){
str = s;
}
<jsp:setProperty name="readfile" property="str" value=""/>
<jsp:getProperty name="readfile" property="str"/>
回复
win1357 2003-03-28
Can't find a method to write property 'str' in a bean of type 'readtext.readfile'
是什么意思?setStr()方法没错啊
回复
win1357 2003-03-28
照bsd(小红帽菜鸟)的方法可以通过编译,运行是却有异常:
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Can't find a method to write property 'str' in a bean of type 'readtext.readfile'
at org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:282)
at org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:220)
at org.apache.jsp.JspRead$jsp._jspService(JspRead$jsp.java:87)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:484)
回复
moumouren 2003-03-28
放弃bean
使用 <% page import=""%>
回复
freelarry 2003-03-28
private String str = "";
回复
bsd 2003-03-28
public void setStr(){
str = content;
}
public String getStr(){
return str;
}
回复
win1357 2003-03-28
问题应该不难,我一时也找不到原因,在线等
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-03-28 04:30
社区公告
暂无公告