Site icon WebArtDeveloper

How to Read the Content of a Form using getParameter() method in J2EE

In this tutorial how to Read the Content of a Form using getParameter() method in Advance Java (J2EE) is shown.

Code:

index.html

<html>
<head>
<title>My Login Form</title>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
</head>
<body>
<form action=”log” method=”POST”>
<center>
<table border=”1″ style=”background: #66ffff”>
<tr><td>Login Id:</td>
<td><input type=”text” name=”logid”/></td></tr>
<tr><td>Password:</td>
<td><input type=”password” name=”pwd”/></td></tr>
<tr><td colspan=”2″><center><input type=”submit” value=”Submit Form”/></center></td></tr>
</table>
</center>
</form>

</body>
</html>

log.java

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class log extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(“text/html;charset=UTF-8”);
String id=request.getParameter(“logid”);
String pwd=request.getParameter(“pwd”);
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println(“<!DOCTYPE html>”);
out.println(“<html>”);
out.println(“<head>”);
out.println(“<title>Servlet log</title>”);
out.println(“</head>”);
out.println(“<body>”);
out.println(“<p><font color=’red’>Username:”+id+”</font></p>”);
out.println(“<p><font color=’green’>Password:”+pwd+”</font></p>”);
out.println(“</body>”);
out.println(“</html>”);
}
}

}

https://youtu.be/tRZiS96sGUg

 

Exit mobile version