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?