Im very new in the netbeans IDE and the JSPs are able to link with other JSP but is unable to connect to the servlet i have set the action to, from what i gathered from searching around the net there seems to be nothing wrong(which is a high chance im wrong) but the following code is what i have done and hoping someone would tell me what i have done wrong.
register.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration Page</title>
</head>
<body>
<h1>Welcome to the Registration Page</h1>
<jsp:include page="defaultHome.jsp" /><br><br><br>
<form action ="/Register" method="Post">
<table>
<tr>
<td>Username : </td>
<td><input type="text" name ="nameR" size="20"></td>
</tr>
<tr>
<td>ID No : </td>
<td><input type="text" name ="idR" size="20"></td>
</tr>
<tr>
<td>Contact No : </td>
<td><input type="text" name ="contactNoR" size="20"></td>
</tr>
<tr>
<td>Password : </td>
<td><input type="password" name ="passwordR" size="20"></td>
</tr>
<tr>
<td>X-coordinate : </td>
<td><input type="text" name ="locationXR" size="20"></td>
</tr>
<tr>
<td>Y-Coordinate : </td>
<td><input type="text" name ="locationYR" size="20"></td>
</tr>
</table>
<p><input type="submit" value= "Register"></p>
</form>
</body>
</html>
Register.java
@WebServlet(name = "Register", urlPatterns = {"/Register"})
public class Register extends HttpServlet {
@EJB
private UsersFacade usersFacade;
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String name = request.getParameter("nameR");
String contactNo = request.getParameter("contactNoR");
String id = request.getParameter("idR");
String password = request.getParameter("passwordR");
int locationX = Integer.parseInt(request.getParameter("locationXR"));
int locationY = Integer.parseInt(request.getParameter("locationYR"));
Users checkExistingUser = usersFacade.find(id);
Users user = new Users(id,name,contactNo,password,"staff",locationX,locationY);
try (PrintWriter out = response.getWriter()) {
if(checkExistingUser != null){
request.getRequestDispatcher("defaultHome.jsp").include(request, response);
out.println("<br><br> This IC has been registered under another user");
} else{
usersFacade.create(user);
request.getRequestDispatcher("Login.jsp").include(request, response);
out.println("<br><br> Register successful. Please Login to access the voting system");
}
}
}
web.xml
<servlet>
<servlet-name>Register</servlet-name>
<servlet-class>controller.Register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Register</servlet-name>
<url-pattern>/Register</url-pattern>
</servlet-mapping>
There is no errors with the code but the
HTTP Status 404 - Not Found
type Status report
messageNot Found
descriptionThe requested resource is not available.
GlassFish Server Open Source Edition 4.1.1
keeps popping out and would like help with this matter. Thank you very much.