Results 1 to 7 of 7
  1. #1
    sameerk is offline Member
    Join Date
    Aug 2010
    Posts
    19
    Rep Power
    0

    Default share session object between servlet and jsp

    hi,

    i want to send session object from jsp page to servlet class without defining doGet() or doPost method.

    how to do it?

  2. #2
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    you can set this object in session as a session variable and you can get it from session in servlet class.
    like this:
    Java Code:
    <%= session.setAttribute( "theName" ) %>
    and get it servet class:
    Java Code:
     HttpSession session = request.getSession(true)
    session.getValue(java.lang.String name)

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,807
    Rep Power
    19

    Default

    You go from Servlets to JSPs, not the other way around.
    A JSP should be the end point of your processing.

  4. #4
    sameerk is offline Member
    Join Date
    Aug 2010
    Posts
    19
    Rep Power
    0

    Default

    but how could i get the request object without doget and dopost method ?

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,807
    Rep Power
    19

    Default

    Why are you trying to go from a JSP page to a Servlet?
    WHat are you trying to do?
    Because from what I am reading here you are doing something wrong.

  6. #6
    sameerk is offline Member
    Join Date
    Aug 2010
    Posts
    19
    Rep Power
    0

    Default

    actually i m using struts 2
    i have set one attribute in the session on jsp page and i want that session attribute into the servlet class.

  7. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,807
    Rep Power
    19

    Default

    ?
    Struts uses Actions, which are (sort of) servlets.
    You don't go from a JSP in Struts to an Action (or servlet).

    If you have added something to the session in a JSP it will be visible in the Action the next time it's called from the same session.

Similar Threads

  1. session in servlet
    By erakhman in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-14-2010, 05:20 PM
  2. object in session
    By BigBear in forum Java Servlet
    Replies: 4
    Last Post: 03-29-2010, 01:07 PM
  3. session object
    By faheem in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-04-2009, 03:14 AM
  4. session object
    By 5alive in forum New To Java
    Replies: 1
    Last Post: 06-23-2008, 12:45 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
  •