1

私は初心者であり、シンボリック リンクを使用して Jboss EAP 6.0 の静的コンテンツにアクセスするためのガイダンスを求めています。検索中に Jboss 5/6 の解決策を見つけましたが、それを私たちが持っている EAP バージョンにマップすることができませんでした。

アプリ サーバーには 1000 以上の PDF があり、ユーザーは Web アプリケーションを介してアクセスします。EAP 6.0 では、デプロイされた ear/war 内にシンボリック リンクを作成すると、Web ブラウザから PDF にアクセスできません。

誰かが以前にこれを行ったことがある場合、または EAP での方法について提案がある場合は、お知らせください。

あなたの助けに感謝。

4

1 に答える 1

0

簡単な答え:これらのファイルをどこから取得するかを知っているサーブレットを作成し、それを提供させます。

より長いバージョン/説明:

サーブレットを作成し、次のようにマップします/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);
    }
}

上記のコードは微調整されている可能性がありますが、一般的には解決策の概要を説明しています...

で context init パラメータを指定しますweb.xml

<context-param>
    <param-name>basePath</param-name>
    <param-value>/the/path/to/the/pdfs</param-value>
</context-param>
于 2014-01-22T16:00:41.017 に答える