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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:07:22+00:00 2026-05-31T01:07:22+00:00

I am trying to make a Java web application where users can log into

  • 0

I am trying to make a Java web application where users can log into a Java web app I am creating to access a certian page on the website. I have this code below which checks if the user email and password exists in my database of members.

However when i try to set the seesion variable it is null.

    try {
        Class.forName(driver).newInstance();
        conn = DriverManager.getConnection(url, userName, password);
        if (request.getParameter("email") != null && !request.getParameter("email").equals("") && request.getParameter("password") != null && !request.getParameter("password").equals("")) {
            email = request.getParameter("email").toString();
            userpass = request.getParameter("password").toString();
            strQuery = "SELECT * FROM member WHERE email = ? and password =?";
            PreparedStatement stmt = conn.prepareStatement(strQuery);
            stmt.setString(1, email);
            stmt.setString(2, userpass);


            System.out.println(stmt);
            rs = stmt.executeQuery();
            int count = 0;
            while (rs.next()) {
                session.setAttribute("email", rs.getString(2));
                System.out.println(session.getAttribute(email)); //This is null in system console it should not be
                count++;
            }
            if (count > 0) {
                response.sendRedirect("index.jsp");
            } else {
                response.sendRedirect("index.jsp");
            }
        } else {
            response.sendRedirect("gourmet.jsp");
        }
        System.out.println("Connected to the database");
        conn.close();
        System.out.println("Disconnected from database");
    } catch (Exception e) {
        e.printStackTrace();
    }
  • 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-31T01:07:23+00:00Added an answer on May 31, 2026 at 1:07 am

    There is a simple syntax error in your code. Your session variable needs to be within quotes.
    Try this :

    System.out.println(session.getAttribute("email"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to make out with web-apps on java using google app engine. i
I'm trying to import a IntelliJ java web application project (Maven Project) from a
I am trying to make a web application to perform scientific and engineering calculations.
I am trying to make an Android/ Java application that needs to connect to
I'm trying to get into Java web development but seem to be running into
I'm trying to develop a very simple Java web application using JSP and Servlets.
So my background is in Java web services, but I'm trying to make the
I'm trying to make a rest request in java. I tested the web service
So my situation is simple (IMHO): I am trying to create web-esque Java application
I'm trying to deploy a java web app which uses FreeTTS to generate mp3s.

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.