Springmvc-parameterizableviewcontroller
提供:Dev Guides
Spring MVC-パラメーター化可能なView Controllerの例
次の例は、Spring Web MVCフレームワークを使用してマルチアクションコントローラーのParameterizable View Controllerメソッドを使用する方法を示しています。 パラメータ化可能なビューでは、Webページをリクエストにマッピングできます。
たとえば、URIの場合、上記の構成を使用します。
/indexがリクエストされると、DispatcherServletはリクエストを *UserController コントローラに転送し、viewNameをuser.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 UserController under the com.finddevguides package. |
3 | Create a view file user.jsp under the jsp sub-folder. |
4 | The final step is to create the content of the source and configuration files and export the application as explained below. |
UserController.java
TestWeb-servlet.xml
user.jsp
ソースファイルと構成ファイルの作成が完了したら、アプリケーションをエクスポートします。 アプリケーションを右クリックし、[エクスポート]→[WARファイル]オプションを使用して、 TestWeb.war ファイルをTomcatのwebappsフォルダーに保存します。
次に、Tomcatサーバーを起動し、標準ブラウザーを使用してwebappsフォルダーから他のWebページにアクセスできることを確認します。 ここで、URL – http://localhost:8080/TestWeb/index を試してください。SpringWebアプリケーションで問題がなければ、次の画面が表示されます。