I have problems connecting an html form to a Servlet in my web application. Here's the html file:
<form method="post" class="/Login" action="/Login">
<fieldset class="textbox">
<label class="textbox_field">
<span>Username or Email</span>
<input id="username" name="username" value="" type="text" autocomplete="on" placeholder="Username">
</label>
<label class="textbox_field">
<span>Password</span>
<input id="password" name="password" value="" type="password" placeholder="Password">
</label>
<button class="submit_button" type="submit">Sign-In</button>
</fieldset>
</form>
And here is the servlet, called Login:
@WebServlet("/Login")
public class Login extends HttpServlet {
private static final long serialVersionUID = 1L;
public Login() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("in doPost...");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String username = request.getParameter("username");
String pass = request.getParameter("password");
if(Validate.checkUser(username, pass))
{
RequestDispatcher rs = request.getRequestDispatcher("Welcome");
rs.forward(request, response);
}
else
{
out.println("Username or Password incorrect");
RequestDispatcher rs = request.getRequestDispatcher("index.html");
rs.include(request, response);
}
}
}
I didn't edit the web.xml file since with "Servlet 3.0, the servlets can be configured by @WebServlet annotation on the class without the need for a web.xml". Obviously correct me if I misunderstood this statement.
Finally here's a snippet from the Project Explorer, note that home.jsp is the file where the form is located:
Note: Sadly the solutions provided in other similar questions on stackoverflow don't work in my case.