Introduction to Web applications with Java Technology 3- Servlets

Size: px
Start display at page:

Download "Introduction to Web applications with Java Technology 3- Servlets"

Transcription

1 Introduction to Web applications with Java Technology 3- Servlets Juan M. Gimeno, Josep M. Ribó January, 2008

2 Contents Introduction to web applications with Java technology 1. Introduction. 2. HTTP protocol 3. Servlets 4. Servlet container: Tomcat 5. Web application deployment 1

3 3- Servlets. Contents Introduction to servlets Servlet API Servlet GenericServlet HttpServlet HttpServletRequest HttpServletResponse ServletContext Example 1: Hello world Example 2: Sending an HTTP request Example 3: Parameter capture by name Servlet limitations and introduction to JSP Advanced topics on servlets: Filters Event listeners Servelts and concurrency 2

4 Intro. to Web applications in Java. 3- Servlets. Introduction 2.3 Servlets What is a servlet A servlet is a java class which may manage http requests sent by a client and generate responses to them. An http request from a client may refer (in its URI) a servlet as the requested resource. The execution of that servlet will manage the request and generate a response which is sent back to the client. Servlets are executed in the context of a servlet container. In particular, TOMCAT is a servlet container 3

5 Intro. to Web applications in Java. 3- Servlets. Introduction Servlet lifecycle Each time a request is addressed to a specific servlet, the servlet container is responsible for 1. Loading the servlet class to which the request is associated (only the first time that servlet is required) 2. Invoking the init(..) operation of that servlet class to set up the servlet (e.g., create a connexion with a database) 3. Managing the request by means of the service(..) operation of that servlet class 4. Converting the response generated by the service(..) operation into an http response and sending it back to the client 5. Invoking the destroy(..) operation of the servlet class to release servlet resources and to save the servlet state (only when the server is shut down) Notice that servlets are only loaded the first time they are requested. 4

6 Intro. to Web applications in Java. 3- Servlets. Servlet API Servlet API Java defines a set of packages to work with servlets. In particular, the following interfaces and classes are available: Servlet HttpServlet HttpServletRequest HttpServletResponse ServletContext... In the next few slides we present them 5

7 Intro. to Web applications in Java. 3- Servlets. Servlet API Servlet API. Servlet Outline: The Servlet interface defines all the operations that must be implemented by any servlet class Usually, this interface is implemented by means of a class that subclassifies the class HttpServlet Some methods: void init(servletconfig config) Called by the servlet container right after the servlet class has been loaded and just before starting its operation init is called just once during all the servlet life-cycle (i.e., it may serve many requests but init is called only before serving the first one) 6

8 Intro. to Web applications in Java. 3- Servlets. Servlet API void service(servletrequest req, ServletResponse res) Called by the servlet container to allow the servlet to respond to a request This operation contains all the work that must be done by the servlet req encapsulates the request sent by the client res encapsulates the response generated by the servlet void destroy() Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. java.lang.string getservletinfo() Returns information about the servlet, such as author, version, and copyright. 7

9 Intro. to Web applications in Java. 3- Servlets. Servlet API Servlet API. GenericServlet Outline: Defines a generic, protocol-independent servlet. To write an HTTP servlet for use on the Web, extend HttpServlet instead. Implements: The interface Servlet 8

10 Intro. to Web applications in Java. 3- Servlets. Servlet API Servlet API. HttpServlet Outline: HttpServlet is an abstract class to manage HTTP servlets (i.e., servlets written for the web) HTTP servlets written by a programmer should subclassify HttpServlet instead of GenericServlet Superclass: GenericServlet 9

11 Intro. to Web applications in Java. 3- Servlets. Servlet API Some methods: protected void service(httpservletrequest req, HttpServletResponse res) It is the responsible for: managing the request sent by the client and for creating a response which will be sent back to the client. However, both issues are not actually carried out in this operation. Instead, the service operation receives standard HTTP requests from the client and dispatches them to the doget/dopost operations defined in this class (according to the HTTP request method: GET or POST) Usually, this operation is not overriden by the classes that subclassify HttpServlet. The overriden operations are doget and dopost protected void doget(httpservletrequest req, HttpServletResponse resp) Called by the server (via the service operation) to allow a servlet to handle a GET request. This operation is overriden by a specific class that subclassify HttpServlet if the HTTP request sent to that specific servlet uses the GET method 10

12 Intro. to Web applications in Java. 3- Servlets. Servlet API protected void dopost(httpservletrequest req, HttpServletResponse resp) Called by the server (via the service operation) to allow a servlet to handle a POST request. This operation is overriden by a specific class that subclassify HttpServlet if the HTTP request sent to that specific servlet uses the GET method 11

13 Intro. to Web applications in Java. 3- Servlets. Servlet API Servlet API. HTTPServletRequest Outline: It is an interface that provides methods to encapsulate the details about http requests. It controls the access to the request elements (remote URL, header, parameters...) Superinterface: ServletRequest (request independent of the protocol) Some methods: String getrequesturi(); Returns the part of this request s URL from the protocol name up to the query string in the first line of the HTTP request. String getquerystring(); Returns the query string that is contained in the request URL after the path. String getmethod(); Returns the name of the HTTP method with which this request was made, for example, GET or POST. Enumeration getheadernames(); Returns an enumeration of all the header names this request contains. 12

14 Intro. to Web applications in Java. 3- Servlets. Servlet API String getheader(string name); Returns the value of the specified request header as a String. Enumeration getparameternames(); (Inherited) Returns an Enumeration of String objects containing the names of the parameters contained in this request. String getparameter(string name); (Inherited) Returns the value of a request parameter as a String, or null if the parameter does not exist. ServletInputStream getinputstream(); (Inherited) Retrieves the body of the request as binary data using a ServletInputStream. BufferedReader getreader(); (Inherited) Retrieves the body of the request as character data using a BufferedReader. 13

15 Intro. to Web applications in Java. 3- Servlets. Servlet API Servet API. HTTPServletResponse Outline: It is an interface that acts as a wrapper of the output stream of a servlet and of its length and type. Superinterface: ServletResponse (response independent of the protocol) Some methods: String setcontentlength(); Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header. String setcontenttype(); (Inherited) Sets the content type of the response being sent to the client. void setheader(string name, String value); Sets a response header with the given name and value. Writer getwriter(); (Inherited) Returns a PrintWriter object that can send character text to the client. 14

16 Intro. to Web applications in Java. 3- Servlets. Servlet API Servlet API. ServletContext Outline: It is an interface that defines methods to share information between all the servlets that compound a web application (there is just one context for the whole web application) In the case of distributed web applications (marked as distributed in their deployment descriptors), there will be a context for each Java virtual machine. In this case, the servlet context cannot store the global information for the whole application The servlet context for a specific application can be obtained by means of the operations: GenericServlet.getServletContext() GenericServlet.getServletConfig().getServletContext() Some methods: void setattribute(string name, Object obj); Sets the object obj as a servlet context scope attribute accessible with the given name Object getattribute(string name); Returns the value of the web context-scope attribute with the given name public java.lang.string getinitparameter(java.lang.string name) 15

17 Intro. to Web applications in Java. 3- Servlets. Servlet API Returns a String containing the value of the initialization parameter with name name, or null if the parameter does not exist This parameter can be set in the web.xml deployment descriptor (see 5-Deployment of web applications) <web-app>... <context-param> <param-name>parametername</param-name> <param-value>parametervalue</param-value> <description> Again, some description </description> </context-param>... </web-app> Parameters set in this way have a context-wide scope They are retrieved by: String val = getservletcontext().getinitparameter("paramete 16

18 Intro. to Web applications in Java. 3- Servlets. Servlet API Servlet API. ServletConfig Outline: It is used to send initialization information from the servlet container to the servlet itself In particular, to send servlet initialization parameters Some methods: ServletContext getservletcontext() String getinitparameter(string name) Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. Servlet initialization parameters can be stated within the servlet definition in the web.xml file: <servlet> <servlet-name>servletname</servlet-name> <description>servletdescription</description> <servlet-class>com.alexandria.package.myservlet</servle <init-param> <param-name>parametername</param-name> <param-value>parametervalue</param-value> </init-param> </servlet> 17

19 Intro. to Web applications in Java. 3- Servlets. Servlet API String value = getservletconfig().getinitparameter("paramname Servlet definition in the deployment descriptor web.xml is presented in 5-Web application deployment 18

20 Intro. to Web applications in Java. 3- Servlets. Servlet API Servlet API. RequestDispatcher Outline: When a servlet needs to send a request to some resource, it does it through a RequestDispatcher object This interface is responsible for directing a request sent by a servlet to a resource A specific object of this interface is obtained by a call to: ServletContext.getRequestDispatcher(..) or request.getrequestdispatcher(..) Some methods: void forward(servletrequest request, ServletResponse respo Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. Example: The servlet that calls forward has managed the request. Another servlet is called to generate the response to the client This strategy is used when the MVC pattern is applied (see ****) void include(servletrequest request, ServletResponse respo Includes the content of a resource (servlet, JSP page, HTML file) in the response. When the included resource has been managed, the control returns to the servlet that launches the include call Useful to include headers, footers... 19

21 Intro. to Web applications in Java. 3- Servlets. Servlet API Use of RequestDispatcher: public class MyServlet extends HttpServlet { public void dopost (HttpServletRequest request, HttpServletResponse response){... RequestDispatcher dispatcher = request. getrequestdispatcher("/someresource"); if (dispatcher!= null) dispatcher.forward(request, response); }... dispatcher is an object that wraps requests to /someresource dispatcher.forward(request, response); This instruction forwards the request request to someresource. Notice that request is the same request that MyServlet has received from the client Before forwarding it to another resource, it is possible that dopost modifies it Example: 20

22 Intro. to Web applications in Java. 3- Servlets. Servlet API request.setattribute("catalogue", cat); dispatcher.forward(request,response); This strategy may be used when the MVC pattern is applied 21

23 Intro. to Web applications in Java. 3- Servlets. Example 1 Example 1: Hello world Example location: introapweb/examples/ex3.1 import javax.servlet.*; import java.io.*; import javax.servlet.http.*; import java.util.*; public class HelloWorld extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws IOException, ServletException { dopost( request, response ) ; } public void dopost (HttpServletRequest request, HttpServletResponse response) { try { response.setcontenttype("text/html"); PrintWriter out = response.getwriter(); out.println("<html>"); out.println("<body>"); out.println("<h1> HELLO WORLD!!! </h1>"); out.println("</body>"); out.println("</html>"); } catch (Exception ex) { ex.printstacktrace();} }} 22

24 Intro. to Web applications in Java. 3- Servlets. Example 2 Example 2: Reading an http request Example location: introapweb/examples/ex3.2 This example reads any http request and sends the contents of this request back to the client The contents of an http request consists of: Request line: Requested server file and request method (GET/POST) Request header: Additional information about the client (accepted language, accepted file formats...) Request body: POST requests It contains the parameters codified in 23

25 Intro. to Web applications in Java. 3- Servlets. Example 2 Recall that parameters may be stored as: A query string in the request line (GET request codified as query string) A query string in the body (POST request codified as query string) A sequence of (name, value) pairs linked by a pseudorandom string in the body (POST request codified as multipart-data) In this example we do not explore how to get each one of the parameters by its name, but how to obtain the elements that constitute the request. Next example will be devoted to the capture of individual parameters by name 24

26 Intro. to Web applications in Java. 3- Servlets. Example 2 import javax.servlet.*; import java.io.*; import javax.servlet.http.*; import java.util.*; public class TranscriuPeticio extends HttpServlet { private static final String PAGE_TOP= "<html>"+ "<head"+ "<title> Transcripcio d una peticio http</title>"+ "</head>"+ "<body bgcolor=\"white\">"+ "<h1> Contents of an http request </h1>"+ "<pre>" ; private static final String PAGE_BOTTOM= "*****FINAL PETICIO HTTP"+ " </pre>" + " </body>"+ " </html>" ;...(cont) 25

27 Intro. to Web applications in Java. 3- Servlets. Example 2...(cont) public void doget(httpservletrequest request, HttpServletResponse response) throws IOException, ServletException { dopost( request, response ) ; } public void dopost (HttpServletRequest request, HttpServletResponse response) { String controlline=new String(""); Enumeration enum; String st=new String(""); try { response.setcontenttype("text/html"); PrintWriter out = response.getwriter(); out.println (PAGE_TOP); out.println("<b>1. Request line </b> <br><br>"); out.println("method: "+request.getmethod()); out.println("request URL: "+ request.getrequesturl()); out.println("query string: "+ request.getquerystring()); 26

28 Intro. to Web applications in Java. 3- Servlets. Example 2 } } out.println("<p><b>2.request header</b><br><br>"); enum=request.getheadernames(); while(enum.hasmoreelements()) { st=(string) enum.nextelement(); out.println(st+" : "+request.getheader(st)); } out.println("<p><b>3.request body:</b> <br><br>"); java.io.bufferedreader br=request.getreader(); String temp=br.readline(); while (temp!=null) { out.println(temp); temp=br.readline(); } br.close(); out.println(page_bottom); } catch (Exception ex) { ex.printstacktrace(); } 27

29 Intro. to Web applications in Java. 3- Servlets. Example 2 Example 2: Reading an http request Remarks: The request body is captured as a character stream by means of the method getreader() of the interface ServletRequest: BufferedReader br=request.getreader(); If the request body were a byte sequence, then it would be necessary to get an input stream (binary) by means of the method getinputstream 28

30 Intro. to Web applications in Java. 3- Servlets. Example 2 When the request is received, we do not know either how many headers will come up in the request or the value of those headers. Therefore, 1. We get the header names: (enum=request.getheadernames()) 2. We iterate over those names (enum) to get their values while(enum.hasmoreelements()) { st=(string) enum.nextelement(); out.println(st+" : "+request.getheader(st)); } 29

31 Intro. to Web applications in Java. 3- Servlets. Example 3 Example 3: Parameter capture by name. The form Example location: introapweb/examples/ex3.3 This example will be deployed at chapter 5 (Deployment). See example 5.1 <html> <h1><b>pactador automatic </b></h1> <form action=" method="get"> <b>nom o pseudonim:</b> <input name="nom" type="text" size=50> <p> <b>pacte preferit (selecciona almenys 2 opcions):</b> <input name="pacte" type="checkbox" value="psc"> PSC <input name="pacte" type="checkbox" value="ciu"> CiU <input name="pacte" type="checkbox" value="erc"> ERC <input name="pacte" type="checkbox" value="icv"> ICV <p> <p> <input type="submit" value="enviar"></textarea> <input type="reset" value="reiniciar"></textarea> </form> </html> 30

32 Intro. to Web applications in Java. 3- Servlets. Example 3 Example 3: Parameter capture by name. The servlet import javax.servlet.*; import java.io.*; import javax.servlet.http.*; import java.util.*; public class Parameter extends HttpServlet { private static final String PAGE_TOP= "<html>"+ "<head>"+ "<title>parameter capture in an http request</title>"+ "</head>"+ "<body bgcolor=\"white\">"+ "<h1> Parameter capture in an http request </h1>"+ "<pre>" ; private static final String PAGE_BOTTOM= " </pre>" + " </body>"+ " </html>" ;...(cont) 31

33 Intro. to Web applications in Java. 3- Servlets. Example 3 public void doget(httpservletrequest request, HttpServletResponse response) throws IOException, ServletException { dopost( request, response ) ; }...(cont) 32

34 Intro. to Web applications in Java. 3- Servlets. Example 3 public void dopost (HttpServletRequest request, HttpServletResponse response) { String[] partits; Enumeration enum; String st=new String(); try { response.setcontenttype("text/html"); PrintWriter out = response.getwriter(); out.println (PAGE_TOP); out.println("<b>capture of the parameter names:</b>" +"<br><br>"); enum=request.getparameternames(); while(enum.hasmoreelements()) { st=(string) enum.nextelement(); out.println("name="+st); } out.println("<b>capture of the parameter values:"+ "</b><br><br>"); out.println("parameter name= nom ----> Value="+ request.getparameter("nom")); out.println("parameter name= pacte ----> Values="); partits=request.getparametervalues("pacte"); for(int i=0;i<partits.length;i++){ out.println("partit "+i+": "+partits[i]); } } catch (Exception ex) { ex.printstacktrace();} }} 33

35 Intro. to Web applications in Java. 3- Servlets. Example 3 Example 3: Parameter capture by name. Remarks The action associated to the form is the servlet URI: <form action=" The way to map a servlet class (Parameter.class) with a specific URI: is presented in sections 2.4 and 2.5 Parameters may have a collection of values (e.g., pacte).notice the way in which we access all the values of that parameter: partits=request.getparametervalues("pacte"); for(int i=0;i<partits.length;i++){ out.println("partit "+i+": "+partits[i]); } 34

36 Intro. to Web applications in Java. 3- Servlets. Example 3 Compilation and execution of a servlet This is presented in chapter 5 35

37 Intro. to Web applications in Java. 3- Servlets. Intro to JSP JSP pages. Difficulties with servlets A servlet manages the creation of a web page through its output stream in a way which is non-intuitive and difficult to generate and to maintain: Both the static and the dynamic elements of the web page are managed by the same code Static elements: Those elements that do not change in the resulting page through different requests (e.g., page headers and footers, table structure...) Dynamic elements: Those elements that depends on the parameters of the request and may change in different requests (e.g., table contents) Page contents are generated by means of calls to usual output methods (e.g., println...), which are combined with other programming instructions. The structure of the resulting page is obscure. Each servlet is a complete class with several methods and a complex lifecycle. 36

38 Intro. to Web applications in Java. 3- Servlets. Intro to JSP JSP pages. A solution Idea: Do not program servlets directly, but a JSP web page What is a JSP web page It is a usual web page written in html that incorporates some dynamic elements (e.g., java expressions, java code, tag actions and java beans). A JSP page is translated automatically into a servlet. When the JSP page is requested, the servlet associated to it is executed. The result of the execution of that servlet is an html page that contains: The static (html) code of the JSP page The result of the execution of the java expressions and code of its dynamic part JSP pages are executed within a JSP container. TOMCAT is a servlet and JSP container 37

39 Intro. to Web applications in Java. 3- Servlets. Intro to JSP JSP pages. How do they work hello.jsp NO is there a servlet for hello.jsp? YES Translate into a servlet hello.jsp >hello_jsp.java NO is the servlet more recent than hello.jsp? Compile hello_jsp.java > hello_jsp.class YES Create an object obj of the class hello_jsp.class NO is there already an object obj of hello_jsp.class? send the request to obj YES 38

40 Intro. to Web applications in Java. 3- Servlets. Intro to JSP The first JSP page page import="java.io.*,java.text.*,java.util.*"%> <HTML> <head> <title> First JSP page </title> </head> <body> <h3> First JSP page </h3> <p>hello... <p>1+2= <% int p; p=1+2; %> <%=p%> </body> </html> 39

41 Intro. to Web applications in Java. 3- Servlets. Intro to JSP Servlets. Advanced topics Filters Event listeners Servlets and concurrency Important: You can skip these sections in a first reading. In order to understand them you should be familiar with web application deployment, sessions and scopes. 40

42 Intro. to Web applications in Java. 3- Servlets. Intro to JSP Filters Sorry, ongoing work... See: i18n module of these notes provide an example that uses filters 41

43 Intro. to Web applications in Java. 3- Servlets. Intro to JSP Event listeners Event listeners are Java classes that manage events that take place during the web application execution These events may concern To the web application itself These events are called application-level events or servlet context-level events (Recall that a single servlet context is associated with each application) Examples of these sort of events: The application has started and is ready to receive requests The application is about to be undeployed and therefore its ServletContext is about to be destroyed One attribute associated to the application level has been added/modified/removed (e.g, set/getattribute(...)) 42

44 Intro. to Web applications in Java. 3- Servlets. Intro to JSP To one session that is executed within the web application These events are called HttpSession events (Sessions are presented in ****) Examples of these sort of events: A specific session has started A session has been cancelled or has expired One attribute associated to the session level has been added/modified/removed In which cases can be useful to manage events associated to sessions or the own application? Examples: Annotate log information Duration of a session, number of sessions that have been initiated in a day, user counter... Create a database connection when the application is deployed, so that it can be shared by all the servlets of the application and destroy it when the application is shut down 43

45 Intro. to Web applications in Java. 3- Servlets. Intro to JSP Notice that the events of each category (Application or HttpSession) may have two different origins: A life cycle event Examples: a session has initiated/expired; an application has started/is about to be shutdown An attribute event Examples: A session/application attribute has been created/modified/removed 44

46 Intro. to Web applications in Java. 3- Servlets. Intro to JSP The servlet API provides interfaces with methods to manage each one of the four types of events: ServletContext events HttpSession events life-cycle evts intfc: ServletContextListener intfc: HttpSessionListener mthd: contextdestroyed(), mthd: contextinitialized() mthd: sessioncreated(), mthd: sessiondestroyed() attrib. chge evts intfc: ServletContextAttributeListener intf:httpsessionattributelistener mthd: attributeadded() mthd: attributeremoved() mthd: attributereplaced() This table should be read like this: mthd: attributeadded() mthd: attributeremoved() mthd: attributereplaced() In order to manage the ServletContext events of kind life-cycle it is necessary to implement the methods contextdestroyed(...) and contextinitialized(...) of the interface ServletContextListener 45

47 Intro. to Web applications in Java. 3- Servlets. Intro to JSP When an application is deployed (this is a life-cycle application event), if that application contains a class that implements the interface ServletContextListener, the method contextinitialized(...) of that class will be executed Therefore, in order to manage the event consisting in an application being deployed, the interface ServletContextListener and, in particular, the method contextinitialized(..) must be implemented 46

48 Intro. to Web applications in Java. 3- Servlets. Intro to JSP Which steps should be followed in order to listen to events? 1. Decide which events you are interested in listen to 2. Implement the corresponding interface/s and its/their methods 3. Register the listener in the web.xml file This step is important since the servlet container must create an instance for each listener class that has been implemented and, in addition, must register these classes as listeners of the corresponding events 47

49 Intro. to Web applications in Java. 3- Servlets. Intro to JSP Example Example location: introapsweb/examples/ex3.4 Goal of the example: Gather information about the number of currently active sessions, the total number of sessions that have been initiated since the application was deployed and the duration of each session. Log that information 48

50 Intro. to Web applications in Java. 3- Servlets. Intro to JSP Steps: 1. Decide which events you are interested in listen to Two counters will be needed: totalsessioncounter To keep the total number of sessions that have been initiated since the application deployment activesessioncounter To keep the number sessions that are currently active. Both counters will be declared as application attributes, since they need to work throughout the entire life-cycle of the application. They will be initialized when the application starts up (ServletContextListener.contextInitialized) and will be removed when it is destroyed (ServletContextListener.contextDestroyed) These counters will be udpated when sessions are created and destroyed. Therefore, HttpSessionListener.sessionCreated and HttpSessionListener.se should also be implemented 49

51 Intro. to Web applications in Java. 3- Servlets. Intro to JSP 2. Implement the corresponding interface/s and its/their methods 50

52 Intro. to Web applications in Java. 3- Servlets. Intro to JSP public class SessionCounter implements ServletContextListener, HttpSessionListener { ServletContext servletcontext; public SessionCounter() {} /* Methods from the ServletContextListener */ public void contextinitialized(servletcontextevent scevt { servletcontext = scevt.getservletcontext(); } servletcontext.setattribute ("totalsessioncounter",new Integer(0) servletcontext.setattribute ("activesessioncounter",new Integer(0 public void contextdestroyed(servletcontextevent scevt) { } servletcontext.removeattribute("totalsessioncounter") servletcontext.removeattribute("activesessioncounter" 51

53 Intro. to Web applications in Java. 3- Servlets. Intro to JSP /* Methods for the HttpSessionListener */ public void sessioncreated(httpsessionevent sevt) { Integer totalsessions = ((Integer)servletContext. getattribute("totalsessioncounter")); servletcontext.setattribute("totalsessioncounter", new Integer(totalSessions.intValue()+1) Integer activesessions = ((Integer)servletContext. getattribute("activesessioncounter") servletcontext.setattribute("activesessioncounter", new Integer(activeSessions.intValue()+1) servletcontext.log("session CREATION"); } 52

54 Intro. to Web applications in Java. 3- Servlets. Intro to JSP public void sessiondestroyed(httpsessionevent sevt) { Integer activesessions = ((Integer)servletContext. getattribute("activesessioncounter")) servletcontext.setattribute("activesessioncounter", new Integer(activeSessions.intValue()-1 HttpSession session = sevt.getsession(); long start = session.getcreationtime(); long end = session.getlastaccessedtime(); } servletcontext.log("session DESTRUCTION, Session Duratio + (end - start)); } 53

55 Intro. to Web applications in Java. 3- Servlets. Intro to JSP 3. Register the listener in the web.xml file In the web.xml file, this registration should be added: <listener> <listener-class>sessioncounter</listener-class> </listener> 54

56 Intro. to Web applications in Java. 3- Servlets. Intro to JSP Servlets and concurrency Instance attributes of a servlet are not concurrentsafe Servlets are multithreaded Each client request is assigned by the servlet container to a new thread (usually from a pool of threads) This thread is associated with a reference to an existing servlet instance As a result, various concurrent requests to the same servlet can be managed by the same servlet instance thus accessing the same instance attributes Resources shared by different (or the same) servlets are not concurrent-safe Different servlets or different instances of the same servlet may access concurrently to the same resources Which are these shared resources? Static attributes Scoped attributes Servlets may access to attributes defined in the servlet context or session scopes 55

57 Intro. to Web applications in Java. 3- Servlets. Intro to JSP (e.g.: getservletcontext.setattribute("maxproducts",mp); ) The servlet context is shared by all the servlets of a (non-distributed) web application Extern resources Connection to networks or databases 56

58 Intro. to Web applications in Java. 3- Servlets. Intro to JSP How to solve this problem Make the servlet implement the SingleThreadModel interface The servlet container will grant only one thread per servlet instance. That is: one request per servlet instance public class MyServlet extends HttpServlet implements SingleThreadModel {...} However: This does not prevent problems that arise from concurrent access to static or scoped attributes This interface has been deprecated Use the Java synchronization mechanisms on the concurrently accessed objects E.g. Use the synchronized element 57

59 Intro. to Web applications in Java. 3- Servlets. Intro to JSP References Servlet specification Servlet API 58

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 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

6- JSP pages. Juan M. Gimeno, Josep M. Ribó. January, 2008

6- JSP pages. Juan M. Gimeno, Josep M. Ribó. January, 2008 6- JSP pages Juan M. Gimeno, Josep M. Ribó January, 2008 Contents Introduction to web applications with Java technology 1. Introduction. 2. HTTP protocol 3. Servlets 4. Servlet container: Tomcat 5. Web

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

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

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

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

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

&' () - #-& -#-!& 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

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

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

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

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

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

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

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

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

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

Servlets. An extension of a web server runs inside a servlet container 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

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

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

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

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

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

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

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

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

Questions and Answers

Questions and Answers Q.1) Servlet mapping defines A. An association between a URL pattern and a servlet B. An association between a URL pattern and a request page C. An association between a URL pattern and a response page

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

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

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

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 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

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 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

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

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

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

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

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

The Servlet Life Cycle

The Servlet Life Cycle The Servlet Life Cycle What is a servlet? Servlet is a server side component which receives a request from a client, processes the request and sends a content based response back to the client. The Servlet

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

Table of Contents. Introduction... xxi

Table of Contents. Introduction... xxi Introduction... xxi Chapter 1: Getting Started with Web Applications in Java... 1 Introduction to Web Applications... 2 Benefits of Web Applications... 5 Technologies used in Web Applications... 5 Describing

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

Introduction to JSP and Servlets Training 5-days

Introduction to JSP and Servlets Training 5-days QWERTYUIOP{ Introduction to JSP and Servlets Training 5-days Introduction to JSP and Servlets training course develops skills in JavaServer Pages, or JSP, which is the standard means of authoring dynamic

More information

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

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

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

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

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

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

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

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

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

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

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

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

Oracle Containers for J2EE

Oracle Containers for J2EE Oracle Containers for J2EE Servlet Developer's Guide 10g (10.1.3.1.0) B28959-01 October 2006 Oracle Containers for J2EE Servlet Developer s Guide, 10g (10.1.3.1.0) B28959-01 Copyright 2002, 2006, Oracle.

More information

Fast Track to Java EE 5 with Servlets, JSP & JDBC

Fast Track to Java EE 5 with Servlets, JSP & JDBC Duration: 5 days Description Java Enterprise Edition (Java EE 5) is a powerful platform for building web applications. The Java EE platform offers all the advantages of developing in Java plus a comprehensive

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

SCWCD Study Guide Exam: CX

SCWCD Study Guide Exam: CX SCWCD Study Guide Exam: CX-310-081 Book: Head First Servlets & JSP Authors: Bryan Basham, Kathy Sierra, Bert Bates Abridger: Barney Marispini CHAPTER 1 (Overview) HTTP HTTP stands for HyperText Transfer

More information

Java Programming Course Overview. Duration: 35 hours. Price: $900

Java Programming Course Overview. Duration: 35 hours. Price: $900 978.256.9077 admissions@brightstarinstitute.com Java Programming Duration: 35 hours Price: $900 Prerequisites: Basic programming skills in a structured language. Knowledge and experience with Object- Oriented

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

Construction d Applications Réparties / Master MIAGE

Construction d Applications Réparties / Master MIAGE Construction d Applications Réparties / Master MIAGE HTTP and Servlets Giuseppe Lipari CRiSTAL, Université de Lille February 24, 2016 Outline HTTP HTML forms Common Gateway Interface Servlets Outline HTTP

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

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

Chettinad College of Engineering and Technology CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND TECHNOLOGY

Chettinad College of Engineering and Technology CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND TECHNOLOGY CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND TECHNOLOGY UNIT IV SERVLETS 1. What is Servlets? a. Servlets are server side components that provide a powerful mechanism

More information

CS506 Web Design & Development Final Term Solved MCQs with Reference

CS506 Web Design & Development Final Term Solved MCQs with Reference with Reference I am student in MCS (Virtual University of Pakistan). All the MCQs are solved by me. I followed the Moaaz pattern in Writing and Layout this document. Because many students are familiar

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

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

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

How does the Web work? HTTP and the Dynamic Web. Naming and URLs. In Action. HTTP in a Nutshell. Protocols. The canonical example in your Web browser

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

More information

SWE642 Oct. 22, 2003

SWE642 Oct. 22, 2003 import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.arraylist; DataServlet.java /** * First servlet in a two servlet application. It is responsible

More information

INTERNET PROGRAMMING TEST-3 SCHEME OF EVALUATION 1.A 3 LIFE CYCLE METHODS - 3M 1.B HTML FORM CREATION - 2 M

INTERNET PROGRAMMING TEST-3 SCHEME OF EVALUATION 1.A 3 LIFE CYCLE METHODS - 3M 1.B HTML FORM CREATION - 2 M INTERNET PROGRAMMING TEST-3 SCHEME OF EVALUATION 1.A 3 LIFE CYCLE METHODS - 3M EXPLANATION - 1.B HTML FORM CREATION - 2 M SERVLET CODE IN POST METHOD IMPORT STATEMENTS - CLASS NAME AND METHOD (POST) -

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

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

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes Java CORE JAVA Core Java Programing (Course Duration: 40 Hours) Introduction to Java What is Java? Why should we use Java? Java Platform Architecture Java Virtual Machine Java Runtime Environment A Simple

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

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

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1 Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1 Introducing Object Oriented Programming... 2 Explaining OOP concepts... 2 Objects...3

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

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-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

A Servlet-Based Search Engine. Introduction

A Servlet-Based Search Engine. Introduction A Servlet-Based Search Engine Introduction Architecture Implementation Summary Introduction Pros Suitable to be deployed as a search engine for a static web site Very efficient in dealing with client requests

More information

Web Technology Programming Web Applications with Servlets

Web Technology Programming Web Applications with Servlets Programming Web Applications with Servlets Klaus Ostermann, Uni Marburg Based on slides by Anders Møller & Michael I. Schwartzbach Objectives How to program Web applications using servlets Advanced concepts,

More information

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started Application Development in JAVA Duration Lecture: Specialization x Hours Core Java (J2SE) & Advance Java (J2EE) Detailed Module Part I: Core Java (J2SE) Getting Started What is Java all about? Features

More information

HTTP. HTTP HTML Parsing. Java

HTTP. HTTP HTML Parsing. Java ђѕђяѡъ ьэющ HTTP HTTP TCP/IP HTTP HTTP HTML Parsing HTTP HTTP GET < > web servers GET HTTP Port 80 HTTP GOOGLE HTML HTTP Port 80 HTTP URL (Uniform Resource Locator) HTTP URL http://www.cs.tau.ac.il:80/cs/index.html

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

Module 3 Web Component

Module 3 Web Component Module 3 Component Model Objectives Describe the role of web components in a Java EE application Define the HTTP request-response model Compare Java servlets and JSP components Describe the basic session

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

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

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

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 And JSP. Mr. Nilesh Vishwasrao Patil, Government Polytechnic, Ahmednagar. Mr. Nilesh Vishwasrao Patil

Servlet And JSP. Mr. Nilesh Vishwasrao Patil, Government Polytechnic, Ahmednagar. Mr. Nilesh Vishwasrao Patil Servlet And JSP, Government Polytechnic, Ahmednagar Servlet : Introduction Specific Objectives: To write web based applications using servlets, JSP and Java Beans. To write servlet for cookies and session

More information

Advanced Internet Technology Lab # 5 Handling Client Requests

Advanced Internet Technology Lab # 5 Handling Client Requests Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2011 Advanced Internet Technology Lab # 5 Handling Client Requests Eng. Doaa Abu Jabal Advanced Internet Technology Lab

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

Université du Québec à Montréal

Université du Québec à Montréal Laboratoire de Recherches sur les Technologies du Commerce Électronique arxiv:1803.05253v1 [cs.se] 14 Mar 2018 Université du Québec à Montréal How to Implement Dependencies in Server Pages of JEE Web Applications

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

Java Technologies Web Filters

Java Technologies Web Filters Java Technologies Web Filters The Context Upon receipt of a request, various processings may be needed: Is the user authenticated? Is there a valid session in progress? Is the IP trusted, is the user's

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

LTBP INDUSTRIAL TRAINING INSTITUTE

LTBP INDUSTRIAL TRAINING INSTITUTE Java SE Introduction to Java JDK JRE Discussion of Java features and OOPS Concepts Installation of Netbeans IDE Datatypes primitive data types non-primitive data types Variable declaration Operators Control

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