0% found this document useful (0 votes)
2 views6 pages

Indexjava Merged

The document contains HTML and Java servlet code demonstrating the use of GET and POST methods. It includes forms for user input (name, email, mobile number) and a servlet that processes the data and forwards it to a JSP page for display. Two separate JSP pages are provided to show results for both GET and POST methods.

Uploaded by

vanshchourey286
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Indexjava Merged

The document contains HTML and Java servlet code demonstrating the use of GET and POST methods. It includes forms for user input (name, email, mobile number) and a servlet that processes the data and forwards it to a JSP page for display. Two separate JSP pages are provided to show results for both GET and POST methods.

Uploaded by

vanshchourey286
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

HelloServlet.

html

1 <!-- Experiment 10 : Write a program to demonstrate GET and POST method using servlet -->
2
3 <!DOCTYPE html>
4 <html>
5 <head>
6 <title>GET and POST</title>
7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
8 </head>
9 <body>
10 <h1>Using POST method</h1>
11 <form action="print" method="post">
12 Name
13 <input type="text" name = "name">
14
15 Email
16 <input type="email" name="email">
17
18 Mobile Number
19 <input type="number" name="number">
20
21 <input type ="submit" value="Submit">
22
23
24 </form>
25 </body>
26 </html>
27
[Link]

1
2 package [Link];
3
4 import [Link];
5 import [Link];
6 import [Link];
7 import [Link];
8 import [Link];
9 import [Link];
10 import [Link];
11
12
13 @WebServlet("/print")
14 public class HelloServlet extends HttpServlet {
15
16 @Override
17 protected void doPost(HttpServletRequest request, HttpServletResponse response)
18 throws ServletException, IOException {
19
20 String name = [Link]("name");
21 String email = [Link]("email");
22 String number = [Link]("number");
23
24 [Link]("name", name);
25 [Link]("email" , email);
26 [Link]("number" , number);
27
28 RequestDispatcher rd = [Link]­
("[Link]");
29 [Link](request,response);
30
31 }
32
33
34 }
35
[Link]

1 <%@page contentType="text/html" pageEncoding="UTF-8"%>


2 <!DOCTYPE html>
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6 <title>Results from GET</title>
7 </head>
8 <body>
9 <h1>Results from GET methods</h1>
10 <p>Name : ${name}</p>
11 <p>Email : ${email}</p>
12 <p>Mobile Number : ${number}</p>
13
14 </body>
15 </html>
16
[Link]

1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>GET and POST</title>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6 </head>
7 <body>
8 <h1>Using GET method</h1>
9 <form action="print" method="get">
10 Name
11 <input type="text" name = "name">
12
13 Email
14 <input type="email" name="email">
15
16 Mobile Number
17 <input type="number" name="number">
18
19 <input type ="submit" value="Submit">
20
21
22 </form>
23 </body>
24 </html>
25
[Link]

1
2 package [Link];
3
4 import [Link];
5 import [Link];
6 import [Link];
7 import [Link];
8 import [Link];
9 import [Link];
10 import [Link];
11
12
13 @WebServlet("/print")
14 public class HelloServlet extends HttpServlet {
15
16 @Override
17 protected void doGet(HttpServletRequest request, HttpServletResponse response)
18 throws ServletException, IOException {
19
20 String name = [Link]("name");
21 String email = [Link]("email");
22 String number = [Link]("number");
23
24 [Link]("name", name);
25 [Link]("email" , email);
26 [Link]("number" , number);
27
28 RequestDispatcher rd = [Link]­
("[Link]");
29 [Link](request,response);
30
31 }
32
33
34 }
35
[Link]

1 <%@page contentType="text/html" pageEncoding="UTF-8"%>


2 <!DOCTYPE html>
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6 <title>Results from POST</title>
7 </head>
8 <body>
9 <h1>Results from POST methods</h1>
10 <p>Name : ${name}</p>
11 <p>Email : ${email}</p>
12 <p>Mobile Number : ${number}</p>
13
14 </body>
15 </html>
16

You might also like