SlideShare a Scribd company logo
1 of 68
An  Introduction to  Java Web Technology (Java Servlet) Presented At: JECRC, Faculty of E&T, Jodhpur National University, Jodhpur, Rajasthan India -342001
HTTP   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
HTTP METHODS Uploads a representation of the specified resource. PUT Converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy. [3] CONNECT Returns the HTTP methods that the server supports for specified URL. This can be used to check the functionality of a web server by requesting '*' instead of a specific resource. OPTIONS Echoes back the received request, so that a client can see what intermediate servers are adding or changing in the request. TRACE Deletes the specified resource. DELETE Submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request. POST means retrieve whatever data is identified by the URI GET Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content. HEAD DESCRIPTION METHOD
HTTP METHODS HTTP servers are required to implement at least the GET and HEAD methods [4] and, whenever possible, also the OPTIONS method  Safe methods Some methods (for example, HEAD, GET, OPTIONS and TRACE) are defined as  safe , which means they are intended only for information retrieval and should not change the state of the server. Idempotent methods Some http methods are defined to be idempotent, meaning that multiple identical requests should have the same effect as a single request. Methods PUT, DELETE, GET, HEAD, OPTIONS and TRACE, being prescribed as safe, should also be idempotent. HTTP is a stateless protocol. By contrast, the POST method is not necessarily idempotent, and therefore sending an identical POST request multiple times may further affect state or cause further side effects.(like updating inserting records in database multiple times).
DIFFERENCE BETWEEN GET AND POST ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WHAT IS WEB CONTAINER? ,[object Object],[object Object]
WHAT IS JAVA SERVLET? ,[object Object],[object Object]
STRUCTURE OF A WEB APPLICATION ,[object Object],[object Object],[object Object],[object Object],[object Object]
WEB-INF DIRECTORY ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SERVLET LIFE CYCLE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SERVLET LIFE CYCLE
SERVLET LIFE CYCLE - STEPS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SERVLET LIFE CYCLE - STEPS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SETTING UP SERVLET DEVELOPMENT ENVIRONMENT ,[object Object],[object Object],[object Object],[object Object],[object Object]
SETTING UP SERVLET DEVELOPMENT ENVIRONMENT ,[object Object],[object Object]
SETTING UP SERVLET DEVELOPMENT ENVIRONMENT
SETTING UP SERVLET DEVELOPMENT ENVIRONMENT In the variable name filed, enter JAVA_HOME. Specify the path to root directory of JAVA installation in variable value field and click OK button. Now JAVA_HOME will appear under user variables.  Next you need to add bin directory under the root directory of JAVA installation in PATH environment variable.Select the PATH variable from System variables and click on Edit button.  Add: ;%JAVA_HOME%in; at the end of variable value field and click OK button.
INSTALLING TOMCAT Tomcat is an opensource web container. it is also web container reference implementation.  Download the latest version of tomcat from this  URL  . Download the jakarta-tomcat-5.0.28.tar.gz and extract it to the directory of your choice.  Note: This directory is referred as TOMCAT_HOME in other tutorials.   That’s all, tomcat is installed. Starting and shutting down Tomcat To start the tomcat server, open the command prompt, change the directory to TOMCAT HOME/bin and run the startup.bat file. It will start the server.  >startup To shut down the tomcat server, run the shutdown.bat file. It will stop the server.  >shutdown  Verifying Tomcat installation To verify that tomcat is installed properly, start the server as explained above, open the web browser and access the following URL.  http://localhost:8080/index.jsp  It should show the tomcat welcome page, if tomcat is installed properly and server is running.
INSTALLING TOMCAT Setting up the CLASSPATH Now you need to create a new environment variable CLASSPATH if it is not already set. We need to add the servlet-api.jar into the CLASSPATH to compile the Servlets. Follow the same steps as you did to create the JAVA_HOME variable. Create a new variable CLASSPATH under system variables. Add TOMCAT_HOME/lib/servlet-api.jar in variable value field.  Note: here TOMCAT_HOME refers to the tomcat installation directory.
SERVLET API CLASSES AND INTERFACES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SERVLET API CLASSES AND INTERFACES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SERVLET API CLASSES AND INTERFACES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SERVLET API CLASSES AND INTERFACES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SERVLET API CLASSES AND INTERFACES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SERVLET API CLASSES AND INTERFACES ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Understanding the GenericServlet class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Understanding the GenericServlet class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Understanding the GenericServlet class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
GenericServlet Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
GenericServlet Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A VERY SIMPLE SERVLET EXAMPLE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A VERY SIMPLE SERVLET EXAMPLE ,[object Object],[object Object],[object Object],[object Object]
A VERY SIMPLE SERVLET EXAMPLE ,[object Object],[object Object],[object Object]
A VERY SIMPLE SERVLET EXAMPLE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A VERY SIMPLE SERVLET EXAMPLE ,[object Object],[object Object],[object Object],[object Object]
A VERY SIMPLE SERVLET EXAMPLE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A VERY SIMPLE SERVLET EXAMPLE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A VERY SIMPLE SERVLET EXAMPLE
A VERY SIMPLE SERVLET EXAMPLE
A VERY SIMPLE SERVLET EXAMPLE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Handling Form Data using Java Servlet
ADVANTAGES OF JAVA SERVLET ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ADVANTAGES OF JAVA SERVLET OVER CGI ,[object Object],[object Object],[object Object],[object Object],[object Object]
INTRO TO SERVER SIDE PROGRAMMING ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
INTRO TO SERVER SIDE PROGRAMMING ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WRITING SIMPLE HELLOWORLD SERVLET import  java.io.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  HelloWorld  extends  HttpServlet{     public void  doGet(HttpServletRequest request, HttpServletResponse response)                                     throws  ServletException,IOException{     response.setContentType(&quot;text/html&quot;);     PrintWriter pw = response.getWriter();     pw.println(&quot;<html>&quot;);     pw.println(&quot;<head><title>Hello World</title></title>&quot;);     pw.println(&quot;<body>&quot;);     pw.println(&quot;<h1>Hello World</h1>&quot;);     pw.println(&quot;</body></html>&quot;);   } }
WRITING SIMPLE HELLOWORLD SERVLET web.xml file for this program: <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!--<!DOCTYPE web-app  PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;  &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;> --> <web-app>  <servlet>    <servlet-name>Hello</servlet-name>   <servlet- class >HelloWorld</servlet- class >  </servlet>  <servlet-mapping>  <servlet-name>Hello</servlet-name>  <url-pattern>/HelloWorld</url-pattern>  </servlet-mapping> </web-app>
WRITING SIMPLE HELLOWORLD SERVLET
WRITING SIMPLE DISPLAYINGDATE SERVLET import  java.io.*; import  java.util.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  DisplayingDate  extends  HttpServlet{       public void  doGet(HttpServletRequest request, HttpServletResponse                     response)  throws  ServletException, IOException{      PrintWriter pw = response.getWriter();      Date today =  new  Date();      pw.println( &quot;<html>&quot; + &quot;<body><h1>Today Date is</h1>&quot; );      pw.println( &quot;<b>&quot; + today+ &quot;</b></body>&quot; +  &quot;</html>&quot; );    } }
WRITING SIMPLE DISPLAYINGDATE SERVLET <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!--<!DOCTYPE web-app  PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;  &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;> --> <web-app>  <servlet>   <servlet-name>Hello</servlet-name>   <servlet- class >DateDisplay</servlet- class >  </servlet>  <servlet-mapping>  <servlet-name>Hello</servlet-name>  <url-pattern>/DateDisplay</url-pattern>  </servlet-mapping> </web-app>
WRITING SIMPLE DISPLAYINGDATE SERVLET
WRITING SIMPLE DISPLAYINGDATE SERVLET
SIMPLE COUNTING IN SERVLET import  java.io.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  SimpleCounter  extends  HttpServlet{    int  counter = 0;    public void  doGet(HttpServletRequest request, HttpServletResponse response)                          throws  ServletException, IOException {     response.setContentType(&quot;text/html&quot;);     PrintWriter pw = response.getWriter();     counter++;     pw.println(&quot;At present the value of the counter is &quot; + counter);   } }
GETTING SERVER INFORMATION  import  java.io.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  SnoopingServerServlet  extends  HttpServlet{    protected void  doGet(HttpServletRequest request, HttpServletResponse response)                                    throws  ServletException, IOException {     PrintWriter pw = response.getWriter();     pw.println(&quot;The server name is &quot; + request.getServerName() + &quot;<br>&quot;);     pw.println(&quot;The server port number is &quot; + request.getServerPort()+ &quot;<br>&quot;);     pw.println(&quot;The protocol is &quot; + request.getProtocol()+ &quot;<br>&quot;);     pw.println(&quot;The scheme used is &quot; + request.getScheme());   } }
GETTING HEADER INFORMATION  import  java.io.*; import  java.util.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  HeaderServlet  extends  HttpServlet{    protected void  doGet(HttpServletRequest request, HttpServletResponse response)                                 throws  ServletException, IOException {     PrintWriter pw = response.getWriter();     pw.println(&quot;Request Headers are&quot;);     Enumeration enumeration = request.getHeaderNames();      while (enumeration.hasMoreElements()){       String headerName = (String)enumeration.nextElement();       Enumeration headerValues = request.getHeaders(headerName);        if  (headerValues !=  null ){          while  (headerValues.hasMoreElements()){           String values = (String) headerValues.nextElement();           pw.println(headerName + &quot;: &quot; + values);         }       }     }   } }
GETTING HEADER INFORMATION
READING INITIALIZATION PARAMETER In this example we are going to retreive the init paramater values which we have given in the  web.xml  file.  Whenever the container makes a servlet it always reads it deployment descriptor file i.e. web.xml. Container creates name/value pairs for the  ServletConfig  object.  Once the parameters are in  ServletConfig  they will never be read again by the Container.  The main job of the  ServletConfig  object is to give the init parameters.
READING INITIALIZATION PARAMETER import  java.io.*; import  javax.servlet.*; import  javax.servlet.http.*; import  java.util.*; public class  InitServlet  extends  HttpServlet {    public void  doGet(HttpServletRequest request, HttpServletResponse response)                                    throws  ServletException, IOException {     PrintWriter pw = response.getWriter();     pw.print(&quot;Init Parameters are : &quot;);     Enumeration enumeration = getServletConfig().getInitParameterNames();      while (enumeration.hasMoreElements()){       pw.print(enumeration.nextElement() + &quot; &quot;);       }     pw.println(&quot;The email address is &quot; + getServletConfig().getInitParameter(&quot;AdminEmail&quot;));     pw.println(&quot;The address is &quot; + getServletConfig().getInitParameter(&quot;Address&quot;));     pw.println(&quot;The phone no is &quot; + getServletConfig().getInitParameter(&quot;PhoneNo&quot;));   } }
READING INITIALIZATION PARAMETER <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!DOCTYPE web-app  PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;  &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;> <web-app><servlet>  <init-param> <param-name>AdminEmail</param-name>  <param-value>zulfiqar_mca@yahoo.co.in</param-value>  </init-param>  <init-param> <param-name>Address</param-name>  <param-value>Okhla</param-value>  </init-param>   <init-param> <param-name>PhoneNo</param-name>  <param-value>9911217074</param-value>  </init-param>    <servlet-name>Zulfiqar</servlet-name>   <servlet- class >InitServlet</servlet- class >  </servlet>  <servlet-mapping>  <servlet-name>Zulfiqar</servlet-name>  <url-pattern>/InitServlet</url-pattern>  </servlet-mapping> </web-app>
READING INITIALIZATION PARAMETER
PASSING PARAMETER USING HTML FORM <html> <head> <title>New Page 1</title> </head> <body> <h2>Login</h2> <p>Please enter your username and password</p> <form method=&quot;GET&quot; action=&quot;/htmlform/LoginServlet&quot;>   <p> Username  <input type=&quot;text&quot; name=&quot;username&quot; size=&quot;20&quot;></p>   <p> Password  <input type=&quot;text&quot; name=&quot;password&quot; size=&quot;20&quot;></p>   <p><input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;B1&quot;></p> </form> <p>&nbsp;</p> </body> </html>
PASSING PARAMETER USING HTML FORM import  java.io.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  LoginServlet  extends  HttpServlet{    public void  doGet(HttpServletRequest request, HttpServletResponse response)                                     throws  ServletException, IOException {     response.setContentType(&quot;text/html&quot;);     PrintWriter out = response.getWriter();     String name = request.getParameter(&quot;username&quot;);     String pass = request.getParameter(&quot;password&quot;);     out.println(&quot;<html>&quot;);     out.println(&quot;<body>&quot;);     out.println(&quot;Thanks  Mr.&quot; + &quot;  &quot; + name + &quot;  &quot; + &quot;for visiting roseindia<br>&quot; );     out.println(&quot;Now you can see your password : &quot; + &quot;  &quot; + pass + &quot;<br>&quot;);     out.println(&quot;</body></html>&quot;);   } }
PASSING PARAMETER USING HTML FORM <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!--<!DOCTYPE web-app  PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;  &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;> --> <web-app>  <servlet>   <servlet-name>Hello</servlet-name>   <servlet- class >LoginServlet</servlet- class >  </servlet>  <servlet-mapping>  <servlet-name>Hello</servlet-name>  <url-pattern>/LoginServlet</url-pattern>  </servlet-mapping> </web-app>
PASSING PARAMETER USING HTML FORM
MULTIPLE VALUES  FOR A SINGLE PARAMETER <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;> <html> <head> <title>Insert title here</title> </head> <body> <form method = &quot;post&quot; action = &quot;/GetParameterServlet/GetParameterValues&quot;> <p>Which of the whisky you like most</p> <input type = &quot;checkbox&quot; name =&quot;whisky&quot; value = &quot;RoyalChallenge&quot;>RoyalChallenge.<br> <input type = &quot;checkbox&quot; name =&quot;whisky&quot; value = &quot;RoyalStag&quot;>RoyalStag.<br> <input type = &quot;checkbox&quot; name =&quot;whisky&quot; value = &quot;Bagpiper&quot;>Bagpiper.<br> <input type =&quot;submit&quot; name= &quot;submit&quot;> </form> </body> </html>
MULTIPLE VALUES  FOR A SINGLE PARAMETER ,[object Object]
MULTIPLE VALUES  FOR A SINGLE PARAMETER
Thank You!! Please don’t forget to write your review comments on   http://slideshare.net/vikramsingh.v85

More Related Content

What's hot

What's hot (20)

Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Assemblies
AssembliesAssemblies
Assemblies
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java IO
Java IOJava IO
Java IO
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Files in java
Files in javaFiles in java
Files in java
 
Architecture evaluation
Architecture evaluationArchitecture evaluation
Architecture evaluation
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Event handling
Event handlingEvent handling
Event handling
 
Sequence diagram
Sequence diagramSequence diagram
Sequence diagram
 
Java Collections API
Java Collections APIJava Collections API
Java Collections API
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Servlets
ServletsServlets
Servlets
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#
 

Viewers also liked

java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technologyTanmoy Barman
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Evolve13 cq-commerce-framework
Evolve13 cq-commerce-frameworkEvolve13 cq-commerce-framework
Evolve13 cq-commerce-frameworkPaolo Mottadelli
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletFahmi Jafar
 
PSFK presents the Mobile Commerce Playbook
PSFK presents the Mobile Commerce PlaybookPSFK presents the Mobile Commerce Playbook
PSFK presents the Mobile Commerce PlaybookPSFK
 

Viewers also liked (11)

java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Evolve13 cq-commerce-framework
Evolve13 cq-commerce-frameworkEvolve13 cq-commerce-framework
Evolve13 cq-commerce-framework
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
 
e-Eommerce - Framework
e-Eommerce -  Frameworke-Eommerce -  Framework
e-Eommerce - Framework
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
M-Commerce
M-CommerceM-Commerce
M-Commerce
 
M commerce
M commerceM commerce
M commerce
 
Mobile commerce ppt
Mobile commerce pptMobile commerce ppt
Mobile commerce ppt
 
M commerce ppt
M commerce pptM commerce ppt
M commerce ppt
 
PSFK presents the Mobile Commerce Playbook
PSFK presents the Mobile Commerce PlaybookPSFK presents the Mobile Commerce Playbook
PSFK presents the Mobile Commerce Playbook
 

Similar to Web Tech Java Servlet Update1

Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01raviIITRoorkee
 
Abhishek srivastava ppt_web_tech
Abhishek srivastava ppt_web_techAbhishek srivastava ppt_web_tech
Abhishek srivastava ppt_web_techabhishek srivastav
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache TomcatAuwal Amshi
 
Java Servlets
Java ServletsJava Servlets
Java ServletsEmprovise
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesbharathiv53
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteTushar B Kute
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06Ankit Dubey
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIPRIYADARSINISK
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servletssbd6985
 

Similar to Web Tech Java Servlet Update1 (20)

Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01
 
Abhishek srivastava ppt_web_tech
Abhishek srivastava ppt_web_techAbhishek srivastava ppt_web_tech
Abhishek srivastava ppt_web_tech
 
Servlet basics
Servlet basicsServlet basics
Servlet basics
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Servlets
ServletsServlets
Servlets
 
Marata
MarataMarata
Marata
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Servlet & jsp
Servlet  &  jspServlet  &  jsp
Servlet & jsp
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
 
Unit5 servlets
Unit5 servletsUnit5 servlets
Unit5 servlets
 
Java servlets
Java servletsJava servlets
Java servlets
 
Servlet
Servlet Servlet
Servlet
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, API
 
Ftp servlet
Ftp servletFtp servlet
Ftp servlet
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Servlet classnotes
Servlet classnotesServlet classnotes
Servlet classnotes
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 

More from vikram singh

More from vikram singh (20)

Agile
AgileAgile
Agile
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
 
Web tech importants
Web tech importantsWeb tech importants
Web tech importants
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
2 4 Tree
2 4 Tree2 4 Tree
2 4 Tree
 
23 Tree Best Part
23 Tree   Best Part23 Tree   Best Part
23 Tree Best Part
 
JSP Scope variable And Data Sharing
JSP Scope variable And Data SharingJSP Scope variable And Data Sharing
JSP Scope variable And Data Sharing
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
jdbc
jdbcjdbc
jdbc
 
Sax Dom Tutorial
Sax Dom TutorialSax Dom Tutorial
Sax Dom Tutorial
 
Xml
XmlXml
Xml
 
Dtd
DtdDtd
Dtd
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
JSP
JSPJSP
JSP
 
Request dispatching in servlet
Request dispatching in servletRequest dispatching in servlet
Request dispatching in servlet
 
Servlet Part 2
Servlet Part 2Servlet Part 2
Servlet Part 2
 
Tutorial Solution
Tutorial SolutionTutorial Solution
Tutorial Solution
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorial
 

Recently uploaded

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Web Tech Java Servlet Update1

  • 1. An Introduction to Java Web Technology (Java Servlet) Presented At: JECRC, Faculty of E&T, Jodhpur National University, Jodhpur, Rajasthan India -342001
  • 2.
  • 3. HTTP METHODS Uploads a representation of the specified resource. PUT Converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy. [3] CONNECT Returns the HTTP methods that the server supports for specified URL. This can be used to check the functionality of a web server by requesting '*' instead of a specific resource. OPTIONS Echoes back the received request, so that a client can see what intermediate servers are adding or changing in the request. TRACE Deletes the specified resource. DELETE Submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request. POST means retrieve whatever data is identified by the URI GET Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content. HEAD DESCRIPTION METHOD
  • 4. HTTP METHODS HTTP servers are required to implement at least the GET and HEAD methods [4] and, whenever possible, also the OPTIONS method Safe methods Some methods (for example, HEAD, GET, OPTIONS and TRACE) are defined as safe , which means they are intended only for information retrieval and should not change the state of the server. Idempotent methods Some http methods are defined to be idempotent, meaning that multiple identical requests should have the same effect as a single request. Methods PUT, DELETE, GET, HEAD, OPTIONS and TRACE, being prescribed as safe, should also be idempotent. HTTP is a stateless protocol. By contrast, the POST method is not necessarily idempotent, and therefore sending an identical POST request multiple times may further affect state or cause further side effects.(like updating inserting records in database multiple times).
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. SETTING UP SERVLET DEVELOPMENT ENVIRONMENT
  • 17. SETTING UP SERVLET DEVELOPMENT ENVIRONMENT In the variable name filed, enter JAVA_HOME. Specify the path to root directory of JAVA installation in variable value field and click OK button. Now JAVA_HOME will appear under user variables. Next you need to add bin directory under the root directory of JAVA installation in PATH environment variable.Select the PATH variable from System variables and click on Edit button. Add: ;%JAVA_HOME%in; at the end of variable value field and click OK button.
  • 18. INSTALLING TOMCAT Tomcat is an opensource web container. it is also web container reference implementation. Download the latest version of tomcat from this URL . Download the jakarta-tomcat-5.0.28.tar.gz and extract it to the directory of your choice. Note: This directory is referred as TOMCAT_HOME in other tutorials. That’s all, tomcat is installed. Starting and shutting down Tomcat To start the tomcat server, open the command prompt, change the directory to TOMCAT HOME/bin and run the startup.bat file. It will start the server. >startup To shut down the tomcat server, run the shutdown.bat file. It will stop the server. >shutdown Verifying Tomcat installation To verify that tomcat is installed properly, start the server as explained above, open the web browser and access the following URL. http://localhost:8080/index.jsp It should show the tomcat welcome page, if tomcat is installed properly and server is running.
  • 19. INSTALLING TOMCAT Setting up the CLASSPATH Now you need to create a new environment variable CLASSPATH if it is not already set. We need to add the servlet-api.jar into the CLASSPATH to compile the Servlets. Follow the same steps as you did to create the JAVA_HOME variable. Create a new variable CLASSPATH under system variables. Add TOMCAT_HOME/lib/servlet-api.jar in variable value field. Note: here TOMCAT_HOME refers to the tomcat installation directory.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38. A VERY SIMPLE SERVLET EXAMPLE
  • 39. A VERY SIMPLE SERVLET EXAMPLE
  • 40.
  • 41. Handling Form Data using Java Servlet
  • 42.
  • 43.
  • 44.
  • 45.
  • 46. WRITING SIMPLE HELLOWORLD SERVLET import  java.io.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  HelloWorld  extends  HttpServlet{     public void  doGet(HttpServletRequest request, HttpServletResponse response)                                    throws  ServletException,IOException{     response.setContentType(&quot;text/html&quot;);     PrintWriter pw = response.getWriter();     pw.println(&quot;<html>&quot;);     pw.println(&quot;<head><title>Hello World</title></title>&quot;);     pw.println(&quot;<body>&quot;);     pw.println(&quot;<h1>Hello World</h1>&quot;);     pw.println(&quot;</body></html>&quot;);   } }
  • 47. WRITING SIMPLE HELLOWORLD SERVLET web.xml file for this program: <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!--<!DOCTYPE web-app  PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;  &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;> --> <web-app>  <servlet>    <servlet-name>Hello</servlet-name>   <servlet- class >HelloWorld</servlet- class >  </servlet>  <servlet-mapping>  <servlet-name>Hello</servlet-name>  <url-pattern>/HelloWorld</url-pattern>  </servlet-mapping> </web-app>
  • 49. WRITING SIMPLE DISPLAYINGDATE SERVLET import  java.io.*; import  java.util.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  DisplayingDate  extends  HttpServlet{      public void  doGet(HttpServletRequest request, HttpServletResponse                     response)  throws  ServletException, IOException{      PrintWriter pw = response.getWriter();      Date today =  new  Date();      pw.println( &quot;<html>&quot; + &quot;<body><h1>Today Date is</h1>&quot; );      pw.println( &quot;<b>&quot; + today+ &quot;</b></body>&quot; +  &quot;</html>&quot; );    } }
  • 50. WRITING SIMPLE DISPLAYINGDATE SERVLET <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!--<!DOCTYPE web-app  PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;  &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;> --> <web-app>  <servlet>   <servlet-name>Hello</servlet-name>   <servlet- class >DateDisplay</servlet- class >  </servlet>  <servlet-mapping>  <servlet-name>Hello</servlet-name>  <url-pattern>/DateDisplay</url-pattern>  </servlet-mapping> </web-app>
  • 53. SIMPLE COUNTING IN SERVLET import  java.io.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  SimpleCounter  extends  HttpServlet{    int  counter = 0;    public void  doGet(HttpServletRequest request, HttpServletResponse response)                          throws  ServletException, IOException {     response.setContentType(&quot;text/html&quot;);     PrintWriter pw = response.getWriter();     counter++;     pw.println(&quot;At present the value of the counter is &quot; + counter);   } }
  • 54. GETTING SERVER INFORMATION import  java.io.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  SnoopingServerServlet  extends  HttpServlet{    protected void  doGet(HttpServletRequest request, HttpServletResponse response)                                    throws  ServletException, IOException {     PrintWriter pw = response.getWriter();     pw.println(&quot;The server name is &quot; + request.getServerName() + &quot;<br>&quot;);     pw.println(&quot;The server port number is &quot; + request.getServerPort()+ &quot;<br>&quot;);     pw.println(&quot;The protocol is &quot; + request.getProtocol()+ &quot;<br>&quot;);     pw.println(&quot;The scheme used is &quot; + request.getScheme());   } }
  • 55. GETTING HEADER INFORMATION import  java.io.*; import  java.util.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  HeaderServlet  extends  HttpServlet{    protected void  doGet(HttpServletRequest request, HttpServletResponse response)                                 throws  ServletException, IOException {     PrintWriter pw = response.getWriter();     pw.println(&quot;Request Headers are&quot;);     Enumeration enumeration = request.getHeaderNames();      while (enumeration.hasMoreElements()){       String headerName = (String)enumeration.nextElement();       Enumeration headerValues = request.getHeaders(headerName);        if  (headerValues !=  null ){          while  (headerValues.hasMoreElements()){           String values = (String) headerValues.nextElement();           pw.println(headerName + &quot;: &quot; + values);         }       }     }   } }
  • 57. READING INITIALIZATION PARAMETER In this example we are going to retreive the init paramater values which we have given in the web.xml file. Whenever the container makes a servlet it always reads it deployment descriptor file i.e. web.xml. Container creates name/value pairs for the ServletConfig object.  Once the parameters are in ServletConfig they will never be read again by the Container. The main job of the ServletConfig object is to give the init parameters.
  • 58. READING INITIALIZATION PARAMETER import  java.io.*; import  javax.servlet.*; import  javax.servlet.http.*; import  java.util.*; public class  InitServlet  extends  HttpServlet {    public void  doGet(HttpServletRequest request, HttpServletResponse response)                                   throws  ServletException, IOException {     PrintWriter pw = response.getWriter();     pw.print(&quot;Init Parameters are : &quot;);     Enumeration enumeration = getServletConfig().getInitParameterNames();      while (enumeration.hasMoreElements()){       pw.print(enumeration.nextElement() + &quot; &quot;);       }     pw.println(&quot;The email address is &quot; + getServletConfig().getInitParameter(&quot;AdminEmail&quot;));     pw.println(&quot;The address is &quot; + getServletConfig().getInitParameter(&quot;Address&quot;));     pw.println(&quot;The phone no is &quot; + getServletConfig().getInitParameter(&quot;PhoneNo&quot;));   } }
  • 59. READING INITIALIZATION PARAMETER <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!DOCTYPE web-app  PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;  &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;> <web-app><servlet>  <init-param> <param-name>AdminEmail</param-name>  <param-value>zulfiqar_mca@yahoo.co.in</param-value>  </init-param>  <init-param> <param-name>Address</param-name>  <param-value>Okhla</param-value>  </init-param>   <init-param> <param-name>PhoneNo</param-name>  <param-value>9911217074</param-value>  </init-param>    <servlet-name>Zulfiqar</servlet-name>   <servlet- class >InitServlet</servlet- class >  </servlet>  <servlet-mapping>  <servlet-name>Zulfiqar</servlet-name>  <url-pattern>/InitServlet</url-pattern>  </servlet-mapping> </web-app>
  • 61. PASSING PARAMETER USING HTML FORM <html> <head> <title>New Page 1</title> </head> <body> <h2>Login</h2> <p>Please enter your username and password</p> <form method=&quot;GET&quot; action=&quot;/htmlform/LoginServlet&quot;>   <p> Username  <input type=&quot;text&quot; name=&quot;username&quot; size=&quot;20&quot;></p>   <p> Password  <input type=&quot;text&quot; name=&quot;password&quot; size=&quot;20&quot;></p>   <p><input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;B1&quot;></p> </form> <p>&nbsp;</p> </body> </html>
  • 62. PASSING PARAMETER USING HTML FORM import  java.io.*; import  javax.servlet.*; import  javax.servlet.http.*; public class  LoginServlet  extends  HttpServlet{    public void  doGet(HttpServletRequest request, HttpServletResponse response)                                    throws  ServletException, IOException {     response.setContentType(&quot;text/html&quot;);     PrintWriter out = response.getWriter();     String name = request.getParameter(&quot;username&quot;);     String pass = request.getParameter(&quot;password&quot;);     out.println(&quot;<html>&quot;);     out.println(&quot;<body>&quot;);     out.println(&quot;Thanks  Mr.&quot; + &quot;  &quot; + name + &quot;  &quot; + &quot;for visiting roseindia<br>&quot; );     out.println(&quot;Now you can see your password : &quot; + &quot;  &quot; + pass + &quot;<br>&quot;);     out.println(&quot;</body></html>&quot;);   } }
  • 63. PASSING PARAMETER USING HTML FORM <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <!--<!DOCTYPE web-app  PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;  &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;> --> <web-app>  <servlet>   <servlet-name>Hello</servlet-name>   <servlet- class >LoginServlet</servlet- class >  </servlet>  <servlet-mapping>  <servlet-name>Hello</servlet-name>  <url-pattern>/LoginServlet</url-pattern>  </servlet-mapping> </web-app>
  • 65. MULTIPLE VALUES FOR A SINGLE PARAMETER <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;> <html> <head> <title>Insert title here</title> </head> <body> <form method = &quot;post&quot; action = &quot;/GetParameterServlet/GetParameterValues&quot;> <p>Which of the whisky you like most</p> <input type = &quot;checkbox&quot; name =&quot;whisky&quot; value = &quot;RoyalChallenge&quot;>RoyalChallenge.<br> <input type = &quot;checkbox&quot; name =&quot;whisky&quot; value = &quot;RoyalStag&quot;>RoyalStag.<br> <input type = &quot;checkbox&quot; name =&quot;whisky&quot; value = &quot;Bagpiper&quot;>Bagpiper.<br> <input type =&quot;submit&quot; name= &quot;submit&quot;> </form> </body> </html>
  • 66.
  • 67. MULTIPLE VALUES FOR A SINGLE PARAMETER
  • 68. Thank You!! Please don’t forget to write your review comments on http://slideshare.net/vikramsingh.v85