<jsp:useBean id="card" scope="session" class="untitled1.card"/>

解决方案 »

  1.   

    我看我还是和你解释一下吧!那个ID是你在JSP文件里的表识,SCOPE是代表这个BEAN的生存周期,那个CLASS是代表你的BEAN文件的位置。
    呵呵!
    要简单BEAN程序你就写个HELLOO WORD吧!如果你看了JAVA基础,你就会写。
      

  2.   

    如果你的BEAN类里有PRINT函数那么你在JSP中就应该用card.print();来调用这里假如ID为card
      

  3.   

    请问jsp文件和class文件是放在一个文件夹里吗?为什么我的 jsp不能调用javabean?是不是配置的问题
      

  4.   

    Try it:
    sample.jsp
    <%@page contentType="text/html;charset=GBK"%>
    <html>
    <head>
    <title>
    sample1
    </title>
    </head>
    <jsp:useBean id="Sample1BeanId" scope="session" class="javabean.sample1Bean"/>
    <jsp:setProperty name="Sample1BeanId" property="*" />
    <body>
    <h1>
    A JSP & Bean Sample
    </h1>
    <form method="post"><br>
    Enter new value  : <input name="sample"><br>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" value="Reset"><br>
    Value of Bean property is : <jsp:getProperty name="Sample1BeanId" property="sample"/>
    </form></body>
    </html>sample1Bean.java
    package javabean;public class sample1Bean {
            private String sample = "Start value";
            public String getSample(){
                          return this.sample;
            }
            public void setSample(String newValue){
                    if(newValue != null){
                            this.sample = newValue;
                    }
            }
    }Hint:
    remember 
    1.compile and put:
    bean=>sample1Bean.java
    with in=>TOMCAT_INSTALL_HOME\webapps\newproject\WEB-INF\classes\javabean\sample1Bean.class
    2.put:
    jsp=>sample.jsp
    with in:TOMCAT_INSTALL_HOME\webapps\newproject\WEB-INF\sample.jsp
    Good Luck!!!
      

  5.   

    Remember:
    RUN: http://localhost:8080/newproject/sample.jsp