Springmvc-multiple-resolver-mapping
提供:Dev Guides
Spring MVC-複数のリゾルバーマッピングの例
Spring MVCアプリケーションでMultiple View Resolverを使用する場合、orderプロパティを使用して優先順位を設定できます。 次の例は、Spring Web MVCフレームワークで ResourceBundleViewResolver および InternalResourceViewResolver を使用する方法を示しています。
TestWeb-servlet.xml
ここで、orderプロパティは、ビューリゾルバーのランキングを定義します。 この場合、0は最初のリゾルバであり、1は次のリゾルバなどです。
views.properties
たとえば、URIの場合、上記の構成を使用して-
- /helloが要求されると、DispatcherServletは、要求をviews.propertiesのbean helloで定義されたhello.jspに転送します。
まず、動作するEclipse IDEを用意し、Spring Web Frameworkを使用して動的フォームベースのWebアプリケーションを開発するための次の手順を検討します。
Step | Description |
---|---|
1 | Create a project with a name TestWeb under a package com.finddevguides as explained in the Spring MVC - Hello World chapter. |
2 | Create a Java class HelloController under the com.finddevguidespackage. |
3 | Create a view file hello.jsp under the jsp sub-folder. |
4 | Create a properties file views.properties under the SRC folder. |
5 | Download the JSTL library jstl.jar. Put it in your CLASSPATH. |
6 | The final step is to create the content of the source and configuration files and export the application as explained below. |
HelloController.java
TestWeb-servlet.xml
views.properties
hello.jsp
ソースファイルと構成ファイルの作成が完了したら、アプリケーションをエクスポートします。 アプリケーションを右クリックし、エクスポート→WARファイル*オプションを使用して、 *HelloWeb.war ファイルをTomcatのwebappsフォルダーに保存します。
次に、Tomcatサーバーを起動し、標準ブラウザーを使用してwebappsフォルダーから他のWebページにアクセスできることを確認します。 URLにアクセスしてみてください- http://localhost:8080/HelloWeb/hello 。SpringWebアプリケーションで問題がなければ、次の画面が表示されます。