counter.javapublic class counter {
int count = 0; 
public counter() {}
public int getcount() {
count++;
return this.count;}
public void setcount(int count) {
this.count = count;}} counter.jsp:<html><body>
<jsp:usebean id="bean0" scope="application" class="counter"/>
the counter is :
<jsp:getproperty name="bean0" property="count" /><br>
</body></html> counter.class 放在root\web-inf\classes\counter.class
counter.jsp 放在webapps\Myapp\counter.jsp
为啥不对呢?counter.jsp 页面错误?

解决方案 »

  1.   


    public class counter { 
      int count = 0; 
      public counter() {} 
      public int getCount(){ 
         count++; 
         return this.count;
      } 
      public void setCount(int count) { 
         this.count = count;
      }

      

  2.   

    getproperty 
    改为
    getProperty 
      

  3.   

    usebean 
    改为
    useBean 
      

  4.   

    jsp第一行加上
    <%@ page contentType="text/html; charset=UTF-8"%>
      

  5.   

    新建一个包 例如 aa
    将   counter.java 放在aa这个包下。
    counter.java 代码如下:package aa;public class counter { 
    int count = 0; 
    public counter() {} 
    public int getcount() { 
    count++; 
    return this.count;} 
    public void setcount(int count) { 
    this.count = count;}} 
    counter.jsp:代码如下:
    <html>
      <body>
      <jsp:useBean id="bean0" scope="application" class="aa.counter"/>the counter is : 
    <jsp:getProperty name="bean0" property="count" /> <br>
      </body>
    </html>
    counter.class 放在root\web-inf\classes\aa\counter.class 
    counter.jsp 放在webapps\Myapp\counter.jsp 这样就可以了。已经调试过了。
    没刷新一次就会加一。
      

  6.   

    还是报错:
    org.apache.jasper.JasperException: /counter.jsp(3,1) The value for the useBean class attribute aa.counter is invalid.
      

  7.   

    javaBean中的属性应该是私有变量吧?
      

  8.   

    include 中没包含javaBean吧?
      

  9.   

    The value for the useBean class attribute aa.counter is invalid. 
    你的counter里面压根儿没有counter 这个属性,当然保存啦,在counter 中定义counter 这个属性
      

  10.   

    a11123401:您的可以吗?我的咋不行:
    The value for the useBean class attribute aa.counter is invalid
      

  11.   


    package aa; public class counter { 
    int count = 0; 
    public counter() {} 
    public int getcount() { 
    count++; 
    return this.count;} 
    public void setcount(int count) { 
    this.count = count;}} 
    <html> 
      <body> 
      <jsp:useBean id="bean0" scope="application" class="aa.counter"/>
      the counter is : 
    <jsp:getProperty name="bean0" property="count" /> <br> 
      </body> 
    </html> 
      

  12.   

    我的JDK 版本是1.6.0 使用的是MyEclipse6.6  tomcat6.0 你的大小写应该出现问题了。你的6楼的错误:
    org.apache.jasper.JasperException: /counter.jsp(3,1) The value for the useBean class attribute aa.counter is invalid.是counter.jsp 中在第三行的代码中 的属性出现错误。
    就是
    <jsp:usebean id="bean0" scope="application" class="counter"/> 
    改为
    <jsp:useBean id="bean0" scope="application" class="aa.counter"/>
      

  13.   

    太痛苦了,总是
    The value for the useBean class attribute aa.counter is invalid. 
    ???????????????????????????????
    ????????????????????????????????
      

  14.   

    另外,是否要在环境变量中设置classpath,怎样设置?
    谢谢!
      

  15.   

    The value for the useBean class attribute aa.counter is invalid.说明JDK在编译的时候找不到 aa.counter 既然代码没有问题。就是你的counter.class的位置存放在错误的地方了。把counter.class 放在root\web-inf\classes\counter.class 
    counter.jsp 放在webapps\Myapp\counter.jsp 修改为
    counter.class 放在webapps\Myapp\web-inf\classes\aa\counter.class 
    counter.jsp 放在webapps\Myapp\counter.jsp 这样你的错误就可以消失了。至于环境变量在百度上随便一搜就可以搜到了。
    配完环境变量以后再
    cmd里面输入 javac
    没有错误就证明你的环境变量配置成功了。
      

  16.   

      注意红字部分
        楼主在生成get()和set()方法是用快捷键自动生成不要手写
      

  17.   

    不知道有没有搞清楚什么是JavaBean
      

  18.   

    会不会是tomcat 6.0的配置问题?楼上的快乐的生活,希望您指点迷津,先帮我解开眼前的瓶颈,不胜感激!
      

  19.   

    在jsp里你就没引入aa.counter这个类,你import一下。如果你不引的话编译器把aa.counter认为是一个type
      

  20.   


    就是,在前面引用一下aa这个包,然后再写class="counter"
      

  21.   

    counter.java public class counter { 
    private int count = 0; 
    public counter() {} 
    public int getcount() { 
    count++; 
    return this.count;} 
    public void setcount(int count) { 
    this.count = count;}} counter.jsp: <html> <body> 
    <jsp:useBean id="bean0" scope="application" class="counter"/> 
    the counter is : 
    <jsp:getProperty name="bean0" property="count" /> <br> 
    </body> </html> 
      

  22.   

    public int getCount() { 
    count++; 
    return this.count;} 
    public void setCount(int count) { 
    this.count = count;}}
      

  23.   

    谢谢大家!
    我感觉还是路径有问题,我贴出来大家看看,一定要帮我:
            D:
            |
         Program Flies
           |
        Apache Software Foundation
           |
        Tomcat 6.0
           |
         webapps
           |
      ROOT    myapps  ------在webapps目录下新建myapps,放置作业文件counter.jsp
        |        |
     WEB-INF   counter.jsp
        |
      classes  -----WEB-INF目录下原来没有classes目录,新建classes目录,放置
        |           aa.counter.class文件,同时在操作系统环境变量中新增系统变量
        aa          classpath=D:\Program Files\Apache Software Foundation\Tomcat 6.0
        |           \webapps\ROOT\WEB-INF\classes
       counter.class