I am trying out basic login using JSP and Servlets and don't understand how forwardslashes are used to indicate the path.
login.JSP is located in LoginApp/WebContent/login.jsp
LoginServlet.java is located in LoginApp/src/org/koushik/javabrains/LoginServlet.java
I have the following code in my login.jsp file -
<form action="login" method="post">
<br>User ID input type="text" name="userId" />
<br>Password <input type="password" name="password" />
<br><input type="submit" />
</form>
The corresponding servlet code is
@WebServlet("/login") // <-- forwardslash here
public class LoginServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String userId, password;
userId = request.getParameter("userId");
password = request.getParameter("password");
// more code here
}
}
If we see the form action, there is no forwardslash before "login", whereas if we see the servlet annotation, there is a forwardslash before "login". Why this difference?