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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:24:22+00:00 2026-05-26T12:24:22+00:00

Hey guys i’m working on admin module for my project. When a person logs-in,

  • 0

Hey guys i’m working on admin module for my project. When a person logs-in, a request is sent to login servlet. When it further ask for some other report by clicking other options a request for the report is sent to other servlet which gives the result on the page which is shown at the time of user which is of normal type. The session is lost between two servlets.

I am trying to navigate the generated report on some other page but for that i need to know user type in second servlet. This can be done by fetching value of user_type from login module bean class.

How to handle this situation? thanks

My login servlet is :

LoginService user = new LoginService();
                 user.setUserName(request.getParameter("username"));
                 user.setPassword(request.getParameter("password"));

                 user = UserDAO.login(user);

                 if (user.isValid())
                 {

                      HttpSession session = request.getSession(true);       
                      session.setAttribute("currentSessionUser",user); 



                      if(user.getUser_type().equalsIgnoreCase("admin")){

                          response.sendRedirect("administrator/homepage.jsp");
                      }else{

                      response.sendRedirect("homepage.jsp"); //logged-in page
                      }
                 }

                 else 
                      response.sendRedirect("invalidlogin.jsp"); //error page 
            } 

i tried using this in second servlet:-

LoginService session = (LoginService)request.getAttribute("currentSessionUser");

            String drake = session.getUser_type();
            System.out.println("usertype = " +drake);

Here LoginService is the bean class of login module. i’m get a nullpointer exception here.

  • 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-26T12:24:23+00:00Added an answer on May 26, 2026 at 12:24 pm

    I think you’re trying to do stuff that your web container should handle for you… A session should automatically be maintained over the course of multiple servlet calls from the same client session. Methods from HttpServlet are given a HttpServletRequest. You can obtain the corresponding HttpSession using one of the getSession methods of that class.

    You can bind stuff to the HttpSession using setAttribute and getAttribute.

    EDIT: I’m taking this from the Servlet spec 2.5:

    A servlet can bind an object attribute into an HttpSession implementation by name.
    Any object bound into a session is available to any other servlet that belongs to the
    same ServletContext and handles a request identified as being a part of the same
    session.

    I think you’re better off getting the HttpSession object from the HttpServletRequest (at least assuming it’s a HttpServlet) and setting/getting attributes through that. If you choose a proper name (it follows the same convention as Java package naming) for your attribute, you can be sure the returned object, as long as it’s not null, can be cast to whatever type you put in there. Setting and getting attributes on the request itself isn’t gonna help, I don’t think stuff will get carried over from one servlet call to the next unless you call one servlet from the other with a RequestDispatcher, but that’s not what you’re after here.

    So in your second code sample, do (LoginService)request.getSession().getAttribute("currentSessionUser");, that ought to work. Make sure to check for nulls and maybe choose an attribute name that uses your project’s package name convention (like com.mycompany...).

    I wouldn’t mind a second opinion here since I’m not much of an EE/web developer.

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

Sidebar

Related Questions

Hey guys, I'm working on a project. I need to use the function cvFindHomography
Hey guys, working on an event calendar. I'm having some trouble getting my column
Hey guys. I need help for a project for school. Essentially, I need to
Hey guys, I have a raidan style 2d flying/fighter game that im working on.
Hey guys. Working on Mac OSX 10.6, My problem is that I would like
hey guys, I have mypage.com/user-login.php?action=register and I want to be able to call mypage.com/register
hey guys, i was using Json dll in my project from quite sometime now
Hey guys, I've been bashing my head around for hours now, over this login
hey guys, i'm getting an exception on the following inner exception: {Value cannot be
Hey guys i wrote a quick test. I want delete to call deleteMe which

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.