小黑J2EE學(xué)習(xí)ing
我很會(huì)努力
BlogJava
首頁
新隨筆
聯(lián)系
聚合
管理
隨筆-21 評(píng)論-29 文章-0 trackbacks-0
小黑Struts學(xué)習(xí)(三)
模塊:
使用Struts增加學(xué)生
分析:
①Struts環(huán)境
②AddStudentForm(extends ActionForm)
sId,sname, major, birth, score
<form-bean name="addStudentForm" type="cn.itcast.AddStudentForm">
</form-bean>
③AddStudentAction(extends Action)
覆蓋execute
<action path="/addStudentAction" type="cn.itcast.AddStudentAction" name="addStudentForm">
<forward name="addStudentSuccess" path="/addStudentSuccess.jsp">
<forward name="addStudentFailure" path="/addStudent.jsp">
</action>
IStudentDAO,StudentDAO
addStudent(AddStudentForm form)
④JSP: addStudent.jsp addStudentSuccess
流程圖:
實(shí)踐操作實(shí)現(xiàn)過程
先建AddStudentForm,其繼承自ActionForm類
可參看Struts API 參考ActionForm的相關(guān)信息
AddStudentForm類的代碼為 (注意使用source里面的Generate Getters and Setters)
package
cn.itcast;
import
org.apache.struts.action.ActionForm;
public
class
AddStudentForm
extends
ActionForm
{
private
static
final
long
serialVersionUID
=
1L
;
private
String sname
=
null
;
private
String major
=
null
;
private
String score
=
null
;
private
java.sql.Date birth
=
null
;
public
String getSname()
{
return
sname;
}
public
void
setSname(String sname)
{
this
.sname
=
sname;
}
public
String getMajor()
{
return
major;
}
public
void
setMajor(String major)
{
this
.major
=
major;
}
public
String getScore()
{
return
score;
}
public
void
setScore(String score)
{
this
.score
=
score;
}
public
java.sql.Date getBirth()
{
return
birth;
}
public
void
setBirth(java.sql.Date birth)
{
this
.birth
=
birth;
}
}
在struts-config.xml中添加
<form-bean name="addStudentForm" type="cn.itcast.AddStudentForm"></form-bean>
新建一個(gè)
AddStudentAction類
,其繼承Action類
AddStudentAction類
覆蓋execute方法 并在struts-config.xml中加入action標(biāo)簽 如下所示
建立IStudentDAO
新建StudentDAO,使其實(shí)現(xiàn)IStudentDAO接口 并把StudentDAO返回值改為true
編寫AddStudentAction類代碼 如下
package
cn.itcast;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
import
org.apache.struts.action.Action;
import
org.apache.struts.action.ActionForm;
import
org.apache.struts.action.ActionForward;
import
org.apache.struts.action.ActionMapping;
public
class
AddStudentAction
extends
Action
{
@Override
public
ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws
Exception
{
//
1.cast the form to its subclass
AddStudentForm addStudentForm
=
(AddStudentForm) form ;
//
2.invoke the IStudentDAO module
IStudentDAO studentDAO
=
new
StudentDAO();
boolean
successful
=
false
;
successful
=
studentDAO.addStudent(addStudentForm);
//
3.forward to next module by the result of the business logic
String returnURLKeyWord
=
"
addStudentFailure
"
;
if
(successful
==
true
)
{
returnURLKeyWord
=
"
addStudentSuccess
"
;
}
return
mapping.findForward(returnURLKeyWord);
}
}
新建兩個(gè)JSP頁面 AddStudent.jsp 和 AddStudentSuccess.jsp
<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=ISO-8859-1
"
pageEncoding
=
"
ISO-8859-1
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
>
<
html
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=ISO-8859-1"
>
<
title
>
Insert title here
</
title
>
</
head
>
<
body
>
<
form
action
="<%= request.getContextPath()%>/addStudentAction.do"
method
="get"
>
sname:
<
input
type
="text"
name
="sname"
><
br
>
major:
<
input
type
="text"
name
="major"
><
br
>
birth:
<
input
type
="text"
name
="birth"
><
br
>
score:
<
input
type
="text"
name
="score"
><
br
>
<
input
type
="submit"
value
="add"
>
</
form
>
</
body
>
</
html
>
<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=ISO-8859-1
"
pageEncoding
=
"
ISO-8859-1
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
>
<
html
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=ISO-8859-1"
>
<
title
>
Insert title here
</
title
>
</
head
>
<
body
>
Succeed in adding a student!!!
</
body
>
</
html
>
部署應(yīng)用 并訪問測(cè)試
以上步驟實(shí)現(xiàn)了添加學(xué)生的基本功能,由于本機(jī)沒有安裝oracle數(shù)據(jù)庫,應(yīng)用數(shù)據(jù)庫實(shí)現(xiàn)模塊的設(shè)計(jì)以后再補(bǔ)充!
posted on 2009-05-02 16:44
特立獨(dú)行
閱讀(354)
評(píng)論(0)
編輯
收藏
所屬分類:
Struts框架
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關(guān)文章:
JFreeChart的中文亂碼問題 知道的幫忙解決一下
struts2實(shí)現(xiàn)文件上傳和下載
小黑struts學(xué)習(xí)(五) Action Mapping、ActionForward和ActionForm組件學(xué)習(xí)
小黑Struts學(xué)習(xí)(四)
小黑Struts學(xué)習(xí)(三)
小黑struts學(xué)習(xí)(二) 第一個(gè)實(shí)例的原理分析和Struts工作原理分析
小黑Struts學(xué)習(xí)(一)
小黑J2EE學(xué)習(xí)之路 歡迎大家觀臨! 希望大家能多指教哦!
<
2025年5月
>
日
一
二
三
四
五
六
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
常用鏈接
我的隨筆
我的評(píng)論
我的參與
最新評(píng)論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆分類
Hibernate框架(6)
J2EE核心技術(shù)(1)
Java 技術(shù)
Java面試題
Spring框架(5)
Struts框架(7)
數(shù)據(jù)庫
隨筆檔案
2010年6月 (2)
2009年6月 (1)
2009年5月 (17)
2009年4月 (1)
搜索
最新評(píng)論
1.?re: struts2實(shí)現(xiàn)文件上傳和下載[未登錄]
下載做來直接就在頁面把文件打開了。。
--小菜
2.?re: struts2實(shí)現(xiàn)文件上傳和下載
你這代碼量有點(diǎn)多,STRUTS2封裝好了,頂多15行搞定
--你這代碼量有點(diǎn)多
3.?re: struts2實(shí)現(xiàn)文件上傳和下載
怎么將上傳的東西在頁面上顯示出來啊
--邊城
4.?re: struts2實(shí)現(xiàn)文件上傳和下載
配置的文件 有關(guān)鍵字, 把a(bǔ)ction 中的name 換下就可以了 @陳
--采用
5.?re: struts2實(shí)現(xiàn)文件上傳和下載
大俠 ……怎么實(shí)現(xiàn)點(diǎn)一個(gè)文件下載一個(gè)文件,而不是固定的文件?
--pppppppppp
閱讀排行榜
1.?struts2實(shí)現(xiàn)文件上傳和下載(17518)
2.?小黑struts學(xué)習(xí)(五) Action Mapping、ActionForward和ActionForm組件學(xué)習(xí)(1626)
3.?小黑Hibernate學(xué)習(xí)(三) Session接口及get、load、persist方法(1006)
4.?ASSH框架的技術(shù)基礎(chǔ)和設(shè)計(jì)(762)
5.?Spring 框架的設(shè)計(jì)理念與設(shè)計(jì)模式分析(654)
評(píng)論排行榜
1.?struts2實(shí)現(xiàn)文件上傳和下載(27)
2.?Spring 框架的設(shè)計(jì)理念與設(shè)計(jì)模式分析(1)
3.?很開心加入BlogJava 就像找到了組織一樣(1)
4.?Spring 框架的設(shè)計(jì)理念與設(shè)計(jì)模式分析(2)(0)
5.?JFreeChart的中文亂碼問題 知道的幫忙解決一下(0)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 特立獨(dú)行
主站蜘蛛池模板:
A片在线免费观看
|
黄色免费在线网址
|
中文在线日本免费永久18近
|
国产大片91精品免费观看男同
|
成人亚洲国产va天堂
|
欧亚精品一区三区免费
|
久久亚洲AV成人无码国产
|
67pao强力打造高清免费
|
久久久无码精品亚洲日韩蜜臀浪潮
|
免费视频成人手机在线观看网址
|
日本亚洲视频在线
|
久久精品视频免费看
|
亚洲精品中文字幕乱码
|
999国内精品永久免费视频
|
亚洲人xxx日本人18
|
四虎成人精品在永久免费
|
青青草97国产精品免费观看
|
丁香五月亚洲综合深深爱
|
国产精品免费观看调教网
|
亚洲成a人片7777
|
毛片大全免费观看
|
无遮挡呻吟娇喘视频免费播放
|
AV在线亚洲男人的天堂
|
一级毛片免费观看不卡的
|
亚洲乱码卡三乱码新区
|
免费国产不卡午夜福在线
|
一区视频免费观看
|
亚洲AV本道一区二区三区四区
|
国产在线观看麻豆91精品免费
|
亚洲一卡一卡二新区无人区
|
免费人成网站7777视频
|
国产成人免费AV在线播放
|
香蕉97碰碰视频免费
|
亚洲毛片不卡av在线播放一区
|
永久免费av无码网站yy
|
亚洲av无码片区一区二区三区
|
免费人成网站在线高清
|
久久精品成人免费看
|
精品亚洲456在线播放
|
亚洲精品无码av天堂
|
16女性下面无遮挡免费
|