• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pass objects from one jsp to other  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I've a requirement, where I fetch data from table, display the info on jsp. On the first jsp, I should display only basic info and provide a link (against each row) to other jsp where complete info of that particular record is displayed. So, when I query the database, I have the complete info and it is returned to jsp. Now, how can I avail this info to next jsp.

Below is the piece of code where I iterate over the result set..



I want to pass the result object from my current jsp to next jsp.

Below is my complete jsp.


 
Rancher
Posts: 3348
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You pass the id for the row you want the details of in the second request.
Using that id your servlet can call your database service code to retrieve the correct instance, which can then be added to the request before it is forwarded to the JSP page.
 
santosh batta
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thank you for the response. I don't want to make a second db call. That is why, I got the entire result in the first request and got the response. Now, I have the complete response, but I need to pass the response (in my case, result object) to 2nd jsp.
 
Saloon Keeper
Posts: 1754
44
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

santosh batta wrote:... I don't want to make a second db call. That is why, I got the entire result in the first request and got the response. Now, I have the complete response, but I need to pass the response...


  • One of the ways you can "cache" this data is on the client side using javascript. The original request would contain the full data but it will show the user only a partial amount of data. Without refreshing the page, if a user clicks a drill down, the script can un-hide the hidden data. This is probably the best way to go without bothering the server again.
  • Another way is to use a cookie. The disadvantage is that sometimes cookies can be disabled by some users.
  • Another way is to have a session object. I would strongly suggest against this. A session object should contain stateful info about a session and not "cache" data. You would simple load your web server memory with unnecessary data if you do this.
  • The simplest way is by just keeping the id in the url as Dave suggested. A database fetch query will show the latest state of an object.
  •  
    santosh batta
    Ranch Hand
    Posts: 66
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you Francis. The data in the back end does not change so often. So, I would prefer the 1st option. Can you provide an example how to cache the server data client side using java script? Or can you suggest any reference where I can look for useful info on this topic? I'm very new to the front end development and client side scripting. Thanks in advance for all your help.
     
    Author and ninkuma
    Marshal
    Posts: 66484
    160
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    santosh batta wrote: I'm very new to the front end development and client side scripting.


    If you are new to front-end development then you should take the advice of people that have been doing this for a long time. The correct approach is to not fetch any data you don't need on the first request, and to follow the advice to fetch the info from the database on the second request.

    Trying to front-end cache the data between requests is a kludge at best, and fraught with possible problems.

    If you are worried about the extra DB call, you are likely succumbing to premature optimization which is a very bad thing to give in to.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!