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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:54:33+00:00 2026-06-08T18:54:33+00:00

I am a beginner in Java EE and I have a problem in creating

  • 0

I am a beginner in Java EE and I have a problem in creating a login page.I have made a common login page through which an engineer can login to his/her account.Engineers username starts with ‘engg’. So I have made the following code and getting IllegalStateException error on entering wrong username such as ‘uname100’ which is not present in my table.

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sun.java2d.pipe.GeneralCompositePipe;

import accessdb.Dao;
import accessdb.Getset;

/**
* Servlet implementation class AdminLogIn
*/
public class AdminLogIn extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
    * @return 
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        try {
            String username=request.getParameter("username"); 
            String password=request.getParameter("password");
            Getset g=new Getset();
            Dao dao=new Dao();
            g.setuname(username);
            String newuname=username.substring(0,4);
            // System.out.println(""+username);
            if(newuname.equals("engg"))
            {
                ResultSet rs=dao.EnggLogInUseridCheck(g);

                System.out.println(""+newuname);

                while(rs.next())
                {
                    String uname=rs.getString("uname");
                    System.out.println(""+uname);
                    if(uname.equals(username))
                    {
                        g.setuname(username);
                        System.out.println(""+username);
                        System.out.println(""+uname);
                        ResultSet rs1=dao.EnggLogInPasswordCheck(g);
                        while(rs1.next())
                        {
                            String password1=rs1.getString("password");
                            if(password1.equals(password))
                            {
                                System.out.println(""+password1);
                                response.sendRedirect("engghome.jsp");
                                break;
                            }
                            else
                            {
                                response.sendRedirect("login.jsp");
                                return;
                            }
                        }
                        break;
                    }
                    else
                    {
                        response.sendRedirect("login.jsp");
                        return;
                    }
                }
            }
            else
            {
                response.sendRedirect("login.jsp");
                return;
            }
        }   catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            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-06-08T18:54:35+00:00Added an answer on June 8, 2026 at 6:54 pm

    By the way I have solved the problem.I have modified the code.And the working code is:

     import java.io.IOException;
     import java.io.PrintWriter;
     import java.sql.ResultSet;
     import java.sql.SQLException;
    
     import javax.servlet.ServletException;
     import javax.servlet.http.HttpServlet;
     import javax.servlet.http.HttpServletRequest;
     import javax.servlet.http.HttpServletResponse;
    
     import sun.java2d.pipe.GeneralCompositePipe;
    
     import accessdb.Dao;
     import accessdb.Getset;
    
     /**
     * Servlet implementation class AdminLogIn
      */
     public class Login extends HttpServlet {
    private static final long serialVersionUID = 1L;
    
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    
        String username=request.getParameter("username");
        System.out.println(""+username);
    
        String password=request.getParameter("password");
        System.out.println("test user"+username+"GGG"+password);
        if(username.equals("") || password.equals("") || username.equals(" ") || password.equals(" "))
        {
            response.sendRedirect("login.jsp");
    
        }
         else
         {
             try {
        Getset g=new Getset();
        Dao dao=new Dao();
        g.setuname(username);
    
         String newuname=username.substring(0,4);
    
    
         if(newuname.equals("engg"))
        { 
    
               ResultSet rs;
                rs = dao.EnggLogInCheck(g);
                while(rs.next())
                {
                    String uname=rs.getString("uname");
                    String password1=rs.getString("password");
                    if(uname.equals(username) && (password.equals(password1)))
                    {
                        response.sendRedirect("engghome.jsp");
                        break;
                    }
    
                }
    
                if(rs.next()==false)
                {
                    response.sendRedirect("login.jsp");
                    return;
                }
    
    
        }
    
         else if(newuname.equals("empl"))
            { 
    
                   ResultSet rs;
                    rs = dao.EmplLogInCheck(g);
                    while(rs.next())
                    {
                        String uname=rs.getString("uname");
                        String password1=rs.getString("password");
                        if(uname.equals(username) && (password.equals(password1)))
                        {
                            response.sendRedirect("empcmp.jsp");
                            break;
                        }
    
                    }
    
                    if(rs.next()==false)
                    {
                        response.sendRedirect("login.jsp");
                        return;
                    }
    
    
            }
         else if(username.equals("system"))
            { 
    
                   ResultSet rs;
                    rs = dao.LogInAdmin(g);
                    while(rs.next())
                    {
    
                        String password1=rs.getString(1);
                        if(password.equals(password1))
                        {
                            response.sendRedirect("adminhome.jsp");System.out.println("ffffff");
                            break;
                        }
                        else
                        {
                            response.sendRedirect("login.jsp");
                            return;
                        }
                    }
    
    
    
    
               }
    
    
         else 
               {
                   response.sendRedirect("login.jsp");
                   return;
    
               }
    
    
    
         }
           catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    }
    }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner in Android development. My code crashes. I have made a simple Java method
I'm a beginner in Java programming language, and I have a problem that I
I am beginner in java. I am creating a file chooser that can select
I'm a beginner in Java and I have got some problems with the static
Am Beginner to java.I have a small doubt while i am developing an application
i am a beginner at java language and i use text pad. i have
I'm totally beginner in java. In javascript i have this regex: /[^0-9.,\-\ ]/gi How
I'm a Java-beginner, so please bear with this one. I have a class: class
I'm new to Java and I have a beginner question: NumberFormat is an abstract
I'm sure this is a beginner error... So I have a Java EE 6

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.