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

Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Peter R. Egli
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Fahad Golra
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
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!
 
Decorators in Python
Decorators in PythonDecorators in Python
Decorators in PythonBen James
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaMadishetty Prathibha
 
Spring Framework
Spring FrameworkSpring Framework
Spring Frameworknomykk
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycleDhruvin Nakrani
 
What is Serialization in Java? | Java Tutorial | Edureka
What is Serialization in Java? | Java Tutorial | EdurekaWhat is Serialization in Java? | Java Tutorial | Edureka
What is Serialization in Java? | Java Tutorial | EdurekaEdureka!
 

What's hot (20)

Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Servlet
Servlet Servlet
Servlet
 
Servlets
ServletsServlets
Servlets
 
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...
 
Jpa
JpaJpa
Jpa
 
Servlets
ServletsServlets
Servlets
 
Decorators in Python
Decorators in PythonDecorators in Python
Decorators in Python
 
Interface
InterfaceInterface
Interface
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Servlets
ServletsServlets
Servlets
 
What is Serialization in Java? | Java Tutorial | Edureka
What is Serialization in Java? | Java Tutorial | EdurekaWhat is Serialization in Java? | Java Tutorial | Edureka
What is Serialization in Java? | Java Tutorial | Edureka
 
JVM
JVMJVM
JVM
 

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 (10)

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
 
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
 
Servlet
ServletServlet
ServletIshucs
 

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
 
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
 
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
 
Java part 3
Java part  3Java part  3
Java part 3
 
Servlet
ServletServlet
Servlet
 

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

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 Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
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
 

Recently uploaded (20)

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 Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 

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