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

  • SEARCH
  • Home
  • 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 8812707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:39:57+00:00 2026-06-14T03:39:57+00:00

I need to access a session scoped bean from a servlet. I already tried

  • 0

I need to access a session scoped bean from a servlet. I already tried

UserBean userBean = (UserBean) request.getSession().getAttribute("userBean");

as described in this post. But I only get null as result, altough an instance of UserBean is alreay instatiated. Those are the annotations/imports I use for userBean :

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class UserBean implements Serializable{
 ... }

Some Background why I can’t get rid of the servlet : I have a file upload applet in my jsf page. This applet expects an adress where it can send it’s POST request. (I can’t edit this post request to add more fields or something). The post method of my servlet then stores the file. This job can’t be done by a managed bean because the servlet has to be annotated with @MultiPartConfig and I can’t add this annotation to the jsf managed bean.

  • 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-06-14T03:39:58+00:00Added an answer on June 14, 2026 at 3:39 am

    If it returns null, then it can only mean 2 things:

    1. JSF hasn’t created the bean beforehand yet.
    2. The applet-servlet interaction doesn’t use the same HTTP session as the webapp.

    Given the way how you described the functional requirement, I think it’s the latter. You need to ensure that you pass the session identifier of the webapp along with the HTTP request from the applet as well. This can be in the form of the JSESSIONID cookie or the jsessionid URL path attribute.

    First, you need to tell the applet about the session ID the webapp is using. You can do it by passing a parameter to <applet> or <object> tag holding the applet

    <param name="sessionId" value="#{session.id}" />
    

    (the #{session} is an implicit JSF EL variable referring the current HttpSession which in turn has a getId() method; you don’t need to create a managed bean for that or so, the above line of code is complete as-is)

    which can be retrieved in the applet as follows:

    String sessionId = getParameter("sessionId");
    

    You didn’t describe how you’re interacting with the servlet, but assuming that you’re using the standard Java SE URLConnection for this, pointing to the @WebServlet("/servleturl") servlet, then you can use setRequestProperty() to set a request header:

    URL servlet = new URL(getCodeBase(), "servleturl");
    URLConnection connection = servlet.openConnection();
    connection.setRequestProperty("Cookie", "JSESSIONID=" + sessionId);
    // ...
    

    Alternatively, you can also pass it as a URL path attribute:

    URL servlet = new URL(getCodeBase(), "servleturl;jsessionid=" + sessionId);
    URLConnection connection = servlet.openConnection();
    // ...
    

    (please note that the case matters in the both cases)

    Either way, this way the applet-servlet interaction will take place in the same HTTP session as JSF managed beans.

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

Sidebar

Related Questions

I need to access an application-scoped managed bean to modify certain properties from within
I need to access camera from a remote html page. I load this html
Can I access session object from within a function where request object is not
I need to get a proxied session-scoped bean on the HttpSessionListener.sessionDestroyed() . The objective
I need a session bean accesible for service and data access layers but I
I need to access the Manager from the servlet (or filter) in Tomcat to
I have already one session scoped CDI bean, which keeps currently logged in user
I need access to the uint64_t typedef from stdint.h in some wrapper code that
I know that's bad design, but I need access to the view from my
I need to access a components tag attribute like: <h:inputtext id=input_age/> from a backing

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.