• <label id="pxtpz"><meter id="pxtpz"></meter></label>
      1. <span id="pxtpz"><optgroup id="pxtpz"></optgroup></span>

        當前位置:雨林木風下載站 > 技術(shù)開發(fā)教程 > 詳細頁面

        半翻譯半整理的一些struts的東東,很淺顯的,歡迎指正(二)

        半翻譯半整理的一些struts的東東,很淺顯的,歡迎指正(二)

        更新時間:2021-11-16 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

        3.Struts Plugins:
        Plugin從Struts1.1開始介紹,它定義了一個org.apache.struts.action.Plugin接口,它主要用來分配資源(allocating resources)或者建立數(shù)據(jù)庫的連結(jié)或者JNDI資源。這個接口提供了兩個必須實現(xiàn)的方法:init()和destroy()。如果運用了Plugin技術(shù),那么在容器啟動的時候,會調(diào)用Plugin的init()方法。所以將應(yīng)用系統(tǒng)的初始化信息寫在這里。當容器停止Struts應(yīng)用系統(tǒng)的時候,會調(diào)用destroy()方法,destroy()方法主要是用來收回在init()方法中分配的資源信息。
        ◆擴展Plugin類
         ① 創(chuàng)建一個實現(xiàn)Plugin接口的類
         ② 添加一個空的構(gòu)造器
         ③ 實現(xiàn)init()及destroy()兩個方法
         ④ 在struts-config.xml文件中對<plug-in />元素的配置
        創(chuàng)建Plugin必須繼承org.apache.struts.action.Plugin接口。并且實現(xiàn)init()及destroy()方法。例子:
        package wiley;

        import java.util.Properties;
        import java.io.File;
        import java.io.FileInputStream;
        import java.io.FileNotFoundException;
        import java.io.IOException;
        import javax.servlet.ServletException;
        import javax.servlet.ServletContext;
        import org.apache.struts.action.PlugIn;
        import org.apache.struts.config.ModuleConfig;
        import org.apache.struts.action.ActionServlet;

        public class WileyPlugin implements PlugIn {

        public static final String PROPERTIES = "PROPERTIES";

        public WileyPlugin() {}

        public void init(ActionServlet servlet,
         ModuleConfig config)
        throws javax.servlet.ServletException {
        System.err.println("....>The Plugin is starting<....");
        Properties properties = new Properties();
        String path = "C:\\ApplicationResources"+
        ".properties";
        try {
        // Build a file object referening the properties file
        // to be loaded
        File file = new File(path);
        // Create an input stream
        FileInputStream fis = new FileInputStream(file);
        // load the properties
        properties.load(fis);
        // Get a reference to the ServletContext
        ServletContext context = servlet.getServletContext();
        // Add the loaded properties to the ServletContext
        // for retrieval throughout the rest of the Application
        context.setAttribute(PROPERTIES, properties);
        }
        catch (FileNotFoundException fnfe) {
        throw new ServletException(fnfe.getMessage());
        }
        catch (IOException ioe) {
        throw new ServletException(ioe.getMessage());
        }
        }

        public void destroy() {
        // We don't have anything to clean up, so
        // just log the fact that the Plugin is shutting down
        System.err.println("....>The Plugin is stopping<....");
        }
        }
        ◆配置Plugin:
        在struts-config.xml文件中配置<plug-in>元素。如下:
        <plug-in className=”wiley.WileyPlugin” />
        <plug-in />的詳細配置信息見”struts-config.xml配置文件講解”。

        溫馨提示:喜歡本站的話,請收藏一下本站!

        本類教程下載

        系統(tǒng)下載排行

        主站蜘蛛池模板: 国产偷国产偷亚洲高清在线| 西西人体大胆免费视频| 99久久免费精品国产72精品九九| 亚洲永久网址在线观看| 亚洲一区二区三区免费| 中文字幕亚洲免费无线观看日本 | 免费一看一级毛片人| 免费人成激情视频在线观看冫| 亚洲精品在线网站| 免费一级做a爰片久久毛片潮喷| 在线观看人成视频免费无遮挡| 亚洲五月丁香综合视频| 久久精品亚洲乱码伦伦中文| 99re免费在线视频| 黄色三级三级三级免费看| 亚洲日产2021三区在线| 2048亚洲精品国产| 日韩视频在线精品视频免费观看| 免费又黄又爽又猛大片午夜| 亚洲黄色免费网址| 浮力影院亚洲国产第一页| 中文字幕人成无码免费视频| 91免费在线视频| 亚洲人成电影网站色| 亚洲成a人片77777老司机| 免费a级毛片大学生免费观看| 久久久久久夜精品精品免费啦| 在线观看亚洲视频| 亚洲午夜在线播放| 久久亚洲成a人片| 亚洲综合亚洲综合网成人| 嫩草视频在线免费观看| 亚洲视频在线免费观看| 一级毛片aa高清免费观看| 久久夜色精品国产噜噜亚洲a| 亚洲国产精品热久久| 国产日产亚洲系列最新| 日本免费v片一二三区| 成人免费一区二区无码视频| 最近最新高清免费中文字幕| 中文在线观看免费网站|