久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Tomcat:通過 JNDI 使用 FTP 連接

Tomcat: use FTP connection via JNDI(Tomcat:通過 JNDI 使用 FTP 連接)
本文介紹了Tomcat:通過 JNDI 使用 FTP 連接的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要從運行在 Tomcat 6 上的 Web 應用程序訪問 FTP 服務器.我想使用 JNDI 來執行此操作.

I need to access an FTP server from my Web Application which runs on Tomcat 6. I want to use JNDI to do this.

如何使用 JNDI 在 Tomcat 中配置此 FTP 連接?我必須在 web.xmlcontext.xml 中寫入什么來配置資源?然后如何從 Java 源代碼訪問此連接?

How can I configure this FTP connection in Tomcat using JNDI? What do I have to write into web.xml and context.xml to configure the resource? And how can I then access this connection from the Java source code?

推薦答案

來自這篇文章:http://codelevain.wordpress.com/2010/12/18/url-as-jndi-resource/

在您的 context.xml 中定義您的 FTP URL,如下所示:

Define your FTP URL in your context.xml like this :

 <Resource name="url/SomeService" auth="Container"
 type="java.net.URL"
 factory="com.mycompany.common.URLFactory"
 url="ftp://ftpserver/folder" />

提供 com.mycompany.common.URLFactory 實現并確保生成的類可用于 Tomcat:

Provide the com.mycompany.common.URLFactory implementation and make sure the resulting class is available to Tomcat :

import java.net.URL;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.spi.ObjectFactory;

public class URLFactory implements ObjectFactory {
 public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
 Reference ref = (Reference) obj;
 String urlString =  (String) ref.get("url").getContent();
 return new URL(urlString);
 }
}

在 web.xml 中創建您的參考

Create your reference in web.xml

<resource-ref>
 <res-ref-name>
   url/SomeService
 </res-ref-name>
 <res-type>
   java.net.URL
 </res-type>
 <res-auth>
   Container
 </res-auth>
</resource-ref>

然后在您的代碼中通過 JNDI 查找獲取 FTP URL:

Then in your code obtain the FTP URL by doing a JNDI lookup:

InitialContext context = new InitialContext();
URL url = (URL) context.lookup("java:comp/env/url/SomeService");

這篇關于Tomcat:通過 JNDI 使用 FTP 連接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 久久av一区二区三区 | 精品一区二区三区在线观看国产 | 毛片av免费看 | 欧美日韩福利视频 | 91不卡在线| 日韩久久久久久 | 欧美黄色免费网站 | 精品欧美一区二区三区精品久久 | 成人午夜影院 | 欧美在线视频一区 | 成人精品视频99在线观看免费 | 美女一级毛片 | 成人性视频免费网站 | 久久成人一区 | 一区二区三区欧美在线 | 91久久久久久久久久久久久 | 国产精品日韩 | 天堂网avav| 免费在线成人网 | 国产在线二区 | 久久久tv| 欧洲毛片| 成人性生交大片免费看r链接 | 午夜91| 国产精品激情小视频 | 九九亚洲| 久久久黄色 | 成人三级电影 | 欧美人人| 伊色综合久久之综合久久 | 亚洲精品1 | 日本久久综合 | 久久久国产一区 | 日本涩涩视频 | 亚洲福利 | 成人免费视频在线观看 | 日韩精品久久久 | 韩国欧洲一级毛片 | 欧美日韩一 | 日韩在线中文 | 亚洲精品456|