一共两个文件,sample1.html和sample1Bean.java,文件目录都是设置正确的,运行可以出来结果,
运行结果如下
A JSP&Bean Sample Enter new value:Submit按钮1 Reset按钮2
Value of Bean property is : 但是按按钮1,即Submit的时候,不知道为什么,不能获取到javaBean的property,所以不能显示出来property的值。
sample1.html代码如下:<%@ page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>
web7
</title>
</head>
<jsp:useBean id="sample1BeanId" scope="session" class="Bean.sample1Bean"/>
<jsp:setProperty name="sample1BeanId" property="sample"/>
<body>
<h1>
A JSP&Bean Sample
</h1>
<form method="post">
<br> Enter new value:<input name="sample"><br>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br>
Value of Bean property is :
<jsp:getProperty name ="sample1BeanId" property="sample"/>
</form>
</body>
</html>sample1Bean.java代码如下:
package Bean;
public class sample1Bean
{
private String sample ="start value";
public String getSample()
{
return sample;
}
public void setSample(String newValue)
{
if(newValue!=null){
sample=newValue;}
}
}
以前问过这个问题,有人说把setSample里面的sample改成this.sample,改了也没用。怎么运行,才能让按按钮submit时,正确的显示property?
望指点,谢谢。
运行结果如下
A JSP&Bean Sample Enter new value:Submit按钮1 Reset按钮2
Value of Bean property is : 但是按按钮1,即Submit的时候,不知道为什么,不能获取到javaBean的property,所以不能显示出来property的值。
sample1.html代码如下:<%@ page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>
web7
</title>
</head>
<jsp:useBean id="sample1BeanId" scope="session" class="Bean.sample1Bean"/>
<jsp:setProperty name="sample1BeanId" property="sample"/>
<body>
<h1>
A JSP&Bean Sample
</h1>
<form method="post">
<br> Enter new value:<input name="sample"><br>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br>
Value of Bean property is :
<jsp:getProperty name ="sample1BeanId" property="sample"/>
</form>
</body>
</html>sample1Bean.java代码如下:
package Bean;
public class sample1Bean
{
private String sample ="start value";
public String getSample()
{
return sample;
}
public void setSample(String newValue)
{
if(newValue!=null){
sample=newValue;}
}
}
以前问过这个问题,有人说把setSample里面的sample改成this.sample,改了也没用。怎么运行,才能让按按钮submit时,正确的显示property?
望指点,谢谢。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货