I'm writing a simple web application, using tomcat server, servlets and jsp pages. Ideally, I would like my website to be only one page into which I load content (jsp files) on user actions.
However it is also important that users will be able to "bookmark" certain urls to get straight to the content they need to get to.
For example, lets say I have a page that details all of the registered users of my site and then each user has a profile page. I want that users who navigate to someones profile will see the following url:
and that when they enter this url they will get to the profile of some_user_name.
The problem is that all of the content was generated using ajax, and I manually changed the urls displayed using history.pushState - so that when you enter the example url you simply get 404 page.
A simple solution I had in mind was to have a servlet mapped to the /users/* pattern which responds with the correct jsp page. Is this is a reasonable solution or there are other better and acceptable ways to handle this kind of a problem?
preguntado el 24 de agosto de 12 a las 00:08
If you are managing history using pushState then when the application is accessed directly through the url you can take the url fragment and make an ajax call and load the content. In order to achieve this all your urls must be rest compliant so it will be easy to load proper view in your case it can be something like this
So now when the app is loaded you can load perfiles view with user name some_user_name
if you want some other view like edit then it can be
you should implement a router which can route these urls properly and also an main method which can fetch data from server and pass it on to view.
if you can use your JSP code as a rest webservice this can be achieved easily and also there are lot of libraries which support things like this. you might want to look into Backbone.js /Knockout.js
aquí is the list of popular frameworks with comparisons.
But the issue you might face is SEO. there are some workarounds for this aswell.