I have a servlet
and a jsp
page. The jsp
page contains a form which the end user will fill out.
<html>
<head>
<title>Please log in to your profile</title>
</head>
<body>
<form action="${pageContext.request.contextPath}/login_servlet" method="post">
Email: <input type="text" size="5" name="email"/>
Password: <input type="text" size="5" name="password"/>
<input type="submit" value="Sign In" />
</form>
</body>
</html>
I will then use a doPost()
method in the servlet because the form has a post method. I get the parameters in the servlet so I can print then out to the console.
@WebServlet("/login_servlet")
public class LoginServlet extends HttpServlet {
@Override
public void doPost(HttpServletRequest req,
HttpServletResponse resp) throws ServletException, IOException {
String email = req.getParameter("email");
String password = req.getParameter("password");
System.out.println("Email: " + email);
System.out.println("Password: " + password);
}
}
When I try visit the URL which is http://localhost:8080/StudentPortal/login_servlet
I get this error; HTTP Status 405 - HTTP method GET is not supported by this URL
with the description that "The specified HTTP method is not allowed for the requested resource."
I'm close to being blocked from asking anymore questions. So please before this is marked as duplicate, I want you to know that I have looked at similar questions and have followed the advice given to no avail.
I have to learn servlets because I'm been put on a Spring project for work soon.