How to print list in a jsp?

For some reason Apache Tomcat 7.0 doesn't run my main servlet (PlaceListServlet) that should list a bunch of database items on place-list.jsp page. I keep getting 404 everywhere, and Eclipse doesn't report any errors in the source. What seems to be the problem?

  • import http://java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.servlet.RequestDispatcher; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /**  * Servlet implementation class login  */ public class login extends HttpServlet { private static final long serialVersionUID = 1L;     /**      * @see HttpServlet#HttpServlet()      */     public login() {         super();         // TODO Auto-generated constructor stub     } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request,response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //recuperer le login et le mot de passe saisie par l'utlisateur String login = request.getParameter("login"); String pwd = request.getParameter("pwd"); Statement stmt = null; String page="/login.jsp"; //si les champs sont vide il faut resaisie les donneés(rédirection vers la page inisiale connectionDB c=new connectionDB(); System.out.println("DEBUG 204 -1: init connexion à la base DEEWAN"); stmt=c.getconnection(); if (stmt==null) System.out.println("Echec"); if(login.isEmpty()||pwd.isEmpty()) page="/login.jsp"; try {//si l'utlisateur est un agent de saisie ResultSet rs1=stmt.executeQuery("select * from agentSaisie;"); while (rs1.next()) { if (login.equals(rs1.getString("login")) && pwd.equals(rs1.getString("pwd"))) { page="/accueilSai.jsp"; } } //si l'utlistaeur est un agent de recherche ResultSet rs2=stmt.executeQuery("select * from agentRecherche;"); while (rs2.next()) { if (login.equals(rs2.getString("login")) && pwd.equals(rs2.getString("pwd"))) { page="/accueilRech.jsp"; } } //si les informations entrées sont erroné -> la resaisie d'informatons est obligatoire try { RequestDispatcher dispatcher = request.getRequestDispatcher(page);   dispatcher.forward(request, response); } catch (Exception ex) {     ex.printStackTrace (); } } catch (SQLException e) {     e.printStackTrace();     System.out.println("EXCPETION DEBUG 2014:" + e.getMessage()); }

  • Answer:

    If you do not configure the servlet and servlet mapping in web.xml the request will not reach your servlet and you will get 404.

Corneil du Plessis at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.