I'm at a very basic point in a Java web project and stuck on the login page. I'm using a .jsp for the login (is this bad practice for small projects?) and, upon entry of a username, the page is supposed to send to a servlet that creates a basic game and then another .jsp which will display it.
However, I'm trying to use RequestDispatcher to redirect from the login.jsp to the servlet and then from the servlet to the display page (another .jsp), and I can't seem to find out how to send POST data using RequestDispatcher and if I can't send POST data I don't know how the servlet is supposed to respond (servlets only do GET and POST, right?).
This is my code for login.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@page import="login.User" %>
<%
String username = request.getParameter("username");
if (username != null)
{
session.setAttribute("username", username);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/classes/create");
dispatcher.forward(request,response);
}
%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Login
</title>
</head>
<body>
<h1>Home</h1>
<h3>Please enter a username to log in:</h3>
<form id="login" method="POST" action="create">
Username: <input type="text" id="username" name="username" />
<br />
<br />
<input type="submit" id="submit" name="submit" value="submit" />
<input type="button" id="clear" name="clear" value="clear" />
</form>
</body>
</html>
My servlet has a lot of code that's probably unecessary for my example, however as mentioned I'm using the POST method. The servlet itself also seems to be working.
Is there a way (or a better way) to do what I'm trying to do here? Or should I just send GET parameters through the RequestDispatcher? Or should I be using an .htm login page that sends to the servlet? I'm trying to build the project with MVC principles.