虾米爬啊爬
-xiami's blog
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(4)
给我留言
查看公开留言
查看私人留言
随笔档案
(16)
2007年7月 (1)
2007年5月 (1)
2007年4月 (1)
2007年3月 (2)
2006年11月 (11)
相册
xiami's photo
最新随笔
1. where 1=1(摘)
2. String 转 Date
3. 命名规则
4. ajax(百度百科)
5. 名词解释(来源于百度百科)
6. 使用netbeans开发一个javabean程序
7. 建立一个螺旋形矩阵A[n][n]
8. servlet-api的基本类和其接口介绍
9. 使用netbeans启动捆绑tomcat出现某工程目录does not exist or is not a readable directory
10. JAVA连接MYSQL
11. 管道流通信
12. 用File类来列出和筛选所有文件
13. java.util下的Class Collections的两种sort方法使用
14. 静态内部类
15. 1.5容器note问题
积分与排名
积分 - 17847
排名 - 1849
最新评论
1. re: 使用netbeans启动捆绑tomcat出现某工程目录does not exist or is not a readable directory
评论内容较长,点击标题查看
--rel
2. re: 使用netbeans启动捆绑tomcat出现某工程目录does not exist or is not a readable directory
多半是只读,改下子文件属性,把只读去掉
--老左zuoge85@gmail.com
3. re: 使用netbeans启动捆绑tomcat出现某工程目录does not exist or is not a readable directory
看看你们那个文件目录是不是只读的
--老左zuoge85@gmail.com
4. re: servlet-api的基本类和其接口介绍
东西很多但是很抽象,迷糊中...
--sophia
5. re: 使用netbeans启动捆绑tomcat出现某工程目录does not exist or is not a readable directory
谢谢谢谢 我也这样 终于找到答案了
--amber
阅读排行榜
1. 使用netbeans启动捆绑tomcat出现某工程目录does not exist or is not a readable directory(5492)
2. String 转 Date(2678)
3. java.util下的Class Collections的两种sort方法使用(2169)
4. 使用netbeans开发一个javabean程序(1945)
5. 使用commons-fileupload包进行文件上传(1001)
评论排行榜
1. 使用netbeans启动捆绑tomcat出现某工程目录does not exist or is not a readable directory(4)
2. servlet-api的基本类和其接口介绍(1)
3. where 1=1(摘)(0)
4. String 转 Date(0)
5. 命名规则(0)
Powered by:
博客园
模板提供:
沪江博客
BlogJava
|
首页
|
发新随笔
|
发新文章
|
联系
|
聚合
|
管理
使用netbeans开发一个javabean程序
首先新建一个典型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
"
%>
发表于 2006-11-30 15:04
虾米
阅读(1945)
评论(0)
编辑
收藏
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理