开发者学堂课程【Java Web开发系列课程 - Struts2框架入门:团队协作配置】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/537/detail/7294
团队协作配置
内容介绍:
一、常量配置方式
二、团队协作开发配置
三、package 配置
一、常量配置方式
1.乱码解决
<!-﹣乱码解决-->
く constant name =” struts .i18n. encoding ” value =" UTF -8"/>
2.自定义扩展名
く!-- 自定义扩展名-->
<constant name ='”struts . action . extension "
value =" action ,, siggy “/>
3.友好的提示信息
<!-﹣设置开发模式-->
く constant name =" struts . devMode”value =" true "/>
4.设置配置文件修改后自动加载﹣推荐在开发中使用
< constant name =" struts . configuration . xmL . reload " value =" true "/>
5.常量配置方式二
在 src 下添加 struts . properties 配置文件
二、团队协作开发配置
1.通过 include 添加不同人员的配置文件
较正规配置:
config.sxt.struts
config.sxt.hibernate
config.sxt.spring
会根据模块来选择
找不到 user 上,需要一个连接点接口(文件夹/目录)指向它,即
< include file =" config / sxt / struts / user . xmL "/>
<!-﹣配置 strut
s
属性﹣->
<乱码解决﹣->
< Constant name =" struts .
i
18n. encoding " value =
”
UTF -8"
/
>
く
!
--﹣设置开发模式﹣->
< constant name =" struts . devMode " value =" tr
u
e "/>
く
c
onstant name =" struts . configuration .
x
mL . re
l
oad " value
=
" true "/>
< include f
i
le=" config / sxt / struts / use
r
.
x
mL "/
>
2.user模块配置:
<xml version=
”
1.0
”
encoding=
”
UTF-8?>
<!DOCTYPE struts PUBLIC
“
-// Apache Software Foundation//DTD Struts Configuration 2.3EN
”
“http://struts.apache.org/dtds/struts-2.3.dtd
”
>
く struts >
< package name =" user ” namespace ="/” extends =" struts - default
“
>
く action name =" Login ” class =" cn . sxt . action . LoginAction ">
く result >/ success . jsp </ result >
く result name =" failed ">/ login . jsp </ result >
</ action >
</ package >
</ struts >
三、package 配置
く!-﹣包的名称自定义,可以配置多个包; namespace 命名空间:不同模块可以指定不同的空国
extends 值是直接或者间接继承 struts - default
-
->
< package name =" user ” namespace ="/ user " extends =" struts - defautt >
1.package 配置找到 name
<? xml
version ="1.
0
” encoding =" UT
F
-8"?>
<ID
O
CTYPE
struts PUBLIC
"-
/
/Apache Software Foundation // DTD Struts
Configuration 2.3// EN "
"http://struts. apache . org / dtds / struts -2.3.dtd">
<struts>
<!
-﹣包的名称自定义,可以配置多个包
;
namespace 命名空间
:
不同模块可以指在不同的空
间
-->
< package name =" user ” namespace ="/ user " extends =" struts - defauLt
“
>
< action name =" Login ” class =" cn . sxt . action .LoginAction ">
<
result >/ success jsp く/ result >
<
result name =" failed ">/ login . jsp </ result >
</act
i
on>
</ package >
<struts>
2. 一个项目中需要管理很多类,aciton 名字不能重复,使用框架,遵循规则,可以使代码很规范,风格变得一致。风格一致可以使代码读起来方便不会乱,代码需要整齐干净。
要变得不同,在请求之前加上空间名称即可,加空间名称时需要注意加/,如果不加会找到命名空间下的jsp文件。
<body>
<form action =
”
user/login.siggy
”
method=
”
post
”
>
用户名:<input type=
”
text
”
name=
”
name
”
/><br>
密码:<input type=
”
password
”
name=
”
pwd
”
/><br>
<input type=
”
submit
”
value=
”
登录”/>
</form>
</body>
</html>
3.extends 继承
extends 值是直接或者间接继承 struts - default
核心包中有 struts-default.xml
Struts-default.xml:
<?Xml v
er
si
on="1.0" encoding =" UTF -8”?>
く-
-
/*
*$Id
:
s
trut
s-
default .
x
ml
1326928
2012-04-17
05:03:45Z
i
uka
sz
lenart
$
*
*
L
i
censed t
o
the
Apache Software Foundation ( ASF ) und
e
r one or more c
o
ntributor
lc
ense agreement
s
.
S
ee the NOT
I
CE
file distri
buted
wi
th
thiS
wo
rk
for addit
i
ona
l
information
Regard
i
ng
c
op
yr
i
ght
ow
nership . The ASF
l
icenses
thi
s fil
e
to
y
o
u
u
nder
the Apache
L
ic
ense,Ver
sio
n
2.0
(
the
"L
i
cense”
);
you may not use this
f
il
e except in c
o
mp
li
ance
Wi
th
the
L
ic
ense. You may
obta
i
n a
co
py
o
f
the
li
cense at
http://
www
.apache.org/
l
icenses/LICENSE-2.e
" Unless required by applicable law or agreed to in Nritin
g
4.配置文件加载顺序
struts-default.xml--->struts-plugin.xml--->struts.xml
console中:Parsing configuration file 【
struts-default.xml
】
Parsing configuration file 【
struts-plugin.xml
】
Parsing configuration file 【
struts.xml
】
<package name =
”
struts-default
”
abstract=
”
true
”
>
继承的是 struts-default,功能通过一系列 interceptor 来实现的