javaBean在JSP中应用-小实例

1.
<html>
 <head>
  <title>transPara.htm</title>
 </head>
<body>
 <form method="POST" action="acceptPara.jsp">
    <p align="center">
  姓 名:<input type="text" name="name" size="20"><br>
    年 龄:&nbsp;&nbsp;&nbsp; <input type="text" name="age" size="15"><br>
    性 别:&nbsp;&nbsp;&nbsp;
   <input type="radio" value="male" checked name="sex">
    男&nbsp;&nbsp;&nbsp;&nbsp; 
     <input type="radio" name="sex" value="female">女</p>
    <p align="center">
   <input type="submit" value="submit" name="submit">
     <input type="reset" value="reset" name="reset"></p>
 </form>
</body>
</html>

2.
<html>

<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="atest"  class="test.AcceptPara"/>

<head><title>acceptPara.jsp</title></head>

<body>
<jsp:setProperty name="atest" property="*"/>   //  ***将javabean中的属性自动与html提交过来的变量匹配***********
Value of property "name" :
<jsp:getProperty name="atest" property="name"/><br>
Value of property "age" :
<jsp:getProperty name="atest" property="age"/><br>
Value of property "sex" :
<jsp:getProperty name="atest" property="sex"/><br>
Value of property "submit" :
<jsp:getProperty name="atest" property="submit"/><br>

</body>
</html>



3.
package test;//   在一些tomcat旧版本包定义一定要有,且在jsp引用中如下:<jsp:useBean id="atest"  class="test.AcceptPara"/>  编译后放在\WEB-INF\classes\test\中

public class AcceptPara{

 String name;
 int age;
 String sex;
 String submit;
 
 public void setName(String value){
  name=value;
 }
 
 public String getName(){
  return name;
 }
 
 public void setAge(int value){
  age=value;
 }
 
 public int getAge(){
  return age;
 }
 
 public void setSex(String value){
  sex=value;
 }
 
 public String getSex(){
  return sex;
 }
 
 public void setSubmit(String value){
  submit=value;
 }
 
 public String getSubmit(){
  return submit;
 }
  
 public void acceptPara(){}
 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值