开发者学堂课程【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 "/>
<!-﹣配置 struts 属性﹣->
<乱码解决﹣->
< Constant name =" struts .i18n. encoding " value =” UTF -8"/>
く! --﹣设置开发模式﹣->
< constant name =" struts . devMode " value =" true "/>
くconstant name =" struts . configuration . xmL . reload " value =" true "/>
< include file=" config / sxt / struts / user . xmL "/>
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 =" UTF-8"?>
<IDOCTYPE 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 >
</action>
</ 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 version="1.0" encoding =" UTF -8”?>
く--
/*
*$Id:struts-default .xml 1326928 2012-04-17 05:03:45Z iukaszlenart $
*
*Licensed to the Apache Software Foundation ( ASF ) under one or more contributor lcense agreements .See the NOTICE file distributed with thiS work for additional information
Regarding copyright ownership . The ASF licenses this file
to you under the Apache License,Version 2.0(the
"License”); you may not use this file except in compliance
With the License. You may obtain a copy of the license at
http://www.apache.org/licenses/LICENSE-2.e
" Unless required by applicable law or agreed to in Nriting
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 来实现的