日本国产亚洲-日本国产一区-日本国产一区二区三区-日本韩国欧美一区-日本韩国欧美在线-日本韩国欧美在线观看

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

半翻譯半整理的一些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配置文件講解”。

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

本類教程下載

系統下載排行

主站蜘蛛池模板: 国产成人91高清精品免费 | 视频日韩p影院永久免费 | 黄视频免费网站 | 狠狠操人人干 | 韩国毛片在线观看 | 1204你懂的免费国产 | 免费看的黄视频 | 亚洲国产精品一区二区第四页 | 亚洲久久久久久久 | 91精品国产91久久 | 久久撸视频 | 天天天天天操 | 日本韩国一级 | 色噜噜国产在线91蝌蚪 | 精品三级国产 | a在线视频 | 加勒比亚洲精品久久久久久久久久 | 国产精品自在自线亚洲 | 日本久久精品视频 | 国产精品视频福利一区二区 | 成人免费午夜性视频 | 四虎永久精品免费观看 | 草视频在线观看 | 野花日本中文版免费观看 | 2018天天干天天射 | 狠狠色噜噜狠狠狠狠色吗综合 | 久久久久久噜噜噜久久久精品 | 国产欧美在线观看 | 国产年轻大学生情侣在线 | 996热精品视频在线观看 | 精品手机在线 | 久久美乳 | 亚洲精品乱码久久久久久 | 久久婷婷综合中文字幕 | 99国产欧美久久精品 | 亚洲综合二区 | 精品热久国产福利视频 | 国产三级在线观看专区 | 久久精品94精品久久精品动漫 | 19xxxxxxxxx日本69 1本2本3本不卡视频 | 国产三级网站在线观看播放 |