0

Further below is code for a class named User.

I am getting records of a table and storing them in the User class object which is added in the ArrayList class object. At last, all the records of the table will be stored in the ArrayList class object (collection). Finally, we are storing the ArrayList object in the ServletConext object as an attribute so that we can get it in the servlet and use it.

But when I execute my datab listener class, I face the "404 - Not Found" issue shown in the below image. I don't know where I am going wrong.

404 - Not Found error

I am using Glassfish Server and I have created a web.xml file making entries for all listeners, servlets, and servlet mappings.

Bean ---User class

public class User implements java.io.Serializable {

    String name,password;int id;  


public String getName() {  
    return name;  
}  
public void setName(String name) {  
    this.name = name;  
}  
public String getPassword() {  
    return password;  
}  
public void setPassword(String password) {  
    this.password = password;  
}  

}

Listener class

import javax.servlet.ServletContext;  
import javax.servlet.ServletContextEvent;  
import javax.servlet.ServletContextListener;  
import java.sql.*;  
import java.util.ArrayList;  
import javax.servlet.annotation.WebServlet;

@WebServlet(urlPatterns={"/datab"})
public class datab implements ServletContextListener{  

 public void contextInitialized(ServletContextEvent e) {  
          System.out.println("HI");
  ArrayList list=new ArrayList();  
   try{  
    Class.forName("oracle.jdbc.driver.OracleDriver");  
     Connection con = DriverManager.getConnection("jdbc:oracle:thin:@12.16.19.10:1521:ROW0", "global_urs_prd", "catcat1");

    PreparedStatement ps=con.prepareStatement("select mc_name,folder_name from  ogl_table_status where status <>0");  
    ResultSet rs=ps.executeQuery();  
    while(rs.next()){  
    try{ User u=new User();  
     //u.setId(rs.getInt(1));  
     u.setName(rs.getString(1));  
     u.setPassword(rs.getString(2));  
     list.add(u);}catch(Exception e1){System.out.print(e1);}  
    }  
    con.close();  

   }catch(Exception ex){System.out.print(ex);}  

   //storing the ArrayList object in ServletContext       
   ServletContext context=e.getServletContext();  
   context.setAttribute("data",list);  

 }  
 public void contextDestroyed(ServletContextEvent arg0) {  
    System.out.println("project undeployed...");  
 }  

}  
Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
Mohit Darmwal
  • 275
  • 1
  • 5
  • 21
  • You can't get a resource from the server without a servlet. –  Sep 03 '15 at 14:24
  • Your arrayList declaration is wrong. Please use like this ArrayList list=new ArrayList(); – Rahul Ahirrao Sep 03 '15 at 16:26
  • If something is wrong with your code, you shall get 5xx error, not 404. 404 means you are referring to something which is not available, maybe wrong path, or undeployed stuff due to deploy issues. –  Sep 05 '15 at 16:17

0 Answers0