H2O
BlogJava
首頁
新隨筆
聯系
聚合
管理
隨筆分類
java
(rss)
職業生涯o 0O
(rss)
文章分類
ajax(6)
(rss)
css(5)
(rss)
DataBase(9)
(rss)
ejb
(rss)
EXT(1)
(rss)
hibernate(4)
(rss)
java(14)
(rss)
javascript(13)
(rss)
spring(1)
(rss)
Spring+Struts+Hibernate整合(4)
(rss)
struts(4)
(rss)
webwork
(rss)
職業生涯規劃(1)
(rss)
那一天o 0 O(1)
(rss)
面試(1)
(rss)
文章檔案
2013年10月 (1)
2013年9月 (30)
2013年8月 (7)
2012年2月 (1)
2011年9月 (1)
2011年8月 (1)
2010年10月 (1)
2009年10月 (5)
2009年9月 (4)
2009年8月 (2)
2009年7月 (2)
2009年6月 (4)
2009年5月 (7)
2009年3月 (3)
2008年12月 (1)
2008年11月 (3)
2008年10月 (8)
2008年9月 (12)
2008年8月 (8)
相冊
程序相關
最新隨筆
1.?Debian / Ubuntu ---support UTF-8 locale/encoding
2.?Firefox Latest version
3.?重寫 FastJson 屬性過濾器
4.?freeradius for pptp
5.?Configuring Wildcard AlphaSSL from Centrio Host
6.?SSL
7.?some errors occured in complie firefox source
8.?checking for libnotify >= 0.4... Package libnotify was not found in the pkg-config search path.
9.?modify max_connections on mysql
10.?centos encoding
最新評論
1.?re: js獲取textarea中輸入文本的本選擇內容
333333
--333
2.?re: 小毅原創---struts+spring+hibernate整合小例子
俄方
--預報呢
3.?re: some errors occured in complie firefox source
Thank you very very much for this post!
jelz
--Jelz
4.?re: some errors occured in complie firefox source
Thank you very much for this post!
Jelz
--Jelz
5.?re: Ibatis之LIKE用法[未登錄]
如果用'%$note$%'會造成sql注入的漏洞,使用拼接字符串的方法不錯
--KANG
小毅也玩struts2之helloWorld程序改進版(增加了驗證功能和struts標簽使用)
Posted on 2008-10-09 20:30
H2O
閱讀(394)
評論(0)
編輯
收藏
所屬分類:
struts
login.jsp
<%
@ page language
=
"
java
"
pageEncoding
=
"
UTF-8
"
%>
<%
@taglib prefix
=
"
s
"
uri
=
"
/struts-tags
"
%>
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>
<
html
>
<
head
>
<
title
>
struts標簽的登陸頁面
</
title
>
</
head
>
<
body
>
<
s:form
name
="loginForm"
method
="post"
action
="login"
>
<
s:textfield
name
="username"
label
="用戶名"
></
s:textfield
>
<
s:password
name
="pwd"
label
="密 碼"
></
s:password
>
<
s:submit
label
=" 登 陸 "
></
s:submit
>
<
s:reset
label
=" 重 置 "
></
s:reset
>
</
s:form
>
</
body
>
</
html
>
show.jsp
<%
@ page language
=
"
java
"
pageEncoding
=
"
UTF-8
"
%>
<
html
>
<
head
>
<
title
>
顯示結果
</
title
>
</
head
>
<
body
>
<!--
因為struts2都是用的dispatcher即轉發,都是同一次請求,所以可以到request作用于中取值
-->
<
h3
>
用戶名--->${requestScope.username}
<
br
>
密碼--->${requestScope.pwd}
<
br
>
</
body
>
</
html
>
loginAction
package
com.yz.struts2.actions;
import
com.opensymphony.xwork2.ActionSupport;
public
class
loginAction
extends
ActionSupport
{
private
String username;
private
String pwd;
public
String getUsername()
{
return
username;
}
public
void
setUsername(String username)
{
this
.username
=
username;
}
public
String getPwd()
{
return
pwd;
}
public
void
setPwd(String pwd)
{
this
.pwd
=
pwd;
}
public
String helloWorld()
{
System.out.println(
"
用戶名--->
"
+
username);
System.out.println(
"
密碼--->
"
+
pwd);
if
(
"
小毅
"
.equals(username)
&&
"
xiaoyi
"
.equals(pwd))
{
return
"
ok
"
;
//
查找名字為ok的result,相當于struts1.*的foward名
}
else
{
this
.addFieldError(
"
username
"
,
"
用戶名或密碼錯誤
"
);
return
"
failer
"
;
}
}
//
驗證表單輸入
@Override
public
void
validate()
{
if
(
""
.equals(
this
.getUsername().trim())
||
null
==
this
.getUsername())
{
//
第一個參數為: index.jsp表單中的文本框的name(名字)第二個為錯誤消息
this
.addFieldError(
"
username
"
,
"
用戶名不能為空
"
);
}
if
(
""
.equals(
this
.getPwd().trim())
||
null
==
this
.getPwd())
{
this
.addFieldError(
"
pwd
"
,
"
密碼不能為空
"
);
}
}
}
web.xml
<?
xml version="1.0" encoding="UTF-8"
?>
<
web-app
version
="2.4"
xmlns
="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>
<!--
struts2采用過濾器過濾客戶端發送給服務器的所有請求
-->
<
filter
>
<
filter-name
>
struts2
</
filter-name
>
<
filter-class
>
org.apache.struts2.dispatcher.FilterDispatcher
</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
struts2
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
<
welcome-file-list
>
<
welcome-file
>
index.jsp
</
welcome-file
>
</
welcome-file-list
>
</
web-app
>
struts.xml
<?
xml version="1.0" encoding="UTF-8"
?>
<!
DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"
>
<
struts
>
<!--
struts2會自動到classes下找struts.xml,
直接放在src下工具會自動把src下的文件編譯到classes下
dtd頭信息表示 sturs為根標簽
-->
<!--
struts2這個包繼承sturs2內置的包struts-default
-->
<
package
name
="struts2"
extends
="struts-default"
>
<!--
配置action
name: 對應index.jsp頁面中form的action= login.action 的login
struts默認所有以點action結尾的請求交給struts處理,因為繼承自webwork的特性,習慣于這樣。。
class: action對應的類,包名點類名全路徑(com.yz.struts2.loginAction)
method:請求該action時自動執行的方法,如果沒有配置默認執行execute方法
-->
<
action
name
="login"
class
="com.yz.struts2.actions.loginAction"
method
="helloWorld"
>
<!--
result默認的name為success
-->
<
result
name
="ok"
>
/show.jsp
</
result
>
<!--
在繼承ActionSuport的action中的validate方法來驗證表單輸入信息,驗證中添加filedError后返回
name為input的result對應的頁面,必須name為input,類似于struts1.*中action配置的input
-->
<
result
name
="input"
>
/login2.jsp
</
result
>
<
result
name
="failer"
>
/login2.jsp
</
result
>
</
action
>
</
package
>
</
struts
>
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
小毅收藏整理----解決struts、jsp下載文件時中文文件名亂碼問題
小毅也玩struts2之validate方法簡單的數據驗證
小毅也玩struts2之helloWorld程序改進版(增加了驗證功能和struts標簽使用)
小毅也玩struts2之--->HelloWorld程序
評論排行榜
閱讀排行榜
posts - 0, comments - 21, trackbacks - 0, articles - 101
Copyright © H2O
主站蜘蛛池模板:
色播在线永久免费视频
|
搡女人真爽免费视频大全
|
国产成人A亚洲精V品无码
|
免费一级全黄少妇性色生活片
|
免费高清在线爱做视频
|
亚洲欧洲无码AV不卡在线
|
国产精品免费视频一区
|
免费高清A级毛片在线播放
|
亚洲AV永久无码精品一区二区国产
|
校园亚洲春色另类小说合集
|
免费大黄网站在线看
|
一区二区在线免费视频
|
亚洲精品二区国产综合野狼
|
久久国产精品2020免费m3u8
|
亚洲男人天堂影院
|
成人毛片免费观看视频
|
国产精品亚洲五月天高清
|
最新国产AV无码专区亚洲
|
人妻无码久久一区二区三区免费
|
亚洲午夜在线一区
|
全黄a免费一级毛片人人爱
|
香蕉视频在线免费看
|
亚洲网红精品大秀在线观看
|
在线精品一卡乱码免费
|
美女又黄又免费的视频
|
久久久青草青青亚洲国产免观
|
亚洲精品无码午夜福利中文字幕
|
国产在线精品免费aaa片
|
亚洲精品偷拍无码不卡av
|
免费观看的a级毛片的网站
|
五月天婷婷免费视频
|
麻豆亚洲av熟女国产一区二
|
女人18毛片水真多免费看
|
久久嫩草影院免费看夜色
|
亚洲国产av一区二区三区丶
|
免费一级大黄特色大片
|
午夜免费福利小电影
|
男女超爽视频免费播放
|
亚洲精品高清国产一久久
|
国产伦精品一区二区三区免费下载
|
成在线人视频免费视频
|