<?
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"
>
<
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
>
|
/*
* ClassName: LoginAction.java
* Author: qiujy
* CreateTime: Sep 26, 2007
*
* Copyright 2007 ++YONG All rights reserved.
* EMail: [email protected]
*/
package
org.qiujy.web.struts2.action;
/**
*
@author
qiujy
*
@version
1.0
*/
public
class
LoginAction {
private
String
userName
;
private
String
password
;
/**
*
@return
the
userName
*/
public
String getUserName() {
return
userName
;
}
/**
*
@param
userName
the
userName
to
set
*/
public
void
setUserName(String userName) {
this
.
userName
= userName;
}
/**
*
@return
the
password
*/
public
String getPassword() {
return
password
;
}
/**
*
@param
password
the
password
to
set
*/
public
void
setPassword(String password) {
this
.
password
= password;
}
/**
*
处理用户请求的
excute()
方法
*
@return
结果导航字符串
*
@throws
Exception
*/
public
String execute()
throws
Exception{
if
(
"test"
.equals(
this
.
userName
) &&
"test"
.equals(
this
.
password
)){
return
"success"
;
}
else
{
return
"error"
;
}
}
}
|
<!
DOCTYPE
struts
PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"
>
<
struts
>
<
include
file
=
"struts-default.xml"
/>
<!-- struts2
的
action
必须放在一个指定的包空间下定义
-->
<
package
name
=
"default"
extends
=
"struts-default"
>
<!--
定义处理请求
URL
为
login.action
的
Action -->
<
action
name
=
"login"
class
=
"org.qiujy.web.struts.action.LoginAction"
>
<!--
定义处理结果字符串和资源之间的映射关系
-->
<
result
name
=
"success"
>
/success.jsp
</
result
>
<
result
name
=
"error"
>
/error.jsp
</
result
>
</
action
>
</
package
>
</
struts
>
|
<%@
page
language
=
"java"
pageEncoding
=
"UTF-8"
%>
<
html
>
<
head
>
<
title
>
用户登录页面
</
title
>
</
head
>
<
body
>
<
h2
>
用户入口
</
h2
>
<
hr
>
<
form
action
=
"login.action"
method
=
"post"
>
<
table
border
=
"1"
>
<
tr
>
<
td
>
用户名
:
</
td
>
<
td
><
input
type
=
"text"
name
=
"userName"
/></
td
>
</
tr
>
<
tr
>
<
td
>
密码
:
</
td
>
<
td
><
input
type
=
"password"
name
=
"password"
/></
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
>
<
input
type
=
"submit"
value
=
"
确定
"
/>
</
td
>
</
tr
>
</
table
>
</
form
>
</
body
>
</
html
>
|
<%@
page
language
=
"java"
pageEncoding
=
"UTF-8"
%>
<%@
taglib
prefix
=
"s"
uri
=
"/struts-tags"
%>
<
html
>
<
head
>
<
title
>
登录成功
</
title
>
</
head
>
<
body
>
<
h2
>
登录成功
</
h2
>
<
br
>
欢迎
<
s:property
value
=
"userName"
/>
!!!
</
body
>
</
html
>
|
<%@
page
language
=
"java"
pageEncoding
=
"UTF-8"
%>
<
html
>
<
head
>
<
title
>
登录失败
</
title
>
</
head
>
<
body
>
<
h2
style
=
"color:red"
>
登录失败
</
h2
>
<
br
>
请重试!!!
</
body
>
</
html
>
|