JSP+JavaBean的高手进。我是一个新手。

来源:百度知道 编辑:UC知道 时间:2024/09/21 23:32:54
Java代码:
package testa;
public class b
{
String hello = "";
public b(){}
public void setHello(String str)
{
hello = str;
}
public String getHello()
{
return hello;
}
}
JSP代码:
<%@ page contentType="text/html; charset=gb2312" language="java"%>
<%@ page import="testa.b"%>

<html>
<body>
<jsp:useBean id="bc" class="testa.b" scope="page">
</jsp:useBean>
<%
bc.setHello("Hello");
%>
<%=bc.getHello()%>
</body>
</html>

运行结果:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /javaBean2.jsp(6,0) The value for


<jsp:useBean id="bc" class="testa.b" scope="page">
</jsp:useBean>
之间加上这样一段代码再试试。
<jsp:setProperty property="*" name="bc" />

原因:你想在页面是设定Bean的属性,可是没有得到对其属性设定的权限。

只知道Servlet里面可以用 .setXX()方法

JavaBean标签一般是这么写
传值给bean:<jsp:setProperty name="bc" property="hello" value="hello"/>
从bean中取值::<jsp:getProperty name="bc" property="hello"/>