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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:52:43+00:00 2026-05-20T14:52:43+00:00

I am facing a similar problem and have learnt that my listener class will

  • 0

I am facing a similar problem and have learnt that my listener class will be instantiated when the web.xml is read. I have few functions in the listener class that are used by the main servlet’s doPost(which interacts with the database(mysql) to read/write data regarding the users.)along with the methods of HttpSessionListener. So what prevents the container from loading the listener class. I am getting the 404 error.

snippet:

public class EntryServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {


    PlayersList playa = new PlayersList(); //listener class

    if(!playa.isExisting(params[3])){
        if(params[1].equals("Register")){           
            playa.addPlayer(params);
        }
    }       
    else
        out.println("Username already exists");


    if(playa.isExisting(params[argUName],params[argUPwd])){
        HttpSession session = request.getSession(true);     
        session.setMaxInactiveInterval(600);            
        HashMap playersMap = playa.getActivePlayers();
        //code . .
    }
    else
        out.println("Couldn't locate player Name!");    
        out.println(playa.getIn());         
}

Listener class:

public class PlayersList implements HttpSessionListener{
private Connection cn;
private Statement st;

PlayersList(){
    try{
        Class.forName("com.mysql.jdbc.Driver");
        cn =  DriverManager.getConnection("jdbc:mysql://localhost/homeDbse\'","root","");
        st = cn.createStatement();
    }
    catch(ClassNotFoundException ce){}
    catch(SQLException se){}
    catch(Exception e){}
}   

public boolean isExisting(String player){
    //interaction with dbse
}   

public void addPlayer(String[] args){
    //interaction with dbse

}   
public void sessionCreated(HttpSessionEvent se){
    //session managing
}   
public void sessionDestroyed(HttpSessionEvent se){
    //session managing
}
  • 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-20T14:52:43+00:00Added an answer on May 20, 2026 at 2:52 pm

    This approach is completely wrong. You should be doing it from the other side on. Create a Player object which implements HttpSessionBindingListener and use it instead.

    public class Player implements HttpSessionBindingListener {
    
        @Override
        public void valueBound(HttpSessionBindingEvent event) {
            // Add player to list.
        }
    
        @Override
        public void valueUnbound(HttpSessionBindingEvent event) {
            // Remove player from list.
        }
    
        // ...
    
    }
    

    The valueBound() will be triggered when you do

    Player player = new Player(name);
    request.getSession().setAttribute("player", player);
    

    The valueUnbound() will be triggered when the session has expired or when you remove the attribute.


    Unrelated to the concrete problem, you have serious JDBC problems in your code. This application will crash whenever the DB times out the connection because it’s been open for too long. You should open and close the connection, statement and resultset in the shortest possible scope. I.e., close them in the finally block of the very same try block where the SQL query is been executed.

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

Sidebar

Related Questions

I've worked on projects that have very complex XML configuration, and one problem that's
I have a public facing website that has been receiving a number of SQL
I'm facing a problem while unit testing my forms. The problem is that data
I am learning facelets and Seam and I'm facing the following problem: I have
I have AMQ + Activemessaging running in a Rails App. I'm facing a problem
I'm facing a hard problem: Imagine I have a map of an entire country,
I am facing a conceptual problem that I am having a hard time overcoming.
I'm facing a problem in C++ for which I currently don't have an elegant
I am facing problem with an Oracle Query in a .net 2.0 based windows
I am facing a problem with .NET generics. The thing I want to do

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.