欧美特黄不卡,涩涩视频在线,成人国产精品一区二区网站,亚洲一区二区三区欧美

當(dāng)前位置:雨林木風(fēng)下載站 > 技術(shù)開(kāi)發(fā)教程 > 詳細(xì)頁(yè)面

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

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

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

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

溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!

本類教程下載

系統(tǒng)下載排行

主站蜘蛛池模板: 铜川市| 大安市| 弥渡县| 吉隆县| 肇州县| 灵武市| 措勤县| 高雄县| 库车县| 竹溪县| 汉中市| 江津市| 咸宁市| 洛阳市| 沂水县| 抚远县| 防城港市| 通道| 泽普县| 肇东市| 朝阳区| 黄梅县| 岗巴县| 兰州市| 阜城县| 巩义市| 奇台县| 姚安县| 若尔盖县| 宁陕县| 广平县| 枣强县| 石嘴山市| 铁力市| 河曲县| 靖远县| 苍溪县| 临湘市| 马山县| 巨鹿县| 道孚县|