Question

I have two pages, say A and B. User navigates from Page-A to Page-B. Page-B needs to have some values which are passed from the Page-A. Among these values some of them are Objects. Now I have the following ways to pass the parameter to Page-B

  • Store the Objects in some Scope (say Session, Page-Flow).
  • Pass the Objects as query string after converting them into String.

The drawbacks of the above two ways are followings respectively:

  • If User bookmarks the Page-B for later usage and try to access it from different session, it generates Exception. As the Objects are not present in the scope.
  • There are limitations of the length of the URL, which is 2048 Character (ref). So if I convert it to JSON and try to pass it through URL and if the JSON String is more than the limited characters, I would get JSON Exception from Page-B.

Can I compress the String representation of the Object so that it will not exceed the limitation Character?

How can I solve this issue (by any other means)?

Any solution is greatly appreciated.

Was it helpful?

Solution

Putting serialized objects in the URL is a really bad idea. If you want to access state via URL (GET parameters) then normally the URL should only contain some way of identifying the item in question.

Fortunately if you're using a database back end to persist your objects then the database will usually give them an identity for you, in the form of a primary key. You can then just put the ID in the URL and have Java retrieve the object for that ID whenever it receives a request for it.

If you don't use a database back end then it's up to you to give your objects an identity that they can be located by. The simplest solution would be to store references to the objects in a map and put the map key in the URL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top