strtus2搭建步骤:
1.拷贝所需jar到WEB工程目录下的lib
2.配置WEB.xml文件,配置过滤器Filter
1
2
3
4
5
6
7
8
9
10
|
<
filter
>
<
filter-name
>struts2</
filter-name
>
<
filter-class
>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>struts2</
filter-name
>
<
url-pattern
>/*</
url-pattern
>
</
filter-mapping
>
|
3.编写login.jsp:
1
2
3
4
5
6
|
<
form
action
=
"login.action"
method
=
"post"
>
<
h1
>用户登录</
h1
>
账号:<
input
type
=
"text"
name
=
"userName"
/><
br
/>
密码:<
input
type
=
"password"
name
=
"passWord"
><
br
/>
<
input
type
=
"submit"
value
=
"登录"
/>
</
form
>
|
4.创建LoginAction类继承ActionSupport类,重写execute()
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
32
33
|
package
com.liu.web.action;
import
com.opensymphony.xwork2.ActionSupport;
/**
* 用户登录的action
* @author Administrator
*
*/
public
class
LoginAction
extends
ActionSupport{
private
String userName;
private
String passWord;
@Override
public
String execute()
throws
Exception {
System.out.println(
"账号:"
+userName);
System.out.println(
"密码:"
+passWord);
return
"success"
;
}
public
String getUserName() {
return
userName;
}
public
void
setUserName(String userName) {
this
.userName = userName;
}
public
String getPassWord() {
return
passWord;
}
public
void
setPassWord(String passWord) {
this
.passWord = passWord;
}
}
|
5.拷贝struts.xml配置文件到src目录下:
1
2
3
4
5
6
7
8
|
<
constant
name
=
"struts.enable.DynamicMethodInvocation"
value
=
"false"
/>
<
constant
name
=
"struts.devMode"
value
=
"true"
/>
<
package
name
=
"default"
namespace
=
"/"
extends
=
"struts-default"
>
<
action
name
=
"login"
class
=
"com.liu.web.action.LoginAction"
>
<
result
name
=
"success"
>/success.jsp</
result
>
</
action
>
</
package
>
|
版权声明:原创作品,如需转载,请注明出处。否则将追究法律责任
本文转自 l363130002 51CTO博客,原文链接:http://blog.51cto.com/liuyj/1715860