0

I have a JSP with the following <jsp:useBean>:

<jsp:useBean id="res" class="mycompany.Resource" scope="session" />

I would like to get the instance from the session in a servlet. How can I achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
PankajSays
  • 965
  • 1
  • 9
  • 12
  • 1
    Your question is very cryptic, but to start with, are you familiar with how this `` works under the covers? `session.setAttribute()`, `session.getAttribute()` and so on? – BalusC Nov 20 '13 at 18:02
  • Thanks, that comment was really helpful. I was able to get the object from session.getAttribute("res") in User class. – PankajSays Nov 20 '13 at 18:48
  • Okay, I fixed the bad title/question and posted an answer. – BalusC Nov 20 '13 at 19:02

1 Answers1

2

It's stored as a session attribute under the key as specified by <jsp:useBean id>. You can get it by HttpSession#getAttribute() passing the key as follows:

Resource resource = (Resource) request.getSession().getAttribute("res");
// ...
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555