0

/ {servlet} / historyをサポートする必要があり、これをサポートする必要のあるサーブレットがたくさんあります。私はTomcat、FWIWを使用しています。

以下は機能しますが、すべてのパターンを1行にまとめて、履歴パターンをサポートする必要のあるすべてのサーブレットにurl-patternを追加しないようにする方法があるかどうか疑問に思っています。私はいくつかのオプションを試しましたが失敗しました。

<servlet>
    <servlet-name>History</servlet-name>
    <servlet-class>com.foo.HistoryServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>History</servlet-name>
    <url-pattern>/aDifferentServlet/history/*</url-pattern>
    <url-pattern>/someOtherOne/history/*</url-pattern>
    <url-pattern>/anotherExample/history/*</url-pattern>
</servlet-mapping>
...
<servlet>
    <servlet-name>aDifferentServlet</servlet-name>
    <servlet-class>com.foo.aDifferentServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>aDifferentServlet</servlet-name>
    <url-pattern>/aDifferentServlet/*</url-pattern>
</servlet-mapping>
...

ありがとう。

4

2 に答える 2

3

/history/*URLパターンを1つだけにするためには、のような一般的なプレフィックス(フォルダ)パターンまたはのようなサフィックス(拡張)パターンを指定する必要があります*.history。のように両側でワイルドカードが一致するURLパターンを持つことはできません*/history/*。最善の策は、履歴サーブレットをマッピングし/history/*、それに応じてURLを変更することです/history/aDifferentServlet(この部分はrequest.getPathInfo()、履歴サーブレットで利用できます)。

URLの変更が望ましくない場合は、リクエストURIがパターンFilterに一致するたびに、履歴サーブレットに転送するサーブレットを作成または書き換える必要があります。*/history/*

于 2012-01-27T16:55:47.320 に答える
0

パターンは、アスタリスクで終了することも、アスタリスクで開始することもできます(ファイル拡張子のマッピングを示すため)。

詳細情報:

http://javapapers.com/servlet/what-is-servlet-mapping/#&slider1=1

The url-pattern specification:

        *A string beginning with a ‘/’ character and ending with a ‘/*’ 
        suffix is used for path mapping.
        *A string beginning with a ‘*.’ prefix is used as an extension mapping.
        *A string containing only the ’/’ character indicates the "default" 
        servlet of the application. In this case the 
        servlet path is the request URI minus the context path and the path 
        info is null.
        *All other strings are used for exact matches only.
于 2012-01-27T16:06:19.210 に答える