【问题标题】:Accessing static content in Jboss EAP 6.0在 Jboss EAP 6.0 中访问静态内容
【发布时间】:2014-01-21 15:05:47
【问题描述】:

我是新手,正在寻求一些关于使用符号链接访问 Jboss EAP 6.0 中的静态内容的指导。 在搜索过程中,我找到了 Jboss 5/6 的解决方案,但是我无法将它映射到我们拥有的 EAP 版本。

我们的应用服务器上有 1000 多个 PDF,用户可以通过 Web 应用程序访问它。 在 EAP 6.0 中,当在已部署的 ear/war 中创建符号链接时,无法从 Web 浏览器访问 PDF。

如果有人以前做过此操作或对如何在 EAP 中进行此操作有任何建议,请告诉我们。

感谢您的帮助。

【问题讨论】:

    标签: jboss7.x jboss-eap-6


    【解决方案1】:

    简答:创建一个 servlet,它知道从哪里获取这些文件并让它为它们提供服务。

    加长版/说明:

    创建一个 servlet,将其映射到例如/yourapp/pdfs/*:

    @WebServlet("/pdfs/*")
    public class PdfServlet extends HttpServlet
    {
        public void doGet(HttpServletRequest req, HttpServletResponse res) {
            String basePath = getServletContext().getInitParameter("basePath");
            File f = new File(basePath + File.separator + req.getPathInfo());
            /////////////////////////////////////////////////////////////////////
            ////  BIG WARNING:                                               ////
            ////  Normalize the path of the file and check if the user can   ////
            ////  legitimately access it, or you created a BIG security      ////
            ////  hole! If possible enhance it with system-level security,   ////
            ////  i.e. the user running the application server can access    ////
            ////  files only in the basePath and application server dirs.    ////
            /////////////////////////////////////////////////////////////////////
            if( f.exists() ) {
                OutputStream out = res.getOutputStream();
                // also set response headers for correct content type
                // or even cache headers, if you so desire
                byte[] buf = new byte[1024];
                int r;
                try( FileInputStream fis = new FileInputStream(f) ) {
                    while( (r=fis.read(buf)) >= 0 ) {
                        out.write(buf, 0, r);
                    }
                }
            }
            else res.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }
    

    上面的代码可能需要一些调整,但通常它概述了解决方案...

    现在在web.xml中指定上下文初始化参数:

    <context-param>
        <param-name>basePath</param-name>
        <param-value>/the/path/to/the/pdfs</param-value>
    </context-param>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-12
      • 2021-11-15
      • 2018-05-20
      • 1970-01-01
      • 2016-07-19
      • 2021-09-27
      • 2012-09-22
      相关资源
      最近更新 更多