title: Problems with Glassfish5 and servlet
body: <p>I'm relatively new to Java. Tried my first web application with server Tomcat, which went rather well. However, with another server Glassfish, problems arouse. After application deployment jsp doesn't connect to servlet, therefore error 404 appears. I added project structure and several classes. Any help appreciated.</p>
  
  <p>empBean:</p>
  
  <pre><code>package app.bean;
  
  
  import app.entity.Emp;
  
  import javax.ejb.Stateless;
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  import javax.persistence.TypedQuery;
  import java.util.List;
  
  @Stateless
  public class EmpBean {
      @PersistenceContext(unitName = "DEVMODE")
      private EntityManager em;
  
      public Emp add(Emp emp) {
          return em.merge(emp);
      }
  
      public Emp get(Integer empno) {
          return em.find(Emp.class, empno);
      }
  
      public void update(Emp emp) {
          add(emp);
      }
      public void delete(long empno){
          em.remove(get((int) empno));
      }
  
      public List&lt;Emp&gt; getAll(){
          TypedQuery&lt;Emp&gt; namedQuery = em.createNamedQuery("Emp.getAll", Emp.class);
          return namedQuery.getResultList();
      }
  }
  </code></pre>
  
  <p>Emp:</p>
  
  <pre><code>package app.entity;
  
  
  import javax.persistence.*;
  import java.sql.Date;
  
  @Entity(name="emp")
  @NamedQuery(name = "Emp.getAll", query = "SELECT e from emp e")
  
  
  
  
  public class Emp {
      @Id
      @Column(name="empno")
      private Integer empno ;
      @Column(name="ename")
      private String ename;
      @Column(name="job")
      private String job;
      @Column(name="mgr")
      private Integer mgr;
      @Column(name="hiredate")
      private Date hiredate;
      @Column(name="sal")
      private Integer sal;
      @Column(name="comm")
      private Integer comm;
      @Column(name="deptno")
      private Integer deptno;
  
      public Emp(Integer empno, String ename, String job, Integer mgr, Date hiredate, Integer sal, Integer comm, Integer deptno, String id) {
          this.empno = empno;
          this.ename = ename;
          this.job = job;
          this.mgr = mgr;
          this.hiredate = hiredate;
          this.sal = sal;
          this.comm = comm;
          this.deptno = deptno;
      }
  
      public Emp() {
      }
  
      public Integer getEmpno() {
          return empno;
      }
  
      public void setEmpno(Integer empno) {
          this.empno = empno;
      }
  
      public String getEname() {
          return ename;
      }
  
      public void setEname(String ename) {
          this.ename = ename;
      }
  
      public String getJob() {
          return job;
      }
  
      public void setJob(String job) {
          this.job = job;
      }
  
      public Integer getMgr() {
          return mgr;
      }
  
      public void setMgr(Integer mgr) {
          this.mgr = mgr;
      }
  
      public Date getHiredate() {
          return hiredate;
      }
  
      public void setHiredate(Date hiredate) {
          this.hiredate = hiredate;
      }
  
      public Integer getSal() {
          return sal;
      }
  
      public void setSal(Integer sal) {
          this.sal = sal;
      }
  
      public Integer getComm() {
          return comm;
      }
  
      public void setComm(Integer comm) {
          this.comm = comm;
      }
  
      public Integer getDeptno() {
          return deptno;
      }
  
      public void setDeptno(Integer deptno) {
          this.deptno = deptno;
      }
  
  }
  </code></pre>
  
  <p>Select1Servlet:</p>
  
  <pre><code>package app.servlets;
  
  import app.bean.DeptBean;
  import app.bean.EmpBean;
  import app.bean.SalgradeBean;
  import app.entity.Dept;
  import app.entity.Emp;
  import app.entity.Salgrade;
  
  import javax.ejb.EJB;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.io.IOException;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.io.PrintWriter;
  import java.sql.*;
  import java.util.ArrayList;
  
  @WebServlet("/search")
  public class Select1Servlet extends HttpServlet {
  
      @EJB
      private EmpBean empBean;
      private DeptBean deptBean;
      private SalgradeBean salgradeBean;
  
      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
          resp.setContentType("text/html");
          req.setCharacterEncoding("UTF-8");
          req.getRequestDispatcher("/searchview.jsp").forward(req, resp);
      }
  
  
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws IOException {
  //        response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          Connection conn = null;
          String url = "jdbc:mysql://localhost:3306/users";
          String userName = "root";
          String password = "7777";
  
  
          Statement st;
          try {
  //            Class.forName("com.mysql.jdbc.Driver");
  //            conn = DriverManager.getConnection(url , userName, password);
              System.out.println("Connected!");
              String numb = request.getParameter("numb");
  
              ArrayList al = null;
              ArrayList pid_list = new ArrayList();
  
  //            String query = "SELECT emp.ename, emp.job, emp.sal, dept.dname, salgrade.grade FROM dept,emp,salgrade WHERE (emp.empno = '" + numb + "' ) AND (emp.deptno = dept.deptno) and (emp.sal BETWEEN losal and hisal)  ";
  
  //            System.out.println("query " + query);
              st = conn.createStatement();
  //            ResultSet rs = st.executeQuery(query);
              Emp emp = empBean.get(Integer.valueOf(numb));
              String ename= emp.getEname();
              String job = emp.getJob();
              Integer sal = emp.getSal();
              Integer deptnoEmp= emp.getDeptno();
              Dept dept = deptBean.get(Integer.valueOf(deptnoEmp));
              String dname = dept.getDname();
              Salgrade salgrade = salgradeBean.get(sal);
              Integer grade = salgrade.getGrade();
  
  //            while (rs.next()) {
                  al = new ArrayList();
  //                out.println(rs.getString(1));
  //                out.println(rs.getString(2));
  //                out.println(rs.getString(3));
  //                out.println(rs.getString(4));
                  al.add(ename);
                  al.add(job);
                  al.add(sal);
                  al.add(dname);
                  al.add(grade);
  
                  System.out.println("al :: " + al);
                  pid_list.add(al);
  //            }
  
              request.setAttribute("piList", pid_list);
              RequestDispatcher view = request.getRequestDispatcher("/searchview.jsp");
              view.forward(request, response);
              conn.close();
              System.out.println("Disconnected!");
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      /**
       * Returns a short description of the servlet.
       * @return a String containing servlet description
       */
      @Override
      public String getServletInfo() {
          return "Short description";
      }// &lt;/editor-fold&gt;
  }
  </code></pre>
  
  <p>select1.jsp:</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt; Enter the number &lt;/title&gt;
      &lt;link rel="stylesheet" href="design/w3.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;br/&gt;&lt;br/&gt;
  &lt;form method="post" name="frm" action="search"&gt;
      &lt;table border="0" width="375" align="center" class = "w3-pink w3-text-white" &gt;
          &lt;tr&gt;&lt;td colspan=2 style="font-size:12pt;" align="center"&gt;
              &lt;h3&gt;Search User&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;
          &lt;br/&gt;
          &lt;tr&gt;&lt;td &gt;&lt;b&gt;User Number&lt;/b&gt;&lt;/td&gt;
              &lt;td&gt;: &lt;input type="number" name="numb" id="numb"&gt;
              &lt;/td&gt;&lt;/tr&gt;
          &lt;tr&gt;&lt;td colspan=2 align="center"&gt;
              &lt;br/&gt;
              &lt;input type="submit" name="submit" value="Search" onclick="form.action='/search';"&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  searchview.jsp:
  &lt;%@ page import="java.util.*" %&gt;
  
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%--&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;--%&gt;
  &lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt; List of emp &lt;/title&gt;
      &lt;link rel="stylesheet" href="design/w3.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form  method="get" name="frm" action="searchview"&gt;
  &lt;table width="700px"
        class = "w3-text-pink"&gt;
      &lt;tr&gt;
          &lt;td colspan=5 align="center"
             class = "w3-black w3-text-pink"&gt;
              &lt;b&gt;User Record&lt;/b&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class = "w3-black "&gt;
          &lt;td&gt;&lt;b&gt;User Name&lt;/b&gt;&lt;/td&gt;
          &lt;td&gt;&lt;b&gt;Job&lt;/b&gt;&lt;/td&gt;
          &lt;td&gt;&lt;b&gt;Sal&lt;/b&gt;&lt;/td&gt;
          &lt;td&gt;&lt;b&gt;Dname&lt;/b&gt;&lt;/td&gt;
          &lt;td&gt;&lt;b&gt;Grade&lt;/b&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;%
         int count = 0;
         String color = "#ffffff";
         if (request.getAttribute("piList") != null) {
             ArrayList al = (ArrayList) request.getAttribute("piList");
             System.out.println(al);
             Iterator itr = al.iterator();
             while (itr.hasNext()) {
  
                 if ((count % 2) == 0) {
                     color = "#ffffff";
                 }
                 count++;
                 ArrayList pList = (ArrayList) itr.next();
     %&gt;
      &lt;tr style="background-color:&lt;%=color%&gt;;"&gt;
          &lt;td&gt;&lt;%=pList.get(0)%&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%=pList.get(1)%&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%=pList.get(2)%&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%=pList.get(3)%&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%=pList.get(4)%&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;%
             }
         }
         if (count == 0) {
     %&gt;
      &lt;tr&gt;
          &lt;td colspan=5 align="center"
             style="background-color:#ffffff"&gt;&lt;b&gt;No Record Found..&lt;/b&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;%            }
     %&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
           version="3.1"&gt;
          &lt;servlet&gt;
              &lt;servlet-name&gt;Select1&lt;/servlet-name&gt;
              &lt;servlet-class&gt;app.servlets.Select1Servlet&lt;/servlet-class&gt;
          &lt;/servlet&gt;
  
          &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;Select1&lt;/servlet-name&gt;
              &lt;url-pattern&gt;/search&lt;/url-pattern&gt;
          &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/QeecM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QeecM.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/bUSRn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bUSRn.jpg" alt="enter image description here"></a></p>