Results 1 to 3 of 3
  1. #1
    Msnforum is offline Member
    Join Date
    Sep 2008
    Posts
    7
    Rep Power
    0

    Default JSP session query on page load

    How would one go about loading user content based on "user id" stored in a session attribute?

    I need to load jsp pages that uses database query using "user id" during page load. Correct me if you think there are ways to use servlet to execute session query to database without adding a request attribute when forwarding to jsp page.


    E.g. Calling books.jsp when user is logged in creates multiple database queries(create bean to use for page) based on session attribute data that then displays data on the jsp page.

    I hope this is not too hard to understand.

  2. #2
    anthrax is offline Member
    Join Date
    Feb 2009
    Posts
    57
    Rep Power
    0

    Default

    in your jsp page u can display user content based on stored attribute by 1st setting an attribute like "user_id" somewhere in your program, i usually do it in servlet like
    request.getSession.setAttribute("user_id", string_user_id);
    then use RequestDispatcher to forward to jsp page. to display the content on jsp page use this
    <%= request.getSession.getAttribute("user_id") %>
    if you have many data u can research JSTL to load data from your bean

  3. #3
    Msnforum is offline Member
    Join Date
    Sep 2008
    Posts
    7
    Rep Power
    0

    Default

    Not quite the thing I was looking for because I need to create a bean based on user_id when the jsp page loads.

    I wonder if this approach will work: Load jsp page, if session is available, use RequestDispatcher to forward to servlet with hidden field to create bean and back again to the jsp page to useBean that is created.
    Last edited by Msnforum; 03-21-2010 at 11:01 PM.

Similar Threads

  1. Go back to previous page using session in JSP page
    By gopikarikati009 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-23-2011, 11:30 AM
  2. How to load collection to JSP Page ?
    By tking88 in forum Advanced Java
    Replies: 0
    Last Post: 03-08-2010, 04:09 PM
  3. load classes to jsp page
    By ITMaster in forum New To Java
    Replies: 6
    Last Post: 11-10-2008, 04:33 PM
  4. Add data to combobox in page load
    By hussainzim in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 05-15-2008, 01:57 PM
  5. how to load a servlet on index.jsp page...
    By sujithc34 in forum Java Servlet
    Replies: 1
    Last Post: 01-19-2008, 01:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •