0

I am creating a website in which i need to use request Object to achieve crud functionality against a database using MVC pattern. Website is hosted locally with WildFly 26.0.1. However, every time i click a submit button on the website i only get "not found" on a new page. I have a few .jsp pages and a servlet + a bunch of backend code. The following is my form in employee.jsp:

<form action=Controller method="get">
  Employee ID :<br> <input type="text" name="empId" id="empId"> <br>
  First name :<br> <input type="text" name="fName" id="fName"> <br>
  Last name :<br> <input type="text" name="lName" id="lName"> <br>
  Salary :<br> <input type="text" name="salary" id="salary"> <br>
  Store ID :<br> <input type="text" name="storeId" id="storeID"> <br><br>
  
  <input type="submit" value="Find" class="button black padding-large large margin-top">
  <input type="submit" value="Create" class="button black padding-large large margin-top"> 
  <input type="submit" value="Update" class="button black padding-large large margin-top"> 
  <input type="submit" value="Delete" class="button black padding-large large margin-top">      
  </form>

and this is a snippet of the servlet code in Controller.java:

@WebServlet("/Controller")
public class Controller extends HttpServlet {
private static final long serialVersionUID = 1L;

@EJB
FacadeLocal facade;

    protected void doGet (HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException { 
        
        System.out.println("reached doGet");
        
        String method = request.getParameter("submit");
        
        System.out.print(method);
        
        if(method.equals("Create")) {
            createEmp(request, response);
        }

private void createEmp(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException { 
        
        System.out.print("create emp called");
        
        String empId = request.getParameter("empId");
        String fName = request.getParameter("fName");
        String lName = request.getParameter("lName");
        int salary = Integer.parseInt(request.getParameter("salary"));
        String storeId = request.getParameter("storeId");
        
        Employee e = new Employee(empId, fName, lName, salary, storeId);
        
        facade.createEmp(e);
    

I believe all my backend code should work, it's just that for some reason, the doGet is never called and thus my createEmp and facade functions don't do anything. I've experimented with different variations of calling a doPost/super/init first but to no avail.

My web.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
 <display-name>MyWebProject</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>default.htm</welcome-file>
  </welcome-file-list>
  <servlet>
  <servlet-name>Controller</servlet-name>
<jsp-file>/home.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/src.main.webapp.*.jsp</url-pattern>
</servlet-mapping>
</web-app>

What can I do to try and solve this?

starberg
  • 1
  • 1
  • Check first if the servlet works. Create the URL manually with the path to your servlet and test data and open it with your browser or use curl. If the servlet works try your JSP and open the browser dev tools and examine the request details. E.g. the URL should be similar to your manually created URL. – vanje May 06 '22 at 11:58
  • @vanje alright, sounds like a good idea. I've been messing around with the xml file so much that I probably broke something. So when I run my servlet and get a "not found", what could I change in the web.xml to fix it? I tried just switching the url mapping to a singular * but it didnt help. – starberg May 06 '22 at 12:14
  • What do the browser developers tools say? – stdunbar May 06 '22 at 13:44

0 Answers0