举个详细的例子吧。我的BEANS(StudentInf)是: package student;
public class StudentInf{
public String Id;
public String Name;
//构造函数
public StudentInf(){
this.Id="98612309";
this.Name="unsane";
}
public void setId(String w_Id){
this.Id=w_Id;
}
public String getId(){
return (this.Id);
}
public void setName(String name){
this.Name=name;
}
public String getName(){
return(this.Name);
}
} 而我的JSP文件(student.jsp)代码是:
<html>
<head>
<title>TEST BEAN</title>
</head>
<%@page contentType="html/text;charset=gb2312" %>
<body>
<jsp:useBean id="StuBean" scope="application" class="student.StudentInf"/>
<jsp:setProperty name="StuBean" property="*" />
<% StuBean.setId("98612308");
StuBean.setName("liyunpeng");
%>
使用方法1:<p>
学号:<%=StuBean.getId()%><br>
姓名:<%=StuBean.getName()%><p>
<% StuBean.setId("98612307");
StuBean.setName("lilin");
%>
<b>使用方法2:</b><p>
学号:<jsp:getProperty name="StuBean" property="Id" />
<br>
姓名:<jsp:getProperty name="StuBean" property="Name" />
</body>
</html>
访问JSP,出现的错误:
org.apache.jasper.JasperException: Cannot find any inFORMation on property 'Id' in a bean of type 'student.StudentInf'
这是怎么回事啊?我把“方法2”删除了,方法1能正常工作,方法2的getProperty哪儿有问题啊?请教!
public class StudentInf{
public String Id;
public String Name;
//构造函数
public StudentInf(){
this.Id="98612309";
this.Name="unsane";
}
public void setId(String w_Id){
this.Id=w_Id;
}
public String getId(){
return (this.Id);
}
public void setName(String name){
this.Name=name;
}
public String getName(){
return(this.Name);
}
} 而我的JSP文件(student.jsp)代码是:
<html>
<head>
<title>TEST BEAN</title>
</head>
<%@page contentType="html/text;charset=gb2312" %>
<body>
<jsp:useBean id="StuBean" scope="application" class="student.StudentInf"/>
<jsp:setProperty name="StuBean" property="*" />
<% StuBean.setId("98612308");
StuBean.setName("liyunpeng");
%>
使用方法1:<p>
学号:<%=StuBean.getId()%><br>
姓名:<%=StuBean.getName()%><p>
<% StuBean.setId("98612307");
StuBean.setName("lilin");
%>
<b>使用方法2:</b><p>
学号:<jsp:getProperty name="StuBean" property="Id" />
<br>
姓名:<jsp:getProperty name="StuBean" property="Name" />
</body>
</html>
访问JSP,出现的错误:
org.apache.jasper.JasperException: Cannot find any inFORMation on property 'Id' in a bean of type 'student.StudentInf'
这是怎么回事啊?我把“方法2”删除了,方法1能正常工作,方法2的getProperty哪儿有问题啊?请教!
<jsp:getProperty name="StuBean" property="Id" />
-->
<jsp:getProperty name="stubean" property="id" />
取的时候用小修来取
取的时候用小修来取
hello.java
****************
package newfolder;public class hello {
String Hh;
public hello() {
Hh="";
}
public void setHh(String hh) {
this.Hh=hh;
}
public String getHh() {
return(this.Hh);
}
}
**************
jsp中使用
*************
<jsp:useBean id="hello" scope="page" class="newfoler.hello"/>
输入参数:<jsp:setProperty name="hello" property="hh" value="beyond_xiruo" />
输出参数:<jsp:getProperty name="hello" property="hh" />
我改了以后,再运行JSP,
结果怎么弹出了一个文件下载窗口啊?纳闷。。
http://localhost:8080/test/student/student.jsp
结果就弹出来一个文件下栽窗口,点确定,就把BEANS运行的结果按HTML的方式保存在一个写字板里了,这是怎么回事啊?大家帮忙啊/