Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3596790
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:02:03+00:00 2026-05-18T20:02:03+00:00

In my Java EE 6-webapp (running on latest GlassFish 3.1), I’m using JSF2-ManagedBeans and

  • 0

In my Java EE 6-webapp (running on latest GlassFish 3.1), I’m using JSF2-ManagedBeans and @ManagedProperty to inject them into other ManagedBeans. Now i would like to know if i can also inject a @ManagedBean into a @WebServlet, using @ManagedProperty. Some code:

@WebServlet(name = "vdd")
public class VddServlet extends HttpServlet
{
  @ManagedProperty(value = "#{userIdentity}")
  private UserIdentity identity;
}

The ManagedBean looks like this:

@ManagedBean
public class UserIdentity 
{
  ...
}

Does it work like this? If not, what other ways do i have to inject a ManagedBean into a WebServlet (without CDI, which is currently not an option – since there are some issues in GF 3.1 B32/33 in combination with OSGi-Java EE-apps, but we are short on time)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:02:04+00:00Added an answer on May 18, 2026 at 8:02 pm

    Using @ManagedProperty in a servlet is not possible since this works in @ManagedBean classes only. Further, injecting an object which has a lesser scope than the parent itself is also not possible since that would also only end up in concurrency problems. The injector would throw a runtimeexception for that. A servlet is in essence application scoped and shared among all users and your UserIdentity bean seems to be session scoped.

    Since JSF runs on top of the Servlet API and stores the session scoped beans in, well, the session, you could in the servlet just grab it as session attribute:

    UserIdentity identity = (UserIdentity) request.getSession().getAttribute("userIdentity");
    

    Note that the FacesContext is usually also not available in a servlet other than FacesServlet, so using FacesContext in the servlet as suggested in a comment does not make any sense, that would only return null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what is the best way of displaying/using the revision number in a java webapp?
I have a java webapp that has to be deployed on either Win or
I'm looking for a good tool to profile a java webapp. I'd like to
I need to get UTF-8 working in my Java webapp (servlets + JSP, no
I got a bunch of servlet context listeners in my Java webapp, each of
I've got Postscript code/data (?) in memory (in a Java Tomcat webapp) that I'd
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I've an application written in Java and a webapp associated written essentially with javascript.
I'm using Eclipse and Hibernate to develope a J2EE web app. When running/debugging the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.