在jsp中可以通过
<jsp :setProperty name="**" property="**" value="**"/>
来给javabean变量 赋值
通过
<jsp :getProperty name="**" property="**" />
来获得javabean变量的某一个属性的值
其实它是通过这两个jsp动作 是分别调用 javabean类中的setter和getter函数来实现的
并且 property有严格要求
应该调用getter或者setter函数 出去前面的getter或者setter函数 之后 并将首个字母改成小写
举个例子
package test;
public class TestBean {
private String stringValue = null;
public TestBean(){
}
public void setStringValue(String str){
this.stringValue = str;
}
public String getStringValue(){
return stringValue;
}
}
这个TestBean类 其中有属性stringValue
最好根据默认的setter或者getter函数 命名为setStringValue 和 setStringValue
然后看jsp文件
<%--
Created by IntelliJ IDEA.
User: FX50J
Date: 2018/1/18
Time: 16:17
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
</head>
<body>
<jsp:useBean id="test" scope="page" class="test.TestBean"/>
<jsp:setProperty name="test" property="stringValue" value="上海大学"/>
<h1>Get of String:<jsp:getProperty name="test" property="stringValue"/></h1>
</body>
</html>
这样做就是正确的 否则就会出现 这样的错误