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

        當前位置:雨林木風下載站 > 技術開發教程 > 詳細頁面

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

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

        更新時間:2021-11-16 文章作者:未知 信息來源:網絡 閱讀次數:

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

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

        本類教程下載

        系統下載排行

        主站蜘蛛池模板: 亚洲视频在线一区二区三区| 亚洲gv猛男gv无码男同短文| 中文字幕亚洲男人的天堂网络| 男人j进入女人j内部免费网站| 亚洲人色婷婷成人网站在线观看 | 老司机免费午夜精品视频| 久久久久国色AV免费观看性色| 亚洲国产精品一区二区久| 91免费资源网站入口| 亚洲综合激情五月色一区| 国产精品免费小视频| 日韩免费在线中文字幕| 亚洲色大成网站WWW久久九九| A片在线免费观看| 亚洲日产2021三区| 丁香花在线观看免费观看| www亚洲精品久久久乳| 免费在线观看黄色毛片| 成av免费大片黄在线观看| 亚洲av日韩av不卡在线观看| 国产成人免费午夜在线观看| 2020亚洲男人天堂精品| 全部免费国产潢色一级| 中文在线观看国语高清免费| 亚洲视频免费在线观看| 成人免费在线视频| 国产99久久久久久免费看| 亚洲狠狠综合久久| 色妞WWW精品免费视频| 九九免费观看全部免费视频| 亚洲av福利无码无一区二区 | 亚洲国产精品成人网址天堂 | 二个人看的www免费视频| 精品日韩亚洲AV无码| 我要看免费的毛片| 9久热这里只有精品免费| 亚洲资源最新版在线观看| 国产又大又黑又粗免费视频| 美女视频黄a视频全免费网站色窝| 亚洲最大福利视频| 亚洲日韩激情无码一区|