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

Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Edureka!
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentationritika1
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - JavaDrishti Bhalla
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arraysHassan Dar
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Examplekamal kotecha
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScriptShahDhruv21
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySqlDhyey Dattani
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging TechniquesWebStackAcademy
 

What's hot (20)

Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Spring MVC 3.0 Framework
 
Jquery
JqueryJquery
Jquery
 
ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
React js
React jsReact js
React js
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
jQuery
jQueryjQuery
jQuery
 
React
React React
React
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 

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

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

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