[go: up one dir, main page]

0% found this document useful (0 votes)
98 views15 pages

Practical 4 Servlet Demo

This document provides steps to create and run a servlet program in NetBeans IDE. [1] Create a new Java web project and select the servlet module. [2] Create a servlet class by right clicking on the package and selecting new servlet. [3] Add servlet code and map it to a URL in the web.xml configuration file.

Uploaded by

Soham Joshi
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)
98 views15 pages

Practical 4 Servlet Demo

This document provides steps to create and run a servlet program in NetBeans IDE. [1] Create a new Java web project and select the servlet module. [2] Create a servlet class by right clicking on the package and selecting new servlet. [3] Add servlet code and map it to a URL in the web.xml configuration file.

Uploaded by

Soham Joshi
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
You are on page 1/ 15

Advance java Programming (AJP)

GTU # 3160707

Practical - 4
Servlet

Computer Engineering Department


Darshan Institute of Engineering & Technology, Rajkot
rajkumar.gondaliya@darshan.ac.in
+919723232741
 Create
LoopingJava Web Project:
Steps to run Servlet Program in Netbeans
 Step 1: Open Netbeans IDE, Select File -> New Project

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 3


Steps for Servlet Program
Step 2: Select Java with Ant ->Java Web -> Web Application, then click on Next

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 4


Steps for Servlet Program
 Step 3: Give a name to your project and click on Next,

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 5


Steps for Servlet Program
 Step 4: and then, Click Finish

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 6


Steps for Servlet Program
 Step 5: The complete directory structure required for the Servlet Application will be created
automatically by the IDE.

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 7


Steps for Servlet Program
 Step 6: To create a Servlet, open Source Package, right click on default packages -> New -
> Servlet.

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 8


Steps for Servlet Program
 Step 7: Give a Name to your Servlet class file

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 9


Steps for Servlet Program

It will add servlet


Web.xml is the
information to
configuration file of
web.xml file
web applications in
java.

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 10


Step 8: Write servlet code: MyServlet.java
MyServet1.java
1 import java.io.*;
2 import javax.servlet.*;
3
4 import javax.servlet.http.*;
5 public class MyServlet1 extends HttpServlet
6 { String msg="";
7
8 PrintWriter out;
9 public void init() throws ServletException
10
{ msg="hello world: my first servlet program"; }
11
12 public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException
13 {
14
response.setContentType("text/html");
15
16 out=response.getWriter();
17 out.println(msg);
18
}
19
20 public void destroy()
21 { out.close();
22
}
23
24 }

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 11


Steps for Servlet Program
 Step 9: open web.xml

It is used to
Configuration
map Servlet to of servlet
using <servlet>
specific URL Map the servlet to a URL. This can be done using
<servlet-mapping> element.

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 12


Steps for Servlet Program
 Step 11: Run your application, right click on your Project and select Run

Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 13


Java Servlet

1
2

5
3

Ref: https://www.ntu.edu.sg/home/ehchua/programming/java/JavaServlets.html
Prof. Rajkumar B Gondaliya #3160707 (AJP)  Practical 4 – Servlet 14
Advance java Programming (AJP)

Thank
You

Computer Engineering Department


Darshan Institute of Engineering & Technology, Rajkot
rajkumar.gondaliya@darshan.ac.in
+919723232741

You might also like