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 7548385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:41:06+00:00 2026-05-30T09:41:06+00:00

I am trying to put a HashMap on to the ServletContext object so that

  • 0

I am trying to put a HashMap on to the ServletContext object so that i can access it from a war file that is on a different context. I have not tried to access it from mutliple contexts yet. I just tried to access from the same servlet and i cant seem to be able to get the value. Both approaches below return nullpointerexceptions.

public class TestServlet extends HttpServlet{

private static final long serialVersionUID = -8002515227440283546L;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException{
    PrintWriter out = response.getWriter();

    HashMap<String ,String> hm = new HashMap<String, String>();
    hm.put("1", "1");

    this.getServletContext().setAttribute("usernamanager", hm);
    this.getServletConfig().getServletContext().setAttribute("usernamanager", hm);  

    HashMap newMap2 = (HashMap) this.getServletConfig().getServletContext().getAttribute("usermanager"); 
    HashMap newMap3 = (HashMap) this.getServletContext().getAttribute("usermanager"); 

    out.println("App1 - " + newMap2.get("1"));
    out.println("App1 - " + newMap3.get("1"));
}
}

The servlet is deployed on a Tomcat container.

  • 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-30T09:41:07+00:00Added an answer on May 30, 2026 at 9:41 am

    The attribute names should match: usernamanager vs usermanager

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

Sidebar

Related Questions

I am trying to write an Object of kind HashMap to a file &
I'm trying to read a line of text from a text file and put
I have a java.util.HashMap object m (a return value from a call to Java
I'm trying to put different images (.jpg , .png) dynamically into a ListView from
I'm trying to get the speed of a Test object from a HashMap when
I am trying to write a simple program where i can put a HashMap
I trying to put together an Android app that will take a picture and
We're trying to put together kiosk solution where we can charge people by hour
I'm trying to put in an exception in my web.config so that one page
Im reading values from a file and storing these values in a hashmap, using

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.