I'm trying to get input from the end user through a form. I made the form by using jsp
.
welcome.jsp
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome</title>
</head>
<body>
<form action="welcome" method="post">
<input type="text" value="username" />
<input type="text" value="password" />
<input type="submit" value="login" />
</form>
</body>
</html>
The information that the user will enter will then go to a servlet where it will be printed out to the console.
MyApp.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/welcome")
public class MyApp extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.getRequestDispatcher("/WEB-INF/welcome.jsp").forward(req, resp);
String username = req.getParameter("username");
String password = req.getParameter("password");
System.out.println("Name: " + name);
System.out.println("Password: " + password);
}
}
web.xml
<?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_3_1.xsd"
id="WebApp_ID" version="3.1"
>
<servlet>
<servlet-name>MyApp</servlet-name>
<servlet-class>main.com.myfirstapp.MyApp</servlet-class>
</servlet>
</web-app>
I encounter my problem when I execute my program on the server. This is the error I am getting
HTTP Status 405 - HTTP method GET is not supported by this URL
type: Status report
message: HTTP method GET is not supported by this URL
description: The specified HTTP method is not allowed for the requested resource.