五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

namespace,運(yùn)行action的2種方法,struts.xml加載和分模塊配置,包配置【詩書畫唱】

2021-01-04 23:46 作者:詩書畫唱  | 我要投稿

本期內(nèi)容概括:

namespace

運(yùn)行action的方法

struts.xml加載和分模塊配置

包配置

action啟動(dòng)(比如跳轉(zhuǎn)界面)方法1

action啟動(dòng)方法2

視頻友情推薦

運(yùn)行action的方法START

運(yùn)行action的方法END


struts.xml加載和分模塊配置START

一般情況下,namespace將action分成邏輯上的不同模塊,每一個(gè)模塊有自己獨(dú)立的前綴。使用namespace可以有效的避免action重名的沖突,struts2標(biāo)簽帶有namespace選項(xiàng),可以根據(jù)namespace的不同向服務(wù)器提交不同的package的action的請求。但是以下特殊情況:

1、namespace的值為“/”時(shí),如果輸入的action在別的命名空間沒有找到,則最終會執(zhí)行該命名空間下的action。

2、namespace的值為“”時(shí),或者namespace屬性省略不寫時(shí),跟namespace的值為“/”一樣。









struts.xml加載和分模塊配置END




包配置PPT START






包配置PPT END


講義START


struts2框架的配置方法1:

1、導(dǎo)入框架包

2、導(dǎo)入核心配置文件struts.xml(這個(gè)文件名不能夠更改),放在src目錄下

3、web.xml文件添加一個(gè)struts2框架的過濾器


struts2框架的配置方法2:

1、導(dǎo)入框架包

2、將配置文件放在WebContent/WEB-INF目錄下,文件名可以自己取(必須是xml)

3、web.xml文件添加一個(gè)struts2框架的過濾器,并且通過<init-param>標(biāo)簽指定配置文件的路徑



講義END


視頻START


視頻END

例子START

namespace:


action啟動(dòng)(比如跳轉(zhuǎn)界面)方法1:固定的struts.xml? ?START:



——————


http://localhost:8080/STRUTS2fenMoKuaiJavaWeb/testAc.action

————

package com.jy.action;


public class TestAction {

//http://localhost:8080/J1908021/testAc.action

? ? public String execute(){

? ? return "success";

? ? }

}

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC "-//Apache Software?

Foundation//DTD Struts Configuration 2.1//EN"?

"http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>

? ? <!-- 加載user.xml中的配置到項(xiàng)目中 -->

? ? <include file="com/jy/action/user.xml"></include>??

</struts>

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

? <display-name>J1908021</display-name>

? <!-- struts2框架的配置 -->

? <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>

? <welcome-file-list>

? ? <welcome-file>index.html</welcome-file>

? ? <welcome-file>index.htm</welcome-file>

? ? <welcome-file>index.jsp</welcome-file>

? ? <welcome-file>default.html</welcome-file>

? ? <welcome-file>default.htm</welcome-file>

? ? <welcome-file>default.jsp</welcome-file>

? </welcome-file-list>

</web-app>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%

? ? String path = request.getContextPath();

? ? String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

? ? <head>

? ? ? ? <base hreff="<%=basePath%>">

? ? ? ? <title></title>

? ? ? ? <meta http-equiv="pragma" content="no-cache">

? ? ? ? <meta http-equiv="cache-control" content="no-cache">

? ? ? ? <meta http-equiv="expires" content="0">

? ? ? ? <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

? ? ? ? <meta http-equiv="description" content="This is my page">

? ? </head>

? ? <body>

? ? ? ? <h1>Hello world</h1>

? ? </body>

</html>

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>

? ? <!-- name就是包的名字,方便其他的包進(jìn)行引用的,

? ? ? ? ? ? ? ? ? 整個(gè)項(xiàng)目中的name屬性必須是唯一的 -->

? ? <!-- namespace就是避免調(diào)用同名的action時(shí)產(chǎn)生歧義的屬性 -->

? ? <!-- extends屬性表示當(dāng)前的包繼承自哪個(gè)name屬性的包 -->

? ? <package name="user" namespace="/pub" extends="struts-default">

? ? ? ? <action name="regAc" class="com.jy.action.UserAction">

? ? ? ? ? ? <result name="success">/reg.jsp</result>

? ? ? ? </action>

? ? </package>?

? ? <package name="test" namespace="/" extends="struts-default">

? ? ? ? <action name="testAc" class="com.jy.action.TestAction">

? ? ? ? ? ? <result name="success">/Hello.jsp</result>

? ? ? ? </action>

? ? </package>?

</struts>





package com.jy.action;


public class UserAction {

//http://localhost:8080/J1908021/pub/regAc.action

? ? public String execute(){

? ? return "success";

? ? }

}



action啟動(dòng)(比如跳轉(zhuǎn)界面)方法1:固定的struts.xml? END


action啟動(dòng)方法2:自定義的XXX.xml??START


package com.jy.action;


public class HelloAction {

//http://localhost:8080/J1908022/u/hlAc.action

? ? public String execute(){

? ? System.out.println("Hello world");

? ? return null;

? ? }

}



<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>? ?

</struts>


<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>

? ? <package name="user" namespace="/u" extends="struts-default">

? ? ? ? <action name="hlAc" class="com.jy.action.HelloAction"></action>

? ? </package>

</struts>



<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

? <display-name>J1908022</display-name>

? <!-- struts2框架的配置 -->

? <filter>

? ? ? <filter-name>struts2</filter-name>

? ? ? <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

? ? ? <!-- 加載指定位置的struts2框架的配置文件 -->

? ? ? <init-param>

? ? ? ? ? <param-name>config</param-name>

? ? ? ? ? <param-value>

? ? ? ? ? ? ? struts-default.xml,

? ? ? ? ? ? ? ../struts_config/user.xml,

? ? ? ? ? ? ? ../struts_config/product.xml

? ? ? ? ? </param-value>

? ? ? </init-param>

? </filter>

? <filter-mapping>

? ? ? <filter-name>struts2</filter-name>

? ? ? <url-pattern>/*</url-pattern>

? </filter-mapping>

? <welcome-file-list>

? ? <welcome-file>index.html</welcome-file>

? ? <welcome-file>index.htm</welcome-file>

? ? <welcome-file>index.jsp</welcome-file>

? ? <welcome-file>default.html</welcome-file>

? ? <welcome-file>default.htm</welcome-file>

? ? <welcome-file>default.jsp</welcome-file>

? </welcome-file-list>

</web-app>




action啟動(dòng)方法2:自定義的XXX.xml??END


例子END



namespace,運(yùn)行action的2種方法,struts.xml加載和分模塊配置,包配置【詩書畫唱】的評論 (共 條)

分享到微博請遵守國家法律
密云县| 赤峰市| 福清市| 孙吴县| 嘉义县| 镇康县| 甘孜县| 九龙县| 新丰县| 兴仁县| 文昌市| 霍城县| 卓资县| 化州市| 安乡县| 唐河县| 曲水县| 分宜县| 南江县| 监利县| 克山县| 永顺县| 芜湖县| 平利县| 阳西县| 乡宁县| 柏乡县| 武胜县| 呼和浩特市| 黄石市| 盘锦市| 双城市| 额济纳旗| 天峨县| 铁岭县| 聂拉木县| 临潭县| 溆浦县| 巨鹿县| 内丘县| 祁连县|