Spring 移动重定向 404 错误
Spring mobile redirect 404 error
我正在构建具有不同布局的网站的移动版本。我正在使用 Spring 手机+Thymeleaf。出于测试目的,我从主站点重定向到移动版本。这是我的 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<display-name>Student Accounting site</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>studentacc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>studentacc</servlet-name>
<url-pattern>/</url-pattern>
<url-pattern>/m/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>deviceResolverRequestFilter</filter-name>
<filter-class>org.springframework.mobile.device.DeviceResolverRequestFilter</filter-class>
</filter>
</webapp>
这是我的 servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<context:annotation-config/>
<context:component-scan base-package="org.something.webversion"/>
<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>
<!--Thymeleaf beans init:START-->
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".html"/>
<property name="templateMode" value="HTML5"/>
<property name="characterEncoding" value="UTF-8"/>
</bean>
<bean id="templateEngine"
class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver"/>
<property name="additionalDialects">
<set>
<bean class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect"/>
</set>
</property>
</bean>
<!--Thymeleaf beans init:END-->
<!--Other beans init:START-->
<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" />
</bean>
</mvc:interceptors>
<bean id="liteDeviceDelegatingViewResolver" class="org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver">
<constructor-arg>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine"/>
<property name="characterEncoding" value="UTF-8"/>
</bean>
</constructor-arg>
<property name="mobilePrefix" value="mobile/" />
<property name="enableFallback" value="true" />
</bean>
<!--Other beans init:END-->
<mvc:resources mapping="/resources/*" location="resources/"/>
</beans>
矿场管理员:
public class MainController {
private static final Logger logger = Logger.getLogger(MainController.class.getName());
@RequestMapping(value = "/")
public String HelloWorld(Model model,Device device){
logger.info("Device is "+device);
if(device.isNormal()){
return "hello";
}
return "index";
}
}
我的 webapp 文件夹如下所示:
网络信息---
|
页数---
|
移动的 - -
|
index.html
所以,重定向工作正常,我正在重定向到移动版本。但是我重定向到的页面不存在(404)。我只是看不到错误。提前谢谢你。
"rotate" 重定向到 url 到 sitename:8080/studentacc/m" 因为很可能 "studentacc" 是你在应用程序中的应用程序名称服务器,因此它必须是第一部分。
从对 API 的非常简短的了解中,我会尝试将 SiteSwitcherHandlerInterceptor.urlPath(String mobilePath, String rootPath)
方法与 rootPath
的附加参数一起使用
<bean class="org.springframework.mobile.device.switcher.SiteSwitcherHandlerInterceptor" factory-method="urlPath">
<constructor-arg value="/m" />
<constructor-arg value="/studentacc" />
</bean>
我正在构建具有不同布局的网站的移动版本。我正在使用 Spring 手机+Thymeleaf。出于测试目的,我从主站点重定向到移动版本。这是我的 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<display-name>Student Accounting site</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>studentacc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>studentacc</servlet-name>
<url-pattern>/</url-pattern>
<url-pattern>/m/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>deviceResolverRequestFilter</filter-name>
<filter-class>org.springframework.mobile.device.DeviceResolverRequestFilter</filter-class>
</filter>
</webapp>
这是我的 servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<context:annotation-config/>
<context:component-scan base-package="org.something.webversion"/>
<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>
<!--Thymeleaf beans init:START-->
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".html"/>
<property name="templateMode" value="HTML5"/>
<property name="characterEncoding" value="UTF-8"/>
</bean>
<bean id="templateEngine"
class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver"/>
<property name="additionalDialects">
<set>
<bean class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect"/>
</set>
</property>
</bean>
<!--Thymeleaf beans init:END-->
<!--Other beans init:START-->
<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" />
</bean>
</mvc:interceptors>
<bean id="liteDeviceDelegatingViewResolver" class="org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver">
<constructor-arg>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine"/>
<property name="characterEncoding" value="UTF-8"/>
</bean>
</constructor-arg>
<property name="mobilePrefix" value="mobile/" />
<property name="enableFallback" value="true" />
</bean>
<!--Other beans init:END-->
<mvc:resources mapping="/resources/*" location="resources/"/>
</beans>
矿场管理员:
public class MainController {
private static final Logger logger = Logger.getLogger(MainController.class.getName());
@RequestMapping(value = "/")
public String HelloWorld(Model model,Device device){
logger.info("Device is "+device);
if(device.isNormal()){
return "hello";
}
return "index";
}
}
我的 webapp 文件夹如下所示: 网络信息--- | 页数--- | 移动的 - - | index.html
所以,重定向工作正常,我正在重定向到移动版本。但是我重定向到的页面不存在(404)。我只是看不到错误。提前谢谢你。
"rotate" 重定向到 url 到 sitename:8080/studentacc/m" 因为很可能 "studentacc" 是你在应用程序中的应用程序名称服务器,因此它必须是第一部分。
从对 API 的非常简短的了解中,我会尝试将 SiteSwitcherHandlerInterceptor.urlPath(String mobilePath, String rootPath)
方法与 rootPath
<bean class="org.springframework.mobile.device.switcher.SiteSwitcherHandlerInterceptor" factory-method="urlPath">
<constructor-arg value="/m" />
<constructor-arg value="/studentacc" />
</bean>