如何将spring-mobile-device拦截器应用于welcome-file?

时间:2014-08-23 14:07:31

标签: spring spring-mvc spring-mobile

我使用SpringMVC,我对每种设备类型Desktop / Tablet / Mobile都有不同的设计

<!-- START of MOBILE -->
<mvc:annotation-driven>
    <mvc:argument-resolvers>
        <bean
            class="org.springframework.mobile.device.site.SitePreferenceWebArgumentResolver" />
        <bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
    </mvc:argument-resolvers>
</mvc:annotation-driven>
<mvc:interceptors>
    <!-- Resolve the device which has generated the request -->
    <bean
        class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor" />
    <!-- User's site preference -->
    <bean
        class="org.springframework.mobile.device.site.SitePreferenceHandlerInterceptor" />
    <!-- Redirects users to the device specific site -->
    <bean
        class="org.springframework.mobile.device.switcher.SiteSwitcherHandlerInterceptor"
        factory-method="urlPath">
        <constructor-arg value="/m" />
        <constructor-arg value="/t" />
        <constructor-arg value="/" />
    </bean>
</mvc:interceptors>
<!-- Device aware view resolving -->
<bean id="liteDeviceDelegatingViewResolver"
    class="org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver">
    <constructor-arg>
        <bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/views/" />
            <property name="suffix" value=".jsp" />
        </bean>
    </constructor-arg>
    <property name="mobilePrefix" value="m/" />
    <property name="tabletPrefix" value="t/" />
    <property name="normalPrefix" value="/" />
    <property name="enableFallback" value="true" />
</bean>
<!-- END of MOBILE -->

我在每个设备的/ WEB-INF / views /文件夹中都有/ m / t和/ folders视图,并且一切正常,但此配置不仅适用于欢迎页面,即我打开带有电话的页面并查看桌面 - login.jsp的版本(/WEB_INF/views/login.jsp但不是/WEB-INF/views/m/login.jsp)

<welcome-file-list>
    <welcome-file>/WEB-INF/views/login.jsp</welcome-file>
</welcome-file-list>

我需要做些什么来改变它来修复它。

1 个答案:

答案 0 :(得分:1)

只是不要指定页面...并通过控制器处理'home'请求:)

将您的web.xml修改为:

<welcome-file-list>
    <welcome-file></welcome-file>
</welcome-file-list>

或只删除标记

现在,您的HomeController应如下所示:

@Controller
public class HomeController {

@RequestMapping("/")
public String home(SitePreference sitePreference, Model model) {
    return "login";

    }
}
希望这会有所帮助。