Servlets. An extension of a web server runs inside a servlet container

Size: px
Start display at page:

Download "Servlets. An extension of a web server runs inside a servlet container"

Transcription

1 Servlets What is a servlet? An extension of a web server runs inside a servlet container A Java class derived from the HttpServlet class A controller in webapplications captures requests can forward requests to JSP s and Servlets can create and use Beans multithreaded by nature. Servlets 21 January

2 A servlet is pure JAVA. Its initial purpose was to generate HTML. Like this package serv; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Serv1 extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws IOException, ServletException { response.setcontenttype( text/html ); PrintWriter out = response.getwriter(); out.println( <H1> hello </H1> ); out.println( <a href=\ > klicka här</a> ); public void dopost(httpservletrequest request, HttpServletResponse response) throws IOException, ServletException { doget(request, response); Servlets 21 January

3 Java EE prescribes a certain directory structure that you have to follow. Each application is based in context path. A context path is place in the file system, this acts as a root for my application. Tomcat normally uses a catalogue in its installationhierarchy as the basic context path. The standard location is $TOMCAT-INST/webapps Each application is created in a subdirectory of this root. So if we have a bookshop application we create a catalogue bookshop, this will be our context path. $TOMCAT-INST/webapps/bookshop Each application then should follow a prescribed hierarchy to store its files. Servlet classes should be placed in: context path/web-inf/classes Servlets 21 January

4 Locally on our Solaris system the context path is ~/tomcat/your-username So we put the class file in ~/tomcat/web-inf/classes Since we are using a package here (recommended) the class file should be stored in ~/tomcat/web-inf/classes/serv You can only have one context path in this way. This is due to the local configuration of Tomcat on the Solaris system. Your username will be part Normally you can have as many context paths as you like. Servlets 21 January

5 To compile a servlet, you will need the servlet classes. This is a number of classes distributed as jar-files. They are distributed with tomcat in: $TOMCAT-INST/common/lib/servlet-api.jar. You can also get the library from the course home page. There are several methods to use it: Get the file servlet-api.jar from the tomcat installation or from the course homepage. Store it in ~/tomcat/web-inf/lib/ (on Solaris). Setup your classpath to find them. javac -classpath.:../lib/servlet-api.jar serv/serv1.java You can also set the CLASSPATH environment in the shell if you like. Something like export CLASSPATH=.:/home/olle/tomcat/WEB-INF/lib/servlet-api.jar in.bash_profile Then you can do javac serv/serv1.java Servlets 21 January

6 Another method is to store the jar s you need in your Java installation. You put them in $JAVA-INST/jre/lib/ext The compiler will then pick them up without setting the classpath. Servlets 21 January

7 How do I test my servlet? Normally the servlet is part of a webapplication and is started as part of the application, but you can start a servlet standalone. Use the URL to test this servlet, where app is the name of the application. This is not a recommended way to start a real application but it is OK for test purposes. It is also disabled in Tomcat by default but if you follow the configuration guide in the course homepage you can turn it on. Servlets 21 January

8 (on our Solaris system): where nnn is your user identity. Servlets 21 January

9 The servlet has the following environment: config, request, response, configuration data from the setup request from the browser response to the browser In addition you can request session, ServletContext, the session context the application context These are objects obtained from the container that houses the servlet. Servlets 21 January

10 The structure of a servlet is: An init method that sets up the context for the servlet. Executed once when the servlet is created. It will create a session if needed. The service method do some processing for a HTTP HEAD method and dispatches to the correct method. A destroy method that is executed when the servlet is destroyed. Several doxxx methods, one for each type of HTTP request, eg doget, dopost etc. You don t need to implement any of this, there are default init and destroy methods, and you only need to code the do-methods that you need. Servlets 21 January

11 The servlet lifecycle. client request server servlet not loaded servlet loaded call init call service call destroy call doxxx destroy is called after a specified period of idle time as part of the destruction of the servlet. Servlets 21 January

12 The init method is used to get different context from the webapplication. It can look like this: private static String showpage=null; private static String checkoutpage = null; private static String thankyoupage = null; private static String jdbcurl = null; private static String detailpage=null; private BookListBean booklist = null; /** Initializes the servlet. */ public void init(servletconfig config) throws ServletException { super.init(config); showpage = config.getinitparameter( SHOW_PAGE ); checkoutpage = config.getinitparameter ( CHECKOUT_PAGE ); thankyoupage = config.getinitparameter ( THANKYOU_PAGE ); detailpage = config.getinitparameter( DETAIL_PAGE ); jdbcurl = config.getinitparameter( JDBC_URL );... Servlets 21 January

13 Using the config object, you can ask for different parameters that are setup in the web application with description files. You can have instance variables that you setup in init. It is executed only once. Since servlets are multithreaded, you can only use the instance variables readonly outside the init method. You must not change their value after they have been setup by init, unless you use synchronized code. Servlets 21 January

14 The doxxx methods are declared as: public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, java.io.ioexception {... The simple principle is: Use the request object to find out what you should do. Do that, either yourself or using Beans or JSP s The response object is returned to the client automagically when the method returns. Servlets 21 January

15 Different things that you can do with the request block: getsession() get your session object getparameter(string) get the value of the requested parameter parameters are sent by the browser getattribute(string) get the value of the requested attribut setattribute(string, Object) set a new value for the attribute getheader() getlocale() get the HTTP header the preferred language getcookies() request all Cookies getrequestdispatcher(url) get a dispatcher that can be used to dispatch work to other servlets or JSP s Servlets 21 January

16 The response block can be used to setcontenttype(string) MIME-type for the output setlocale(locale) set the locality in the answer getwriter() get a PrintWriter to produce HTML-output encodeurl(url) Cookies (name/value pair that are stored in the browser) are used to set a sessionid in the browser. In that way it identifies your requests and connects to the correct session. Some users do not allow the server to store cookies. The encodeurl method will test if it can set a cookie, if not it will rewrite all URL s so that a sessionid is appended to the URL. Otherwise the server can not identify your requests. As a general rule, to avoid problems with cookies, always rewrite all URL s Servlets 21 January

17 You can also set/get attributes in the session or application scope. HttpSession sess = request.getsession(); sess.setattribute( x, y ); or ServletContext sc = getservletcontext(); sc.setattribute( booklist,booklist); Servlets 21 January

18 An example package com.mimer.fredrik; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class TestServlet extends HttpServlet { private static final String CONTENT_TYPE = text/html; charset=windows-1252 ; public void init(servletconfig config) throws ServletException { super.init(config); public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { if(request.getparameter( action )!= null && request.getparameter( action ).equals( show )) { TestBean tb = new TestBean(); tb.setage(new Integer( 32 )); tb.setname( Fredrik ); RequestDispatcher rd = request.getrequestdispatcher( test.jsp ); request.setattribute( tb, tb); rd.forward(request, response); Servlets 21 January

19 else{ RequestDispatcher rd = request.getrequestdispatcher( error.jsp ); rd.forward(request, response); Servlets 21 January

20 A servlet is pure JAVA. Its purpose is to generate HTML. Like this package serv; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Serv extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws IOException, ServletException { response.setcontenttype( text/html ); PrintWriter out = response.getwriter(); out.println( <H1> hello </H1> ); out.println( <a href=\ > klicka här</a> ); public void dopost(httpservletrequest request, HttpServletResponse response) throws IOException, ServletException { doget(request, response); Servlets 21 January

21 As you see it is a bit clumsy to print HTML-code. It very easy get cluttered with a lot of special characters and escape sequences. Therefore we usually avoid this and just use the servlet for dispatching work to JSP s that are better suited to output HTML. Servlets 21 January

22 An example of a real servlet that do something package se.upright.education.uu.pvk.assignmenttwo.servlets; /* * Shop.java * */ import javax.servlet.*; import javax.servlet.http.*; import se.upright.education.uu.pvk.assignmenttwo.beans.*; /** * Fredrik Ålund 1.0 */ public class ShopServlet extends HttpServlet { private static String showpage=null; private static String checkoutpage = null; private static String thankyoupage = null; private static String jdbcurl = null; private static String detailpage=null; private BookListBean booklist = null; /** Initializes the servlet. Get some environment variables the have setup in the web application descrition files. We do this to avoid hardcoded filenames and database connections */ public void init(servletconfig config) throws ServletException { super.init(config); showpage = config.getinitparameter( SHOW_PAGE ); checkoutpage = config.getinitparameter( CHECKOUT_PAGE ); thankyoupage = config.getinitparameter( THANKYOU_PAGE ); Servlets 21 January

23 detailpage = config.getinitparameter( DETAIL_PAGE ); jdbcurl = config.getinitparameter( JDBC_URL ); // try to create a Bean that reads our bookstore into // memory try{ booklist = new BookListBean(jdbcURL); catch(exception e){ throw new ServletException(e); // servletcontext is the same as scope Application // store the Bean as an application attribute ServletContext sc = getservletcontext(); sc.setattribute( booklist,booklist); /** Destroys the servlet. */ public void destroy() { /** Processes requests for both HTTP <code> GET</code> and <code>post</code> methods. request servlet request response servlet response */ protected void processrequest( HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.ioexception { HttpSession sess = request.getsession(); RequestDispatcher rd = null; Servlets 21 January

24 // create a shopping cart ShoppingBean shoppingcart = getcart(request); // check what to do, ask for the action parameter if(request.getparameter( action ) == null request.getparameter( action ).equals( show )){ // A request dispatcher that s connected to the page. // dispath work to the JSP showpage // we don t get back rd = request.getrequestdispatcher(showpage); rd.forward(request,response); // another action else if(request.getparameter( action ).equals( add )){ // add a book to our shopping cart // check that is it valid first if (request.getparameter( bookid )!= null && request.getparameter( quantity )!=null ){ BookBean bb = null; bb = booklist.getbyid( Integer.parseInt(request.getParameter( bookid ))); if(bb==null){ throw new ServletException( The book is not in stock. ); else { shoppingcart.addbook(bb,integer.parseint( request.getparameter( quantity ))); rd = request.getrequestdispatcher(showpage); rd.forward(request,response); Servlets 21 January

25 // a method that creates and returns a shoppingcart private ShoppingBean getcart(httpservletrequest request){ HttpSession se = null; se=request.getsession(); ShoppingBean sb =null; sb = (ShoppingBean)se.getAttribute( shoppingcart ); if(sb==null){ sb = new ShoppingBean(); se.setattribute( shoppingcart,sb); return sb; /** Handles the HTTP <code>get</code> method. request servlet request response servlet response */ protected void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, java.io.ioexception { processrequest(request, response); /** Handles the HTTP <code>post</code> method. request servlet request response servlet response */ Servlets 21 January

26 protected void dopost(httpservletrequest request, HttpServletResponse response) throws ServletException, java.io.ioexception { processrequest(request, response); /** Returns a short description of the servlet. */ public String getservletinfo() { return The main BookShop ; Servlets 21 January

27 A simple example with servlets and JSP s package com.mimer.fredrik; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class TestServlet extends HttpServlet { private static final String CONTENT_TYPE = text/html; charset=windows-1252 ; public void init(servletconfig config) throws ServletException { super.init(config); public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { if(request.getparameter( action )!= null && request.getparameter( action ).equals( show )) { TestBean tb = new TestBean(); tb.setage(new Integer( 32 )); tb.setname( Fredrik ); RequestDispatcher rd = request.getrequestdispatcher( test.jsp ); request.setattribute( tb, tb); rd.forward(request, response); Servlets 21 January

28 else{ RequestDispatcher rd = request.getrequestdispatcher( error.jsp ); rd.forward(request, response); Servlets 21 January

29 test.jsp <html><head> <meta http-equiv= Content-Type content= text/html; charset=windows-1252 > <title>hello World</title> </head> <body> <h2>the current time is: </h2> <p> <%= new java.util.date() %></p> <jsp:usebean id= tb scope= request class= com.mimer.fredrik.testbean > Error, the instance is created in the bean </jsp:usebean> <H1> </H1> <jsp:getproperty name= tb property= name /> </body></html> Servlets 21 January

30 error.jsp page contenttype= text/html;charset=windows-1252 %> <html> <head> <meta http-equiv= Content-Type content= text/html; charset=windows-1252 > <title>hello World</title> </head><body> <h2>the current time is: </h2> <p><%= new java.util.date() %></p> Error </body></html> Servlets 21 January

31 TestBean.java package com.mimer.fredrik; public class TestBean { String name; Integer age; public TestBean() { public String getname() { return name; public void setname(string newname) { name = newname; public Integer getage() { return age; public void setage(integer newage) { age = newage; Servlets 21 January

Introduction. This course Software Architecture with Java will discuss the following topics:

Introduction. This course Software Architecture with Java will discuss the following topics: Introduction This course Software Architecture with Java will discuss the following topics: Java servlets Java Server Pages (JSP s) Java Beans JDBC, connections to RDBMS and SQL XML and XML translations

More information

Introduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003

Introduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003 Introduction This course Software Architecture with Java will discuss the following topics: Java servlets Java Server Pages (JSP s) Java Beans JDBC, connections to RDBMS and SQL XML and XML translations

More information

Advanced Web Technology

Advanced Web Technology Berne University of Applied Sciences Dr. E. Benoist Winter Term 2005-2006 Presentation 1 Presentation of the Course Part Java and the Web Servlet JSP and JSP Deployment The Model View Controler (Java Server

More information

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2 Java Servlets Adv. Web Technologies 1) Servlets (introduction) Emmanuel Benoist Fall Term 2016-17 Introduction HttpServlets Class HttpServletResponse HttpServletRequest Lifecycle Methods Session Handling

More information

Java Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1

Java Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1 Java Enterprise Edition Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1 Java Beans Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 2 Java Bean POJO class : private Attributes public

More information

Session 8. Introduction to Servlets. Semester Project

Session 8. Introduction to Servlets. Semester Project Session 8 Introduction to Servlets 1 Semester Project Reverse engineer a version of the Oracle site You will be validating form fields with Ajax calls to a server You will use multiple formats for the

More information

Structure of a webapplication

Structure of a webapplication Structure of a webapplication Catalogue structure: / The root of a web application. This directory holds things that are directly available to the client. HTML-files, JSP s, style sheets etc The root is

More information

A.1 JSP A.2 JSP JSP JSP. MyDate.jsp page contenttype="text/html; charset=windows-31j" import="java.util.calendar" %>

A.1 JSP A.2 JSP JSP JSP. MyDate.jsp page contenttype=text/html; charset=windows-31j import=java.util.calendar %> A JSP A.1 JSP Servlet Java HTML JSP HTML Java ( HTML JSP ) JSP Servlet Servlet HTML JSP MyDate.jsp

More information

Servlets1. What are Servlets? Where are they? Their job. Servlet container. Only Http?

Servlets1. What are Servlets? Where are they? Their job. Servlet container. Only Http? What are Servlets? Servlets1 Fatemeh Abbasinejad abbasine@cs.ucdavis.edu A program that runs on a web server acting as middle layer between requests coming from a web browser and databases or applications

More information

Session 9. Introduction to Servlets. Lecture Objectives

Session 9. Introduction to Servlets. Lecture Objectives Session 9 Introduction to Servlets Lecture Objectives Understand the foundations for client/server Web interactions Understand the servlet life cycle 2 10/11/2018 1 Reading & Reference Reading Use the

More information

Servlet Fudamentals. Celsina Bignoli

Servlet Fudamentals. Celsina Bignoli Servlet Fudamentals Celsina Bignoli bignolic@smccd.net What can you build with Servlets? Search Engines E-Commerce Applications Shopping Carts Product Catalogs Intranet Applications Groupware Applications:

More information

JAVA SERVLET. Server-side Programming INTRODUCTION

JAVA SERVLET. Server-side Programming INTRODUCTION JAVA SERVLET Server-side Programming INTRODUCTION 1 AGENDA Introduction Java Servlet Web/Application Server Servlet Life Cycle Web Application Life Cycle Servlet API Writing Servlet Program Summary 2 INTRODUCTION

More information

Introduction. This course Software Architecture with Java will discuss the following topics:

Introduction. This course Software Architecture with Java will discuss the following topics: Introduction This course Software Architecture with Java will discuss the following topics: Java servlets Java Server Pages (JSP s) Java Beans JDBC, connections to RDBMS and SQL XML and XML translations

More information

Servlet Basics. Agenda

Servlet Basics. Agenda Servlet Basics 1 Agenda The basic structure of servlets A simple servlet that generates plain text A servlet that generates HTML Servlets and packages Some utilities that help build HTML The servlet life

More information

HttpServlet ( Class ) -- we will extend this class to handle GET / PUT HTTP requests

HttpServlet ( Class ) -- we will extend this class to handle GET / PUT HTTP requests What is the servlet? Servlet is a script, which resides and executes on server side, to create dynamic HTML. In servlet programming we will use java language. A servlet can handle multiple requests concurrently.

More information

Java Servlets. Preparing your System

Java Servlets. Preparing your System Java Servlets Preparing to develop servlets Writing and running an Hello World servlet Servlet Life Cycle Methods The Servlet API Loading and Testing Servlets Preparing your System Locate the file jakarta-tomcat-3.3a.zip

More information

CSC309: Introduction to Web Programming. Lecture 10

CSC309: Introduction to Web Programming. Lecture 10 CSC309: Introduction to Web Programming Lecture 10 Wael Aboulsaadat WebServer - WebApp Communication 2. Servlets Web Browser Get servlet/serv1? key1=val1&key2=val2 Web Server Servlet Engine WebApp1 serv1

More information

Servlets and JSP (Java Server Pages)

Servlets and JSP (Java Server Pages) Servlets and JSP (Java Server Pages) XML HTTP CGI Web usability Last Week Nan Niu (nn@cs.toronto.edu) CSC309 -- Fall 2008 2 Servlets Generic Java2EE API for invoking and connecting to mini-servers (lightweight,

More information

Enterprise Java Unit 1- Chapter 4 Prof. Sujata Rizal Servlet API and Lifecycle

Enterprise Java Unit 1- Chapter 4 Prof. Sujata Rizal Servlet API and Lifecycle Introduction Now that the concept of servlet is in place, let s move one step further and understand the basic classes and interfaces that java provides to deal with servlets. Java provides a servlet Application

More information

2. Follow the installation directions and install the server on ccc. 3. We will call the root of your installation as $TOMCAT_DIR

2. Follow the installation directions and install the server on ccc. 3. We will call the root of your installation as $TOMCAT_DIR Installing a Web Server 1. Install a sample web server, which supports Servlets/JSPs. A light weight web server is Apache Tomcat server. You can get the server from http://tomcat.apache.org/ 2. Follow

More information

Web applications and JSP. Carl Nettelblad

Web applications and JSP. Carl Nettelblad Web applications and JSP Carl Nettelblad 2015-04-02 Outline Review and assignment Jara Server Pages Web application structure Review We send repeated requests using HTTP Each request asks for a specific

More information

COMP9321 Web Application Engineering

COMP9321 Web Application Engineering COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid=2411 1 Review:

More information

Java Server Pages, JSP

Java Server Pages, JSP Java Server Pages, JSP Java server pages is a technology for developing web pages that include dynamic content. A JSP page can change its content based on variable items, identity of the user, the browsers

More information

Advanced Internet Technology Lab # 4 Servlets

Advanced Internet Technology Lab # 4 Servlets Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2011 Advanced Internet Technology Lab # 4 Servlets Eng. Doaa Abu Jabal Advanced Internet Technology Lab # 4 Servlets Objective:

More information

The Basic Web Server CGI. CGI: Illustration. Web based Applications, Tomcat and Servlets - Lab 3 - CMPUT 391 Database Management Systems 4

The Basic Web Server CGI. CGI: Illustration. Web based Applications, Tomcat and Servlets - Lab 3 - CMPUT 391 Database Management Systems 4 CMPUT 391 Database Management Systems The Basic Web based Applications, - - CMPUT 391 Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems

More information

INTRODUCTION TO SERVLETS AND WEB CONTAINERS. Actions in Accord with All the Laws of Nature

INTRODUCTION TO SERVLETS AND WEB CONTAINERS. Actions in Accord with All the Laws of Nature INTRODUCTION TO SERVLETS AND WEB CONTAINERS Actions in Accord with All the Laws of Nature Web server vs web container Most commercial web applications use Apache proven architecture and free license. Tomcat

More information

To follow the Deitel publishing program, sign-up now for the DEITEL BUZZ ON-

To follow the Deitel publishing program, sign-up now for the DEITEL BUZZ ON- Ordering Information: Advanced Java 2 Platform How to Program View the complete Table of Contents Read the Preface Download the Code Examples To view all the Deitel products and services available, visit

More information

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC) Session 8 JavaBeans 1 Reading Reading & Reference Head First Chapter 3 (MVC) Reference JavaBeans Tutorialdocs.oracle.com/javase/tutorial/javabeans/ 2 2/27/2013 1 Lecture Objectives Understand how the Model/View/Controller

More information

Module 4: SERVLET and JSP

Module 4: SERVLET and JSP 1.What Is a Servlet? Module 4: SERVLET and JSP A servlet is a small Java program that runs within a Web server. Servlets receive and respond to requests from Web clients, usually across HTTP, the Hyper

More information

Unit 4 - Servlet. Servlet. Advantage of Servlet

Unit 4 - Servlet. Servlet. Advantage of Servlet Servlet Servlet technology is used to create web application, resides at server side and generates dynamic web page. Before Servlet, CGI (Common Gateway Interface) was popular as a server-side programming

More information

Handout 31 Web Design & Development

Handout 31 Web Design & Development Lecture 31 Session Tracking We have discussed the importance of session tracking in the previous handout. Now, we ll discover the basic techniques used for session tracking. Cookies are one of these techniques

More information

COMP9321 Web Application Engineering

COMP9321 Web Application Engineering COMP9321 Web Application Engineering Java Server Pages (JSP) Dr. Basem Suleiman Service Oriented Computing Group, CSE, UNSW Australia Semester 1, 2016, Week 3 http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid=2442

More information

a. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22.

a. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22. Answers 1. What is the super interface to all the JDBC Drivers, specify their fully qualified name? a. Java.sql.Driver i. JDBC-ODBC Driver ii. Java-Native API Driver iii. All Java Net Driver iv. Java Native

More information

JavaServer Pages (JSP)

JavaServer Pages (JSP) JavaServer Pages (JSP) The Context The Presentation Layer of a Web App the graphical (web) user interface frequent design changes usually, dynamically generated HTML pages Should we use servlets? No difficult

More information

Session 20 Data Sharing Session 20 Data Sharing & Cookies

Session 20 Data Sharing Session 20 Data Sharing & Cookies Session 20 Data Sharing & Cookies 1 Reading Shared scopes Java EE 7 Tutorial Section 17.3 Reference http state management www.ietf.org/rfc/rfc2965.txt Cookies Reading & Reference en.wikipedia.org/wiki/http_cookie

More information

Web based Applications, Tomcat and Servlets - Lab 3 -

Web based Applications, Tomcat and Servlets - Lab 3 - CMPUT 391 Database Management Systems Web based Applications, - - CMPUT 391 Database Management Systems Department of Computing Science University of Alberta The Basic Web Server CMPUT 391 Database Management

More information

Servlet. Web Server. Servlets are modules of Java code that run in web server. Internet Explorer. Servlet. Fire Fox. Servlet.

Servlet. Web Server. Servlets are modules of Java code that run in web server. Internet Explorer. Servlet. Fire Fox. Servlet. Servlet OOS Lab Servlet OOS Servlets are modules of Java code that run in web server. Internet Explorer Web Server Fire Fox Servlet Servlet Servlet Java Application 2 Servlet - Example OOS import java.io.*;

More information

Java servlets CSCI 470: Web Science Keith Vertanen Copyright 2013

Java servlets CSCI 470: Web Science Keith Vertanen Copyright 2013 Java servlets CSCI 470: Web Science Keith Vertanen Copyright 2013 Overview Dynamic web content genera2on (thus far) CGI Web server modules Server- side scrip2ng e.g. PHP, ASP, JSP Custom web server Java

More information

Servlets by Example. Joe Howse 7 June 2011

Servlets by Example. Joe Howse 7 June 2011 Servlets by Example Joe Howse 7 June 2011 What is a servlet? A servlet is a Java application that receives HTTP requests as input and generates HTTP responses as output. As the name implies, it runs on

More information

Programming on the Web(CSC309F) Tutorial 9: JavaServlets && JDBC TA:Wael Abouelsaadat

Programming on the Web(CSC309F) Tutorial 9: JavaServlets && JDBC TA:Wael Abouelsaadat Programming on the Web(CSC309F) Tutorial 9: JavaServlets && JDBC TA:Wael Abouelsaadat WebSite: http://www.cs.toronto.edu/~wael Office-Hour: Friday 12:00-1:00 (SF2110) Email: wael@cs.toronto.edu 1 Using

More information

&' () - #-& -#-!& 2 - % (3" 3 !!! + #%!%,)& ! "# * +,

&' () - #-& -#-!& 2 - % (3 3 !!! + #%!%,)& ! # * +, ! "# # $! " &' ()!"#$$&$'(!!! ($) * + #!,)& - #-& +"- #!(-& #& #$.//0& -#-!& #-$$!& 1+#& 2-2" (3" 3 * * +, - -! #.// HttpServlet $ Servlet 2 $"!4)$5 #& 5 5 6! 0 -.// # 1 7 8 5 9 2 35-4 2 3+ -4 2 36-4 $

More information

Using Java servlets to generate dynamic WAP content

Using Java servlets to generate dynamic WAP content C H A P T E R 2 4 Using Java servlets to generate dynamic WAP content 24.1 Generating dynamic WAP content 380 24.2 The role of the servlet 381 24.3 Generating output to WAP clients 382 24.4 Invoking a

More information

Advance Java. Configuring and Getting Servlet Init Parameters per servlet

Advance Java. Configuring and Getting Servlet Init Parameters per servlet Advance Java Understanding Servlets What are Servlet Components? Web Application Architecture Two tier, three tier and N-tier Arch. Client and Server side Components and their relation Introduction to

More information

ServletConfig Interface

ServletConfig Interface ServletConfig Interface Author : Rajat Categories : Advance Java An object of ServletConfig is created by the web container for each servlet. This object can be used to get configuration information from

More information

Servlet and JSP Review

Servlet and JSP Review 2006 Marty Hall Servlet and JSP Review A Recap of the Basics 2 JSP, Servlet, Struts, JSF, AJAX, & Java 5 Training: http://courses.coreservlets.com J2EE Books from Sun Press: http://www.coreservlets.com

More information

UNIT-V. Web Servers: Tomcat Server Installation:

UNIT-V. Web Servers: Tomcat Server Installation: UNIT-V Web Servers: The Web server is meant for keeping Websites. It Stores and transmits web documents (files). It uses the HTTP protocol to connect to other computers and distribute information. Example:

More information

AJP. CHAPTER 5: SERVLET -20 marks

AJP. CHAPTER 5: SERVLET -20 marks 1) Draw and explain the life cycle of servlet. (Explanation 3 Marks, Diagram -1 Marks) AJP CHAPTER 5: SERVLET -20 marks Ans : Three methods are central to the life cycle of a servlet. These are init( ),

More information

Enterprise Java Technologies (Part 1 of 3) Component Architecture. Overview of Java EE. Java Servlets

Enterprise Java Technologies (Part 1 of 3) Component Architecture. Overview of Java EE. Java Servlets ID2212 Network Programming with Java Lecture 10 Enterprise Java Technologies (Part 1 of 3) Component Architecture. Overview of Java EE. Java Servlets Leif Lindbäck, Vladimir Vlassov KTH/ICT/SCS HT 2015

More information

This tutorial will teach you how to use Java Servlets to develop your web based applications in simple and easy steps.

This tutorial will teach you how to use Java Servlets to develop your web based applications in simple and easy steps. About the Tutorial Servlets provide a component-based, platform-independent method for building Webbased applications, without the performance limitations of CGI programs. Servlets have access to the entire

More information

Introduction to Servlets. After which you will doget it

Introduction to Servlets. After which you will doget it Introduction to Servlets After which you will doget it Servlet technology A Java servlet is a Java program that extends the capabilities of a server. Although servlets can respond to any types of requests,

More information

Introduction to Java Servlets. SWE 432 Design and Implementation of Software for the Web

Introduction to Java Servlets. SWE 432 Design and Implementation of Software for the Web Introduction to Java Servlets James Baldo Jr. SWE 432 Design and Implementation of Software for the Web Web Applications A web application uses enabling technologies to 1. make web site contents dynamic

More information

Get the cookies from the service request: Cookie[] HttpServletRequest.getCookies() Add a cookie to the service response:

Get the cookies from the service request: Cookie[] HttpServletRequest.getCookies() Add a cookie to the service response: Managing Cookies Cookies Cookies are a general mechanism which server side applications can use to both store and retrieve information on the client side Servers send cookies in the HTTP response and browsers

More information

Stateless -Session Bean

Stateless -Session Bean Stateless -Session Bean Prepared by: A.Saleem Raja MCA.,M.Phil.,(M.Tech) Lecturer/MCA Chettinad College of Engineering and Technology-Karur E-Mail: asaleemrajasec@gmail.com Creating an Enterprise Application

More information

CS433 Technology Overview

CS433 Technology Overview CS433 Technology Overview Scott Selikoff Cornell University November 13, 2002 Outline I. Introduction II. Stored Procedures III. Java Beans IV. JSPs/Servlets V. JSPs vs. Servlets VI. XML Introduction VII.

More information

Topics. Advanced Java Programming. Quick HTTP refresher. Quick HTTP refresher. Web server can return:

Topics. Advanced Java Programming. Quick HTTP refresher. Quick HTTP refresher. Web server can return: Advanced Java Programming Servlets Chris Wong chw@it.uts.edu.au Orginal notes by Dr Wayne Brookes and Threading Copyright UTS 2008 Servlets Servlets-1 Copyright UTS 2008 Servlets Servlets-2 Quick HTTP

More information

Java4570: Session Tracking using Cookies *

Java4570: Session Tracking using Cookies * OpenStax-CNX module: m48571 1 Java4570: Session Tracking using Cookies * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 Abstract

More information

LAB 1 PREPARED BY : DR. AJUNE WANIS ISMAIL FACULTY OF COMPUTING UNIVERSITI TEKNOLOGI MALAYSIA

LAB 1 PREPARED BY : DR. AJUNE WANIS ISMAIL FACULTY OF COMPUTING UNIVERSITI TEKNOLOGI MALAYSIA LAB 1 PREPARED BY : DR. AJUNE WANIS ISMAIL FACULTY OF COMPUTING UNIVERSITI TEKNOLOGI MALAYSIA Setting up Java Development Kit This step involves downloading an implementation of the Java Software Development

More information

JAVA SERVLET. Server-side Programming ADVANCED FEATURES

JAVA SERVLET. Server-side Programming ADVANCED FEATURES JAVA SERVLET Server-side Programming ADVANCED FEATURES 1 AGENDA RequestDispacher SendRedirect ServletConfig ServletContext ServletFilter SingleThreadedModel Events and Listeners Servlets & Database 2 REQUESTDISPATCHER

More information

JAVA SERVLET. Server-side Programming PROGRAMMING

JAVA SERVLET. Server-side Programming PROGRAMMING JAVA SERVLET Server-side Programming PROGRAMMING 1 AGENDA Passing Parameters Session Management Cookie Hidden Form URL Rewriting HttpSession 2 HTML FORMS Form data consists of name, value pairs Values

More information

SERVLET AND JSP FILTERS

SERVLET AND JSP FILTERS SERVLET AND JSP FILTERS FILTERS OVERVIEW Filter basics Accessing the servlet context Using initialization parameters Blocking responses Modifying responses FILTERS: OVERVIEW Associated with any number

More information

Introduction to Web applications with Java Technology 3- Servlets

Introduction to Web applications with Java Technology 3- Servlets Introduction to Web applications with Java Technology 3- Servlets Juan M. Gimeno, Josep M. Ribó January, 2008 Contents Introduction to web applications with Java technology 1. Introduction. 2. HTTP protocol

More information

SERVLETS INTERVIEW QUESTIONS

SERVLETS INTERVIEW QUESTIONS SERVLETS INTERVIEW QUESTIONS http://www.tutorialspoint.com/servlets/servlets_interview_questions.htm Copyright tutorialspoint.com Dear readers, these Servlets Interview Questions have been designed especially

More information

JSP. Common patterns

JSP. Common patterns JSP Common patterns Common JSP patterns Page-centric (client-server) CLIENT JSP or Servlet CLIENT Enterprise JavaBeans SERVER DB Common JSP patterns Page-centric 1 (client-server) Page View request response

More information

The Structure and Components of

The Structure and Components of Web Applications The Structure and Components of a JEE Web Application Sample Content garth@ggilmour.com The Structure t of a Web Application The application is deployed in a Web Archive A structured jar

More information

Database Applications Recitation 6. Project 3: CMUQFlix CMUQ s Movies Recommendation System

Database Applications Recitation 6. Project 3: CMUQFlix CMUQ s Movies Recommendation System 15-415 Database Applications Recitation 6 Project 3: CMUQFlix CMUQ s Movies Recommendation System 1 Project Objective 1. Set up a front-end website with PostgreSQL as the back-end 2. Allow users to login,

More information

Introduction. This course Software Architecture with Java will discuss the following topics.

Introduction. This course Software Architecture with Java will discuss the following topics. Introduction This course Software Architecture with Java will discuss the following topics. I Java servlets I Java Server Pages (JSP's) I Java Beans I JDBC, connections to RDBMS and SQL I XML and XML translations

More information

Unit-4: Servlet Sessions:

Unit-4: Servlet Sessions: 4.1 What Is Session Tracking? Unit-4: Servlet Sessions: Session tracking is the capability of a server to maintain the current state of a single client s sequential requests. Session simply means a particular

More information

4.1 The Life Cycle of a Servlet 4.2 The Java Servlet Development Kit 4.3 The Simple Servlet: Creating and compile servlet source code, start a web

4.1 The Life Cycle of a Servlet 4.2 The Java Servlet Development Kit 4.3 The Simple Servlet: Creating and compile servlet source code, start a web UNIT - 4 Servlet 4.1 The Life Cycle of a Servlet 4.2 The Java Servlet Development Kit 4.3 The Simple Servlet: Creating and compile servlet source code, start a web browser and request the servlet, example

More information

CSc31800: Internet Programming, CS-CCNY, Spring 2004 Jinzhong Niu May 9, JSPs 1

CSc31800: Internet Programming, CS-CCNY, Spring 2004 Jinzhong Niu May 9, JSPs 1 CSc31800: Internet Programming, CS-CCNY, Spring 2004 Jinzhong Niu May 9, 2004 JSPs 1 As we know, servlets, replacing the traditional CGI technology, can do computation and generate dynamic contents during

More information

Introdução a Servlets

Introdução a Servlets Introdução a Servlets Sumário 7.1.1.Introdução 7.1.2.Servlet Overview and Architecture 7.1.2.1 Interface Servlet and the Servlet Life Cycle 7.1.2.2 HttpServlet Class 7.1.2.3 HttpServletRequest Interface

More information

********************************************************************

******************************************************************** ******************************************************************** www.techfaq360.com SCWCD Mock Questions : Servlet ******************************************************************** Question No :1

More information

CE212 Web Application Programming Part 3

CE212 Web Application Programming Part 3 CE212 Web Application Programming Part 3 30/01/2018 CE212 Part 4 1 Servlets 1 A servlet is a Java program running in a server engine containing methods that respond to requests from browsers by generating

More information

Servlets Basic Operations

Servlets Basic Operations Servlets Basic Operations Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring Overview Preparing to

More information

UNIT-VI. HttpServletResponse It extends the ServletResponse interface to provide HTTP-specific functionality in sending a response.

UNIT-VI. HttpServletResponse It extends the ServletResponse interface to provide HTTP-specific functionality in sending a response. UNIT-VI javax.servlet.http package: The javax.servlet.http package contains a number of classes and interfaces that describe and define the contracts between a Servlet class running under the HTTP protocol

More information

First Servlets. Chapter. Topics in This Chapter

First Servlets. Chapter. Topics in This Chapter First Servlets Chapter Topics in This Chapter The basic structure of servlets A simple servlet that generates plain text The process of compiling, installing, and invoking servlets A servlet that generates

More information

Java Servlets Basic Concepts and Programming

Java Servlets Basic Concepts and Programming Basic Concepts and Programming Giuseppe Della Penna Università degli Studi di L Aquila dellapenna@univaq.it http://www.di.univaq.it/gdellape This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

More information

Session 9. Data Sharing & Cookies. Reading & Reference. Reading. Reference http state management. Session 9 Data Sharing

Session 9. Data Sharing & Cookies. Reading & Reference. Reading. Reference http state management. Session 9 Data Sharing Session 9 Data Sharing & Cookies 1 Reading Reading & Reference Chapter 5, pages 185-204 Reference http state management www.ietf.org/rfc/rfc2109.txt?number=2109 2 3/1/2010 1 Lecture Objectives Understand

More information

Chapter 17. Web-Application Development

Chapter 17. Web-Application Development Chapter 17. Web-Application Development Table of Contents Objectives... 1 17.1 Introduction... 1 17.2 Examples of Web applications... 2 17.2.1 Blogs... 2 17.2.2 Wikis... 2 17.2.3 Sakai... 3 17.2.4 Digital

More information

Oracle EXAM - 1Z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Buy Full Product

Oracle EXAM - 1Z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Buy Full Product Oracle EXAM - 1Z0-858 Java Enterprise Edition 5 Web Component Developer Certified Professional Exam Buy Full Product http://www.examskey.com/1z0-858.html Examskey Oracle 1Z0-858 exam demo product is here

More information

Advanced Topics in Operating Systems. Manual for Lab Practices. Enterprise JavaBeans

Advanced Topics in Operating Systems. Manual for Lab Practices. Enterprise JavaBeans University of New York, Tirana M.Sc. Computer Science Advanced Topics in Operating Systems Manual for Lab Practices Enterprise JavaBeans PART III A Web Banking Application with EJB and MySQL Development

More information

JAVA. Web applications Servlets, JSP

JAVA. Web applications Servlets, JSP JAVA Web applications Servlets, JSP Overview most of current web pages are dynamic technologies and laguages CGI, PHP, ASP,... now we do not talk about client side dynamism (AJAX,..) core Java-based technologies

More information

COMP9321 Web Application Engineering

COMP9321 Web Application Engineering COMP9321 Web Application Engineering Semester 2, 2017 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid=2465 1 Review:

More information

Model View Controller (MVC)

Model View Controller (MVC) Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 5049 Advanced Internet Technology Lab Lab # 11 Model View Controller (MVC) El-masry May, 2014 Objectives To be

More information

Servlets Pearson Education, Inc. All rights reserved.

Servlets Pearson Education, Inc. All rights reserved. 1 26 Servlets 2 A fair request should be followed by the deed in silence. Dante Alighieri The longest part of the journey is said to be the passing of the gate. Marcus Terentius Varro If nominated, I will

More information

Servlet. 1.1 Web. 1.2 Servlet. HTML CGI Common Gateway Interface Web CGI CGI. Java Applet JavaScript Web. Java CGI Servlet. Java. Apache Tomcat Jetty

Servlet. 1.1 Web. 1.2 Servlet. HTML CGI Common Gateway Interface Web CGI CGI. Java Applet JavaScript Web. Java CGI Servlet. Java. Apache Tomcat Jetty 1 Servlet 1.1 Web Web WWW HTML CGI Common Gateway Interface Web HTML Web Web CGI CGI CGI Perl, PHP C Java Applet JavaScript Web CGI HTML 1.2 Servlet Java Servlet Servlet CGI Web CGI 1 Java Java JVM Java

More information

Supplement IV.E: Tutorial for Tomcat For Introduction to Java Programming By Y. Daniel Liang

Supplement IV.E: Tutorial for Tomcat For Introduction to Java Programming By Y. Daniel Liang Supplement IV.E: Tutorial for Tomcat 5.5.9 For Introduction to Java Programming By Y. Daniel Liang This supplement covers the following topics: Obtaining and Installing Tomcat Starting and Stopping Tomcat

More information

Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실

Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실 데이타베이스시스템연구실 Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실 Overview http://www.tutorialspoint.com/jsp/index.htm What is JavaServer Pages? JavaServer Pages (JSP) is a server-side programming

More information

1. Introduction. 2. Life Cycle Why JSP is preferred over Servlets? 2.1. Translation. Java Server Pages (JSP) THETOPPERSWAY.

1. Introduction. 2. Life Cycle Why JSP is preferred over Servlets? 2.1. Translation. Java Server Pages (JSP) THETOPPERSWAY. 1. Introduction Java Server Pages (JSP) THETOPPERSWAY.COM Java Server Pages (JSP) is used for creating dynamic web pages. Java code can be inserted in HTML pages by using JSP tags. The tags are used for

More information

This course is intended for Java programmers who wish to write programs using many of the advanced Java features.

This course is intended for Java programmers who wish to write programs using many of the advanced Java features. COURSE DESCRIPTION: Advanced Java is a comprehensive study of many advanced Java topics. These include assertions, collection classes, searching and sorting, regular expressions, logging, bit manipulation,

More information

More JSP. Advanced Topics in Java. Khalid Azim Mughal Version date: ATIJ More JSP 1/42

More JSP. Advanced Topics in Java. Khalid Azim Mughal   Version date: ATIJ More JSP 1/42 More JSP Advanced Topics in Java Khalid Azim Mughal khalid@ii.uib.no http://www.ii.uib.no/~khalid/atij/ Version date: 2006-09-04 ATIJ More JSP 1/42 Overview Including Resources in JSP Pages using the jsp:include

More information

CIS 455 / 555: Internet and Web Systems

CIS 455 / 555: Internet and Web Systems 1 Background CIS 455 / 555: Internet and Web Systems Spring, 2010 Assignment 1: Web and Application Servers Milestone 1 due February 3, 2010 Milestone 2 due February 15, 2010 We are all familiar with how

More information

HTTP and the Dynamic Web

HTTP and the Dynamic Web HTTP and the Dynamic Web How does the Web work? The canonical example in your Web browser Click here here is a Uniform Resource Locator (URL) http://www-cse.ucsd.edu It names the location of an object

More information

Session 22. Intra Server Control. Lecture Objectives

Session 22. Intra Server Control. Lecture Objectives Session 22 Intra Server Control 1 Lecture Objectives Understand the differences between a server side forward and a redirect Understand the differences between an include and a forward and when each should

More information

sessionx Desarrollo de Aplicaciones en Red A few more words about CGI CGI Servlet & JSP José Rafael Rojano Cáceres

sessionx Desarrollo de Aplicaciones en Red A few more words about CGI CGI Servlet & JSP José Rafael Rojano Cáceres sessionx Desarrollo de Aplicaciones en Red José Rafael Rojano Cáceres http://www.uv.mx/rrojano A few more words about Common Gateway Interface 1 2 CGI So originally CGI purpose was to let communicate a

More information

Integrating Servlets and JavaServer Pages Lecture 13

Integrating Servlets and JavaServer Pages Lecture 13 Integrating Servlets and JavaServer Pages Lecture 13 Core Servlets & JSP book: More Servlets & JSP book: www.moreservlets.com Servlet and JSP Training Courses: courses.coreservlets.com 1 Slides Marty Hall,

More information

Unit 5 JSP (Java Server Pages)

Unit 5 JSP (Java Server Pages) Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic, platform-independent method for building Web-based applications. It focuses more on presentation logic

More information

SSC - Web applications and development Introduction and Java Servlet (I)

SSC - Web applications and development Introduction and Java Servlet (I) SSC - Web applications and development Introduction and Java Servlet (I) Shan He School for Computational Science University of Birmingham Module 06-19321: SSC Outline Outline of Topics What will we learn

More information

Université Antonine - Baabda

Université Antonine - Baabda Université Antonine - Baabda Faculté d ingénieurs en Informatique, Multimédia, Systèmes, Réseaux et Télécommunications Applications mobiles (Pocket PC, etc ) Project: Manipulate School Database Préparé

More information

Lecture Notes On J2EE

Lecture Notes On J2EE BIJU PATNAIK UNIVERSITY OF TECHNOLOGY, ODISHA Lecture Notes On J2EE Prepared by, Dr. Subhendu Kumar Rath, BPUT, Odisha. INTRODUCTION TO SERVLET Java Servlets are server side Java programs that require

More information

Servlet for Json or CSV (or XML) A servlet serving either Json or CSV (or XML) based on GET parameter - This version uses org.json

Servlet for Json or CSV (or XML) A servlet serving either Json or CSV (or XML) based on GET parameter - This version uses org.json Servlet for Json or CSV (or XML) A servlet serving either Json or CSV (or XML) based on GET parameter - This version uses org.json A Servlet used as an API for data Let s say we want to write a Servlet

More information