1

Right now we are working on a project that will have a desktop and a mobile version of the site, created in Spring. We want the mobile and the desktop version to share the same Spring security system etc.

We are using Spring mobile to detect whether or not the device is mobile, and may possibly use the Spring site preference parameter.

We dont want to use the spring mobile redirector, as this appears to redirect to another domain (eg m.website.com), and would not use the same spring security easily.

So I am thinkin gof using a HandlerInterceptor to redirect to a specfic directory within the site - eg "/jsp/mobile/".

1) Is it possible in this extended HandlerInterceptor to use the Spring Mobile device detector in the preHandle method?

2) What is the best way to redirect? Is it a) to just use the http response, or b) to somehow change the viewResolver and change the prefix from "/jsp/" to "/jsp/mobile/"

Sorry for the long winded question, but I hoped to put as much info in as possible about what we are trying to do!

Cheers

Davos555
  • 1,974
  • 15
  • 23

2 Answers2

1

I am currently using a HandlerInterceptor in the pre handler method makes the assessment of whether or not the application is a mobile device, if coming from a mobile device, through the method requestUri get current address and places as prefix "m" after the name of the application context. Then do a redirect:

response.sendRedirect("/application/m/.....") ( documentation )

Example

/application/user           //recived
/application/m/user         //sent

The problem is that this interceptor intercepts all requests, therefore it is necessary to assess the following:

  1. if the request comes with a path like "/application/m/....." not verify that comes from a mobile device, because the "m" and says it does me

  2. if you let spring handle static resources, the interceptor must not redirect if the requests come from a mobile device (the mobile version and the normal share these resources)

Jhonathan
  • 1,611
  • 2
  • 13
  • 24
1

Thanks for the answer. What I did is use a HandlerInterceptor and changed the view name in the post handle method like so:

if (modelAndView.getViewName() != null)
{
    modelAndView.setViewName("/mobile/" + modelAndView.getViewName());
}
else
{
    modelAndView.setViewName("/mobile/");
}

Plus that is wrapped in an if else agains whether the device is mobile or not, by injecting DeviceResolver into the constructor and then resolving the local device.

Davos555
  • 1,974
  • 15
  • 23