javaBean的内容:
package untitled1;
public class Jsp2Bean {
private String sample;
public String getSample() {
return sample;
}
public void setSample() {
sample = "hello";
}
}
jsp页面内容:
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
jsp2
</title>
</head>
<jsp:useBean id="jsp2BeanId" scope="session" class="untitled1.Jsp2Bean" />
<jsp:setProperty name="jsp2BeanId" property="sample"/>
<jsp:getProperty name="jsp2BeanId" property="sample"/>
<body bgcolor="#ffffff">
</body>
</html>
问题:javaBean里set方法如果是无参数直接在方法内部附值用jsp标准动作来调用总是报异常,但是jsp页面代码改为:
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
jsp2
</title>
</head>
<jsp:useBean id="jsp2BeanId" scope="session" class="untitled1.Jsp2Bean" />
<%
jsp2BeanId.setSample();
%>
<jsp:getProperty name="jsp2BeanId" property="sample"/>
<body bgcolor="#ffffff">
</body>
</html>
就能正确显示hello 也就是说问题出在红色代码的部分,用Scriptlet来调用无参的set方法就可以正确,为什么这种情况下不能用jsp动作来调用呢?麻烦高手解答一下
[此贴子已经被作者于2007-6-10 2:55:46编辑过]