0

私は、それぞれにRMIアプリケーションを実行している多くの本番サーバーと、さらに4つのJava Webアプリケーションを持っています。

Server A:
RMI app by JNLP file;
webapp_1 (connected by RMI with local RMI app);
webapp_2 (connected by RMI with local RMI app);
webapp_3 (connected by RMI with local RMI app);
webapp_4 (connected by RMI with local RMI app);

Server B:
...the same..OK

すべてのユーザーは、このサーバーに 8080 ポート (Jetty に直接) で直接アクセスします。たとえば、「main-area」などの既定のコンテキストで、すべてのアプリ (RMI アプリ、webapp_1、webapp_2 など) の一部の html リンクでアクセスできます。

一部のユーザーが「/」ページにアクセスすると、たとえば次のようになります。

www.foo.com:8080/

main-area/
webapp_1/
webapp_2/
webapp_3/
...

Jetty はすべてのアプリケーションのリストを返します (Apache のディレクトリ リストと同様)。

それをブロックするか、「メインエリア」コンテキストにリダイレクトする方法はありますか?

4

3 に答える 3

4

一致しない webapp コンテキストのリストは"/"、の責任の一部として提示されます。org.eclipse.jetty.server.handler.DefaultHandler

DefaultHandlerデフォルトで有効になっており、サーブレット仕様への準拠を維持しています。

DefaultHandler の無効化:

DefaultHandler によって情報が提示されない単純な 404 が必要な場合は、${jetty.home}/etc/jetty.xml

<!-- =========================================================== -->
<!-- Set handler Collection Structure                            --> 
<!-- =========================================================== -->
<Set name="handler">
  <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
    <Set name="handlers">
     <Array type="org.eclipse.jetty.server.Handler">
       <Item>
         <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
       </Item>
       <!-- Disable the DefaultHandler to avoid listing of non-matching contexts
       <Item>
         <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
       </Item>
        -->
     </Array>
    </Set>
  </New>
</Set>

"/"(ROOT) コンテキストの静的コンテンツの表示:

"/"ルート コンテキスト(ROOT) に別のものを表示させたい場合は、${jetty.home}/webapps/ROOTディレクトリを作成し、そこに index.html ファイルを配置します。

[jetty-distribution-7.6.13.v20130916]$ cat webapps/ROOT/index.html 
<h1>This is ROOT</h1>

これにより、必要なコンテンツ、画像、css などを配置できる静的コンテンツ webapp がデプロイされます。

"/"別のパスへの自動リダイレクト(ROOT):

${jetty.home}/webapps/ROOT注: これは、上記のオプション、このオプション、またはそのオプションと同時には機能しませんが、両方では機能しません。

Jetty を"/"別の URL に自動的にリダイレクトする場合は、書き換えハンドラーを使用します。

書き換えオプションが有効になっていることを確認し、一連の書き換えルール xml を含めます。

[jetty-distribution-7.6.13.v20130916]$ grep rewrite start.ini 
OPTIONS=Server,jsp,jmx,resources,websocket,ext,rewrite
etc/jetty-rewrite.xml

次に、書き換えルールを定義します...

からへの${jetty.home}/etc/jetty-rewrite.xmlアクセスをリダイレクトするの内容"/""/test/"

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
                   "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <Get id="oldhandler" name="handler"/>

    <Set name="handler">
     <New id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
      <Set name="handler"><Ref id="oldhandler"/></Set>
      <Set name="rewriteRequestURI">true</Set>
      <Set name="rewritePathInfo">false</Set>
      <Set name="originalPathAttribute">requestedPath</Set>

      <!-- redirect from the welcome page to a specific page -->
      <Call name="addRule">
        <Arg>
          <New class="org.eclipse.jetty.rewrite.handler.RedirectRegexRule">
            <Set name="regex">^/$</Set>
            <Set name="replacement">/test/</Set>
          </New>
        </Arg>
      </Call>
     </New>
    </Set>
</Configure>
于 2013-10-16T18:39:28.297 に答える
3

その場所の index.html ファイルを作成します。

これは提供されるため、リストを生成する必要はありません。

次に、ブラウザがリダイレクトを尊重しない場合は、通常のリンクとともに、単純なリダイレクトをそこに配置できます。

于 2013-10-16T14:39:49.853 に答える
0

Thorbjørn Ravn Andersenの解決策に感謝:

内部に JSP HTML/JS リダイレクトを含む単一の index.jsp を使用して、基本的な動的 Web アプリケーションを作成しました。

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="refresh" content="1;url=bar/index.jsp">
        <script type="text/javascript">
            window.location.href = "bar/index.jsp"
        </script>
        <title>Page Redirection</title>
    </head>
    <body>
        If you are not redirected automatically, follow the <a href='bar/index.jsp'>main area</a>
    </body>
</html>

「ROOT.war」としてデプロイし、「...jetty/contexts/」で「root.xml」を次のように構成しました。

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/</Set>
  <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/ROOT.war</Set>
</Configure>
于 2013-10-16T15:10:05.877 に答える