Announcement Announcement Module
Collapse
No announcement yet.
Problem with Spring MVC (Servlets) and Single-Page Applications Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with Spring MVC (Servlets) and Single-Page Applications

    I am developing Single-Page Application. Browser bar URLs are representing an internal state in the application that can be shared or bookmarked.

    To achieve this, I use hasher.js, which routes deep urls to the browser's # anchor. For example: http://www.example.com/myview#myparam=myvalue

    This is all working well, until some server side code needs to relate to that data (myparam=myvalue). The problem is that Spring MVC (and possibly Servlets in general) does not relate to anything that comes after # in the url. In fact, it possibly does not even aware that the anchor exists. This results in reloading a hashed url, but not getting the expected behavior from the server side.

    Has anyone encountered this issue before? Any ideas how to resolve this without letting go of the SPA architecture?

    Is it possible to change browser URL outside the hash part (i.e url query string) without reloading the page?

    Yuval

  • #2
    As you already noticed the hash is just an anchor nothing more nothing less and as such it isn't interpreted as variables it isn't even part of the query string. Not sure if the part after the hash is even send to the server (if it is you could probably create a Filter which wraps the request so that the # is also parsed as/for parameters).

    Comment


    • #3
      Thanks Marten, indeed the #anchor is not sent to the server, which is why I switched to another framework, history.js, which supports history without hashing it in #. Of course, this is still a problem for older browsers such as IE7-8, but at least it solves the problem for most browsers that supports HTML5.

      Comment

      Working...
      X