首先新建一个典型web应用程序
然后建一个com.storm包,在包下写一个UserBean的类,添加private的属性之后只要点击菜单重构-封装字段就可以添加set和get方法

package  com.storm;
public   class  UserBean  {
    
private  String name;
    
private   int  sex;
    
private  String education;
    
private  String email;
    
public  String getName()  {
        
return  name;
    }


    
public   void  setName(String name)  {
        
this .name  =  name;
    }


    
public   int  getSex()  {
        
return  sex;
    }


    
public   void  setSex( int  sex)  {
        
this .sex  =  sex;
    }


    
public  String getEducation()  {
        
return  education;
    }


    
public   void  setEducation(String education)  {
        
this .education  =  education;
    }


    
public  String getEmail()  {
        
return  email;
    }


    
public   void  setEmail(String email)  {
        
this .email  =  email;
    }

}

然后再写一个注册页面index.jsp
<% @page contentType = " text/html; charset=GB2312 "   %>
< html >
    
< head >
        
< meta http - equiv = " Content-Type "  content = " text/html; charset=UTF-8 " >
        
< title > JSP Page </ title >
    
</ head >
    
< body >
        
< form name = " form "  action = " reg.jsp "  method = " POST " >
            
< table border = " 1 " >
                
< thead >
                    
< tr >
                        
< td > 用户名 </ td >
                        
< td >< input type = " text "  name = " name "  value = ""  width = " 6 "   /></ td >
                    
</ tr >
                
</ thead >
                
< tbody >
                    
< tr >
                        
< td > 性别 </ td >
                        
< td >  
                            
< input type = " radio "  name = " sex "  value = " 0 "   />

                            
< input type = " radio "  name = " sex "  value = " 1 "   />

                        
</ td >

                    
</ tr >
                    
< tr >
                        
< td > 学历 </ td >
                        
< td >< select name = " education " >
                            
< option value = " 高中 "  selected > 高中 </ option >
                            
< option value = " 大学 " > 大学 </ option >
                            
< option value = " 硕士 " > 硕士 </ option >
                            
< option value = " 博士 " > 博士 </ option >
                        
</ select ></ td >
                    
</ tr >
                    
< tr >
                        
< td > EMAIL </ td >
                        
< td >< input type = " text "  name = " mail "  value = ""  width = " 10 "   /></ td >
                    
</ tr >
                    
< tr >
                        
< td ></ td >
                        
< td ></ td >
                    
</ tr >
                    
< tr >
                        
< td >< input type = " submit "  value = " 提交 "  name = " submit "   /></ td >
                        
< td >< input type = " reset "  value = " 重置 "  name = " reset "   /></ td >
                    
</ tr >
                
</ tbody >
            
</ table >      
        
</ form >

    
</ body >
</ html >

form会交给reg.jsp处理,reg.jsp负责实例化一个javabean,并储存数据


<% @page contentType = " text/html; charset=GB2312 "   %>
< html >
    
< head >
        
< meta http - equiv = " Content-Type "  content = " text/html; charset=UTF-8 " >
        
< title > JSP Page </ title >
    
</ head >
    
< body >
        
<%
            request.setCharacterEncoding(
" GB2312 " );
        
%>
        
< jsp:useBean id = " user "  scope = " session "   class = " com.storm.UserBean " >
            
< jsp:setProperty name = " user "  property = " * "   />
            
< jsp:setProperty name = " user "  property = " email "  param = " mail "   />
        
</ jsp:useBean >
    
</ body >
</ html >

链接到get.jsp用于取出javabean的数据并显示

<%@page contentType="text/html; charset=GB2312" %>
<html>
    
<head>
        
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
<title>JSP Page</title>
    
</head>
    
<body>
<jsp:useBean id="user" scope="session" class="com.storm.UserBean" />
        
<jsp:getProperty name="user" property="name" /><br>
        你的性别:
<% int sex=user.getSex();
            
if(0==sex)
                out.println(
"");
            
else if(1==sex)
                out.println(
"");
        
%>
        
<br>
        你的学历:
<jsp:getProperty name="user" property="education" /><br>
        你的email:
<jsp:getProperty name="user" property="email" /><br>
    
</body>
</html>


需要注意的是同一个javabean实例在打开浏览器之后创建并储存数据直到关闭也无法通过后退再到Index.jsp-reg.jsp改变其中的数据
而且要支持中文必须在每个文件头加上 <%@page contentType="text/html; charset=GB2312" %>