1

プレーンな html ページを操作するために、Spring MVC を REST で構成する方法を見つけようとしています。私がこのようにしたい理由は、html と javascript と共に phone gap を使用して Android または ios アプリケーションを作成したいからです。

これにより、ブラウザーとモバイル アプリケーションの両方をサポートするためのメンテナンスとプログラミングを減らすことができます。これまでのところ、Eclipse の spring mvc テンプレートから作成された基本的なサンプル プロジェクトから始めました。ビューが jsp 形式の場合は問題なく動作しますが、ビューを .html に変更し、接尾辞も html に変更すると、ページが見つかりません。

2 番目の質問です。私が見たすべての例から、それらはすべて .jsp ファイルのみを使用しています。jsf のように xhtml に置き換えることはできますか?

テストされたサンプルコード

/**
 * Handles requests for the application home page.
 */
@Controller
@RequestMapping("/wb")
public class HomeController {

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    /**
     * Simply selects the home view to render by returning its name.
     */

        @RequestMapping("/create/")
        public String home(Device device, Model model) {
            if (device == null) {
                logger.info("no device detected");
            } else if (device.isNormal()) {
                logger.info("Device is normal");
            } else if (device.isMobile()) {
                logger.info("Device is mobile");
            } else if (device.isTablet()) {
                logger.info("Device is tablet");
            }
            return "home";
        }
}

Bean の構成

<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
        <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven>
        <argument-resolvers>
            <beans:bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
        </argument-resolvers>
    </annotation-driven>

        <!-- Use the DeviceResolverHandlerInterceptor OR the DeviceResolverRequestFilter in the web.xml -->
    <interceptors>
        <!-- On pre-handle, resolve the device that originated the web request -->
       <beans:bean class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor" />
    </interceptors>
    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".html" />
    </beans:bean>

    <context:component-scan base-package="com.veera.myapp" />



</beans:beans>

.html 使用時のログ

INFO : com.veera.myapp.HomeController - Device is normal
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/myapp-1.0.0-BUILD-SNAPSHOT/WEB-INF/views/home.html] in DispatcherServlet with name 'appServlet'

.html の代わりに .jsp を使用すると、機能します。ここに画像の説明を入力

4

0 に答える 0