Bean set属性
大家好:) 我在使用 Bean 时对 setPropety 有误解吗? 当我这样制作时,
<jsp:setProperty name="myBean" property="*">
我必须使表单的字段名称与 myBean 中的属性名称相同 为了使 HTTPRequest 的值与 myBean 的属性之间匹配, 如果我在表单字段中使用其他名称,则值将达到空值。 但是如果我想在同一个jsp页面中使用表单值,并定义保存表单值的Bean,那么如果我在表单字段中使用其他名称而不是bean属性的相同名称,那就没有意义了!!这是为什么 ??
看到这里,密码字段的名称是“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>
有人可以告诉我发生了什么事吗?
编辑:我对代码进行了修改。
Hello everybody :)
I have misunderstanging in setPropety in using Bean ?
when I make like this
<jsp:setProperty name="myBean" property="*">
I have to make the field names of the form the same as attribute names in myBean
in order to make match between values is HTTPRequest and the attributes of myBean,
if I use onther names in the form fields, values are reached null values.
but If I ever want to use the form values in the same jsp page , and define Bean that holds the values of the form, it doesn't make sence if I use other names in the form fields rather than the same name of bean attributes !! why is that ??
see here, the name of password field is "password" , and the name of attribute of myBean is pass, and even that it works !
//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>
can some one tell me what has happened?
Edit: I make modification to the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的密码字段的名称是也是
pass
。其他原因可能是您没有运行您认为正在运行的代码。请注意,bean 名称
infoo
是错误的。The name of your password field is also
pass
.Other cause could be that you aren't running the code you think you're running. Note that the bean name
infoo
is wrong.我遇到了和你一样的问题,我刚刚做了这个例子,它有效!
HTML 页面
registerBean.jsp
重点关注 (
param=""
) 属性,因为它一方面负责 html 表单字段名称,另一方面负责 javabean 之间的匹配。UserBean.java
I faced the same problem as you, and I just made this example and it works!
HTML page
registerBean.jsp
Focus on (
param=""
) attribute, because it's the one that will make the matching between the html form field name on one hand and javabean on the other hand.UserBean.java