当前位置: 技术问答>java相关
为什么我使用java bean的页面不能正常显示?大家帮忙呀!
来源: 互联网 发布时间:2015-09-20
本文导语: 我的java bean如下: package mybeans; import java.io.*; public class Counter implements Serializable { private int count; public Counter() { count=0; } public void setCount(int count) { this.count=count; } public void getCount(int count) { this.count...
我的java bean如下:
package mybeans;
import java.io.*;
public class Counter implements Serializable
{
private int count;
public Counter()
{
count=0;
}
public void setCount(int count)
{
this.count=count;
}
public void getCount(int count)
{
this.count=++count;
}
}
*******************************************************
我的jsp原文件ScopeOfBean.jsp
Scope Of Bean
*************************************************************
出错信息:
Error: 500
Location: /mysite/ScopeOfBean.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Cannot find a method to read property 'count' in a bean of type 'mybeans.Counter'
at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:620)
at org.apache.jasper.compiler.GetPropertyGenerator.generate(GetPropertyGenerator.java:101)
at org.apache.jasper.compiler.JspParseEventListener$GeneratorWrapper.generate(JspParseEventListener.java:771)
at org.apache.jasper.compiler.JspParseEventListener.generateAll(JspParseEventListener.java:220)
at org.apache.jasper.compiler.JspParseEventListener.endPageProcessing(JspParseEventListener.java:175)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:210)
at org.apache.jasper.servlet.JspServlet.doLoadJSP(JspServlet.java:612)
at org.apache.jasper.servlet.JasperLoader12.loadJSP(JasperLoader12.java:146)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:542)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:258)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:268)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:806)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:752)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:479)
package mybeans;
import java.io.*;
public class Counter implements Serializable
{
private int count;
public Counter()
{
count=0;
}
public void setCount(int count)
{
this.count=count;
}
public void getCount(int count)
{
this.count=++count;
}
}
*******************************************************
我的jsp原文件ScopeOfBean.jsp
Scope Of Bean
Session Count的值是:
Application Count的值是:
*************************************************************
出错信息:
Error: 500
Location: /mysite/ScopeOfBean.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Cannot find a method to read property 'count' in a bean of type 'mybeans.Counter'
at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:620)
at org.apache.jasper.compiler.GetPropertyGenerator.generate(GetPropertyGenerator.java:101)
at org.apache.jasper.compiler.JspParseEventListener$GeneratorWrapper.generate(JspParseEventListener.java:771)
at org.apache.jasper.compiler.JspParseEventListener.generateAll(JspParseEventListener.java:220)
at org.apache.jasper.compiler.JspParseEventListener.endPageProcessing(JspParseEventListener.java:175)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:210)
at org.apache.jasper.servlet.JspServlet.doLoadJSP(JspServlet.java:612)
at org.apache.jasper.servlet.JasperLoader12.loadJSP(JasperLoader12.java:146)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:542)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:258)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:268)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:806)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:752)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:479)
|
方法getCount()改为:
public int getCount() {
return (++count);
}
但是每次提交后得到的结果是一样的,因为你用的事class="mybeans.Count".
用class的结果是,每次动态生成一个formbean的对象,没有达到计数的功能。
public int getCount() {
return (++count);
}
但是每次提交后得到的结果是一样的,因为你用的事class="mybeans.Count".
用class的结果是,每次动态生成一个formbean的对象,没有达到计数的功能。
|
public void getCount(int count)
{
this.count=++count;
}
有问题,应该返回int吧:
public int getCount()
{
return this.count;
}
{
this.count=++count;
}
有问题,应该返回int吧:
public int getCount()
{
return this.count;
}
|
怎么可以把count这个属性变量用private来定义呢?
再说getCount()方法也应该有返回值呀
再说getCount()方法也应该有返回值呀
|
你好像没有给getCount传参数阿!
jsp中加两句:
方法getCount()改为:
public int getCount()
{
this.count=++this.count;
return this.count;
}
感觉应该这样,没有试过,不一定对,仅作参考!
jsp中加两句:
方法getCount()改为:
public int getCount()
{
this.count=++this.count;
return this.count;
}
感觉应该这样,没有试过,不一定对,仅作参考!
|
用这种方法来记录访问量好像不对哟
每次用的时候都要使 count=0
每次用的时候都要使 count=0
|
gz