index.html (HTML file it can be JSP file also)
<html><body>
<center>
<form action="LoginServlet" method="POST">
<b> Login form </b><br><br>
Username: <input type="text" name="uname" value="" /><br><br>
Password: <input type="password" name="pass" value="" /><br><br>
<input type="submit" value="submit" />
</form>
</center>
</body></html>
LoginServlet.java (Servlet File)
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>UserPassword</title></head>");
out.println("<body>");
String username = request.getParameter("uname");
String password = request.getParameter("pass");
out.println("Username " + username);
out.println("<br>");
out.println("Password is : " + password);
out.println("</body></html>");
out.close();
}
}
Where to save how to run
ReplyDeleteWhat is a output
ReplyDeletebsdk
ReplyDelete