- Prepare HTML or JSP Page to accept user input.
- Retrive Information from the HTML or JSP page & Displaying it on to the Servlet.
Enter the following code snippet in the body tag of the HTML or JSP Page.
<form action="resultservlet">//action is used to go to the servlet when user clicks OK.
Name : <input type="text" name="username"/>
Email ID : <input type="text" name="email"/>
<input type="submit" value="OK"/>
</form>
Step 2 : Retrive Information from the HTML or JSP page & Displaying it on to the Servlet..
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
//retriving & storing user input in the String Variables
String name = request.getParameter("username");
String eid = request.getParameter("email") ;
//displaying output to the user as simple text
response.getWriter().println("Hello" + name + ", Your Email ID is " + eid);
}
No comments:
Post a Comment