<jsp:useBean id="helloworld" scope="page" class="helloworld.class">
jsp页面加这个了吗?

解决方案 »

  1.   

    加了的 这是的源代码:
    <!--hellobean.jsp-->
    <%@page contentType="text/html;charset=gb2312"%>
    <%@page import="javabean.helloworld"%>
    <html>
    <head>
    <title>javabean</title>
    </head>
    <body>
    <center>
    <h2><jsp:useBean id="hello" class="helloworld.class" scope="page"/>
    <jsp:setProperty name="hello" property="jsp"/>
    <jsp:getProperty name="hello" property="welcome"/>
    <br>
    <% 
    hello.setWelcome("你好");
    out.print(hello.getWelcome());
    %>
    <br>
    </h2>
    </center>
    </body>
    </html>
    package javabean;
    public class helloworld{
    String name;
    String welcome;
    public helloworld(){
    name=null;
    welcome="hello world!!";
    }

    public void setName(String value){
    name=value;
    }

    public String getName(){
    return name;
    }

    public void setWelcome(String value){
    welcome=value;
    }

    public String getWelcome(){
    return welcome+name;
    }
    }
      

  2.   

    <jsp:useBean id="hello" class="helloworld.class" scope="page"/>
    这句话不对,useBean标签不是这样用的,应该是class="包名.类名",即class="javabean.helloworld"。另,@page中的import似乎可以不加。