Spring Mobile is a server side framework developed by the same team who was involved in the development of other Spring modules ( Spring Core , Spring MVC etc). Spring Mobile is also an extension over the conventional Spring MVC to facilitate the development of mobile web applications.
Spring Mobile tells you on the server side about the request source and then serve the content on the basis of incoming request source type (mobile/tablet/desktop).
At the core Spring Mobile presents following 3 features.
1. Device Resolver: Device resolver main responsibility is to find the source of the request whether it’s a mobile / tablet /desktop by analyzing the header information present in HTTP request. It plays an important role when we want to serve different type of contents for mobile and tablets. In addition to this device resolver also gives you the internal details of the device like its operating system , screen size , resolution etc. LiteDeviceResolver is the default implementation that Spring Mobile provides.
2. Site Preference Management: Once device type is resolved next thing that comes into the play to check whether user has set any preferences for its display. For an example consider you have developed an application that provides different interfaces for different device types , now if an user is accessing your application on a mobile device and he/she wants to switch to the other view e.g Desktop view because some of the features are not available in mobile version.
Site preference management allows the user to indicate if he or she prefers the mobile site or the normal site. The indicated site preference is saved for the user in a SitePreferenceRepository, and made available as a request attribute named ‘currentSitePreference’. In addition to this user preference is also stored in the client side cookie ,so that they can be remembered for future requests.It’s always a part of good design to give flexibility to your application users to choose the view type.
3. Site Switching: With site switching an application can be redirected to a different domain depending on the type of the source from where request is originated. Spring mobile provides static factory methods like mDot,dotMobi,urlPtah that can be used for site switching.
• mDot – mDot factory method constructs a site switcher that redirects all the request to m.$(originalUrl) , when request is originated from a mobile device.
e.g : lotusmediacentre.com will be redirected to m.lotusmediacentre.com
• dotMobi – dotMobi factor method constructs a site switcher that redirects all the request to $(originalUrl – domainextension).mobi , when request is originated from a mobile device.
e.g : lotusmediacentre.com will be redirected to lotusmediacentre.mobi
• standard – standard factory method constructs a site switcher that redirects all the request to a custom url pattern, when request is originated from a mobile or a tablet device.
e.g : lotusmediacentre.com will be redirected to mobile.lotusmediacentre.com and to tablet.lotusmediacentre.com when request is originated from a mobile and a tablet respectively.
• urlPath – urlPath factory method constructs to a site switcher that redirects all the request to a new context in your application , this context you have to define in your DispatcherServlet configuration.
e.g lotusmediacentre.com will be redirected to lotusmediacentre.com/m or lotusmediacentre.com/t when request has been originated from a mobile or a tablet respectively.
Latest posts by Saurabh Jain (see all)
- java.lang.IncompatibleClassChangeError: Found interface org.apache.hadoop.mapreduce.TaskInputOutputContext, but class was expected - August 8, 2014
- org.datanucleus.store.rdbms.exceptions.MappedDatastoreException: INSERT INTO “TABLE_PARAMS” – Hive with Kite Morphlines - July 17, 2014
- java.io.IOException: can not read class parquet.format.PageHeader: null – Hive - July 12, 2014