1、通过变量名(MyBean)引用到变量(MyVariable),即MyBean.MyVarible,从scriptlet直接访问变量;
例如:
JavaBean代码:
public class JavaBeanLearn{
String userName,....;
public void setUserName(String userName){
this.userName = userName;
}
public String getUserName(){
return userName;
}
........
}
jsp代码:
.......
<jsp:useBean id = "JavaBeanLearnTest" class="JavaBeanLearn" />
<%
JavaBeanLearnTest.userName="bluestar";
%>
userName:<%=JavaBeanLearnTest.userName%>
.......
2、通过适当的set和get方法访问,即直接调用JavaBean中的set和get方法.MyBean.setValue(....);MyBaen.getValue()
例如:
对以上JavaBean代码可以使用如下jsp文件设置或获取变量值
jsp代码:
.........
<jsp:useBean id = "JavaBeanLearnTest" class="JavaBeanLearn" />
<%
JavaBeanLearnTest.setUserName("bluestar");
%>
userName:<%=JavaBeanLearnTest.getUserName()%>
.........
3、通过setProperty和getProperty标签访问
例如:
对以上JavaBean代码可以使用如下jsp文件设置或获取变量值
jsp代码:
.........
<jsp:useBean id = "JavaBeanLearnTest" class="JavaBeanLearn" />
<jsp:setProperty name="JavaBeanLearnTest" property="userName" value="bluestar"/>
userName:<jsp:getProperty name="JavaBeanLearnTest" property="userName"/>
.........