Java Bean集属性
大家好:) 我在使用Bean时误解了setproperty? 当我这样做的时候Java Bean集属性,java,jsp,javabeans,Java,Jsp,Javabeans,大家好:) 我在使用Bean时误解了setproperty? 当我这样做的时候 <jsp:setProperty name="myBean" property="*"> 我必须使表单的字段名与myBean中的属性名相同 为了使HTTPRequest的值与myBean的属性匹配, 如果在表单字段中使用其他名称,则值将达到空值。 但是,如果我想在同一个jsp页面中使用表单值,并定义保存表单值的Bean,那么在表单字段中使用其他名称而不是相同的Bean属性名称是没有意义的!!这是为
<jsp:setProperty name="myBean" property="*">
我必须使表单的字段名与myBean中的属性名相同
为了使HTTPRequest的值与myBean的属性匹配,
如果在表单字段中使用其他名称,则值将达到空值。
但是,如果我想在同一个jsp页面中使用表单值,并定义保存表单值的Bean,那么在表单字段中使用其他名称而不是相同的Bean属性名称是没有意义的!!这是为什么
请看这里,password字段的名称是“password”,myBean属性的名称是pass,甚至它也可以工作
//index.jsp page
<form method="post" action="index.jsp">
Enter Your email:<input type="text" name="email"/>
<br/>
Enter Your Password :<input type="password" name ="pass">
<br/>
<input type="submit" name ="submit"/>
</form>
<jsp:useBean id="info" class="beans.info" scope="page">
<jsp:setProperty name="info" property="*"/>
</jsp:useBean>
Your email is : <jsp:getProperty name="info" property="email"/>
<br/>
Your Pass is : <jsp:getProperty name="info" property="pass"/>
</body>
//index.jsp页面
输入您的电子邮件:
输入您的密码:
您的电子邮件是:
您的通行证是:
谁能告诉我发生了什么事
编辑:我对代码进行修改。
<input type="password" name ="pass">
密码字段的名称也是pass
其他原因可能是您没有运行您认为正在运行的代码。请注意,bean名称
infoo
是错误的。我遇到了与您相同的问题,我刚刚制作了这个示例,它很有效
HTML页面
没有,我只是在这里修改,但是表单字段名是password not pass!!
<form name="registrationForm" id="registrationForm" method="post" action="registerBean.jsp" >
Full Name:*
<input type="text" name="fullname" id="fullname"/>
</form>
<jsp:useBean id="userBean" scope="session" class="Code.UserBean" />
<jsp:setProperty name="userBean" property="fullName" param="fullname" />
public class UserBean
{
private String fullName;
/**
* @return the fullName
*/
public String getFullName()
{
return fullName;
}
/**
* @param fullName the fullName to set
*/
public void setFullName(String fullName)
{
this.fullName = fullName;
}
}