【问题标题】:Using web sphere server, Can we update and read file from the deployed .war/.ear/. files?使用 Web Sphere 服务器,我们可以从部署的 .war/.ear/ 中更新和读取文件吗?文件?
【发布时间】:2018-12-06 00:19:27
【问题描述】:

这是我本地的结构(部署前):

使用以下路径访问 key.doc 文件

String filePath = getServlet().getServletContext().getRealPath("/") + "\\FORM22-INDIA";

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

ks.load(new FileInputStream(filePath + "\\key.doc"), PASSWORD);

但在部署之后,在访问 key.doc 文件时出现 File Not Found 异常。

【问题讨论】:

    标签: java servlets deployment websphere digital-signature


    【解决方案1】:

    要访问 Web 应用程序资源,您可以使用 ServletContext.getResourceAsStream() API。

    代码:

    InputStream st= getServletContext().getResourceAsStream("/FORM22-INDIA/key.doc");
    

    此外,将文件(您打算更新的文件)保存在您的 WAR 或 EAR 中并不是一个好主意,因为您的更改将在您重新部署应用程序后立即丢失。

    【讨论】:

    • 假设我要更新上面目录下的Form22.pdf,.EAR文件允许更新吗??
    • 使用 getResourceStream,得到 null(代替 FileNotFound 异常)。获取 [java.lang.IllegalStateException: SRVE0199E: OutputStream 已经获得
    • 它可以工作,但我们必须放在 WEB-INF 文件夹中。
    • 很抱歉无法回复您的评论。很高兴听到它对你有用。编码愉快。
    猜你喜欢
    • 1970-01-01
    • 2010-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2012-10-29
    相关资源
    最近更新 更多