下面的程序错在那里了呀 那位高手给分析解决一下呀
程序是
index.jsp 的代码是
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<jsp:useBean id="pb" class="pa.Pwbean" scope="page"></jsp:useBean>
<%
pb.setPwNum(6);
%>
<%--jsp:setProperty property="pwdNum" name="pb" value="6"/ --%>
<%
pb.createPassword();
%>
<h3>自动生成的随机密码位数为:</h3>
<jsp:getProperty property="pwdNum" name="pb"/>
<h3>自动生成的密码为:</h3>
<jsp:getProperty property="password" name="pb"/>
</body>
</html>javabean中的程序是
package pa;public class Pwbean
{
private int pwdNum;
private long password;
public Pwbean()
{
}
public void setPwNum(int n)
{
if(n<6)
{
pwdNum = n;
}
else
{
pwdNum = 6;
}
}
public int getPwdNum()
{
return pwdNum;
}
public void createPassword()
{
double d = Math.random();
int n = 1;
for(int i=0;i<pwdNum;i++)
{
n = n*10;
}
password = (long)(d*n);
}
public long getPassword()
{
return this.password;
}
}然后就报了 Can't find a method to write property 'pwdNum' of type 'int' in a bean of type 'pa.Pwbean'的错了
程序是
index.jsp 的代码是
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<jsp:useBean id="pb" class="pa.Pwbean" scope="page"></jsp:useBean>
<%
pb.setPwNum(6);
%>
<%--jsp:setProperty property="pwdNum" name="pb" value="6"/ --%>
<%
pb.createPassword();
%>
<h3>自动生成的随机密码位数为:</h3>
<jsp:getProperty property="pwdNum" name="pb"/>
<h3>自动生成的密码为:</h3>
<jsp:getProperty property="password" name="pb"/>
</body>
</html>javabean中的程序是
package pa;public class Pwbean
{
private int pwdNum;
private long password;
public Pwbean()
{
}
public void setPwNum(int n)
{
if(n<6)
{
pwdNum = n;
}
else
{
pwdNum = 6;
}
}
public int getPwdNum()
{
return pwdNum;
}
public void createPassword()
{
double d = Math.random();
int n = 1;
for(int i=0;i<pwdNum;i++)
{
n = n*10;
}
password = (long)(d*n);
}
public long getPassword()
{
return this.password;
}
}然后就报了 Can't find a method to write property 'pwdNum' of type 'int' in a bean of type 'pa.Pwbean'的错了
写错了改成:
public void setPwdNum(int n)
get、set方法可以自动生成。