Introduction to Server-Side Technologies

Size: px
Start display at page:

Download "Introduction to Server-Side Technologies"

Transcription

1 Introduction to Java Servlets Table of Contents Introduction to Server-Side Technologies Dynamic Generation of Web Pages Basic Technology Behind Dynamic Web Pages Getting Started with Java Servlets Installing Apache Tomcat Compiling and Deploying Java Servlets in Tomcat Template Servlet Structure Hello World Servlet Handling Requests with Servlets HTTP Request Headers Handling HTML forms Bibliography Introduction to Server-Side Technologies Dynamic Generation of Web Pages Web-based information systems support remote access to Web pages. The Web pages served by such systems come in two flavours. Either they can be static Web pages that are stored and served as files on the server file system, or they can be generated dynamically on the server side. The dynamic Web pages may be generated as a response to a search query, database query, or purchase request submitted by a user of the system. Generally, there are few reasons for dynamic generation of Web pages [HallBrown2003]: Web pages are based on user queries, e.g. result pages of search engines, shopping carts in online shops, and so on. The data managed by the system changes often, e.g. wheather forecast sites, news tickers, and similar. Web pages are based on data from a database system, e.g. students data from university databases, online flight reservation, etc. There exist a number of server-side technologies for dynamic generation of Web pages. The basic server-side technology is CGI (Common Gateway Interface). It is actaully a standardized specification [CGI1995] of communication between a Web server and external programs. Thus, an external CGI program runs directly on the server side and generates a dynamic Web page. The Web server invokes the external program by passing parameters to it (e.g. user query). The generated Web page is passed back from the external CGI program to the Web server, which in turn forwards the page to the user. All

2 the communication between the Web server and external program is carried using the standard input and output streams. The simplicity of the CGI specification and the fact that CGI programs can be written in any programming language lead to a widespread of CGI-based applications. However, CGI programs have a number of serious drwabacks. The major drawback of CGI programs is the performance issue. Since CGI programs are external programs, the operating system starts a new process for each request to a CGI program. This of course bring the performance costs. Further, there is no possibility for a CGI program to keep database connections open over a number of requests. For each request a new database connection must be established, which leads to significant performance costs in database centric applications. Sun's answer to the CGI technology are Java servlets. Java servlets are Java programs running on the side of a Web server and producing dynamic Web pages. Similar to the CGI specification the Java Servlet Specification [JavaServlet2003] standardized how Java programs run and communicate with a Web server to produce dynamic Web pages. The result of the specification is the Java Servlet Application programming interface (API), which is a Java library with classes needed to write Java servlets that produce dynamic Web pages. The current version of the Java servlet Specification and Java Servlet API is 2.3. The version 2.4 has currently the status of a proposed draft. The reference implementation of the Java Servlet Specification is Apache Tomcat [Tomcat1999]. The version of Tomcat implements the Java Servlet Specification 2.3. Actually, Tomcat is a so-called servlet engine, which is a Java program that provides an execution context for a number of Java servlets, which run within separate Java threads inside the Tomcat process. Tomcat provides all the communicational functions between servletsand Web server, as specified in the Java Servlet Specification. Java servlets have a number od advantages over traditional CGI technologies for generating dynaimc content on the Web. These advantages include [HallBrown2003]: Efficiency. As mentioned before, for each request for a CGI program the operating system starts a new process to handle that request. In the case of Java servlets, there is only one process, that of the servlet engine. Each Java servlet is just a thread running within the context of the servlet engine process. Of course, starting and stopping a thread costs a lot less in terms of performance than starting and stopping of an operating system process. Especially, if the execution time is small. Java servlets are also more efiicient in terms of memory usage. Thus, in the case of multiple synchronous requests for a single servlet the servlet code is loaded only once and multiple threads are started with the same code. Contrary to that for multiple requests for a CGI program, the operating system must load the code as many times as there are requests. Finally, servlets can keep track of consecutive requests, and store some internal data that help improving performance. For instance, servlets can keep database connections open and thus reduce greatly costs of establishing a connection with a database with each new request.

3 High capability. Servlets can share their data, which makes it possible to implement database connection pools, thus greatly reducing costs of establishing database connections, not only within one servlets but among a number of servlets. Further, servlets can keep information from one request to another, making it possible to easy track user's session, cache results from previous computations, and so on. Finally, servlets can talk directly to the Web server and access its data stored in standard places. Portability. Servlets are Java programs written using a standardized API. Thus, servlets written for one platform may be easily ported to another without no need for changing them. Servlet engines are available for all major platforms and all major Web server products. Java software libraries. Since servlets are Java programs they can use the standard Java API or any other Java library available. Thus, libraries for manipulating connections with database managment systems (JDBC libraries), libraries for manipulating digital images, Java XML libraries, etc. are all accessible in Java servlets. Basic Technology Behind Dynamic Web Pages The Web utilizes a classical client-server architecture. Thus, a Web client sends a request over the Internet to a Web server asking it for a specific Web page. To address a Web page the client specify its Uniforme Resource Locator (URL) to the server. Communication between the client and the server is carried out by means of HyperText Transfer Protocol (HTTP). HTTP is a simple text-based protocol. An HTTP request in its simple case can consist of a single request line containing only GET keyword together with the URL of a Web page. As the answer to this simple request the server will respond by sending the requested page back to the client. In the general case, an HTTP request consists of: Request line, which contains an HTTP method (usually GET or POST) and a URL. GET method just retrieves the data from the server, whereas POST method implies that the client sends data to the server. A number of HTTP headers, which set properties of connection between the client and server. For example, Accept header specifies which MIME types are preferred by the client, Accept-Language header specifies which language is preferred by the client if the server has versions of the requested page in different languages, User-Agant specifies type of the client (browser), and so on. All HTTP headers are optional, except Content-Length header, which is required for POST method to specify how much data is sent from the client to the server. Content, that is data sent by the client to the server in the case of POST method. Mostly, dynamic Web pages are generated in accordance with parameters sent by users to a Web server. For instance, to submit a search query to a search engine users type in their serach terms in an HTML form and press the submit button to send the data. HTTP utilizes two possibities to send such parameters from the client to the server:

4 With GET method parameters are encoded in the URL included in the request line. Parameters are submitted as key-value pairs connected with equal '=' sign. Multiple paramaters are separated with ampersand '&' sign. Spaces are encoded as plus '+' sign, and special characters are encoded as a hexidecimal value preceeded with percentage '%' sign. The encoded parameters are preceeded with a question mark '?' sign and attached to the original URL. A typical example of encoding user parameters in URL looks as follows. Example 1. Encoding Parameters in URL 8&hl=de&btnG=Google+Suche&meta= With the above URL parameters for a search query are sent to the Google search engine. The parameters come in key-value pairs: q=java Servlets, ie=utf-8, oe=utf-8, hl=de, btng=google Suche, and meta parameter has no value. Since the length of a URL is limited to 1024 bytes this method allows only limited number of parameters to be transmitted. With POST method parameters are sent as the content of the request. The length of the content is specified as a special Content-Length HTTP header. POST method allows sending of binary data as content, or even mixed binary and text data as content. This is very often used for uploading binary data, such as digital images, compressed files, etc. to the server. On the client side POST method is usually applied within HTML forms. Here is a typical example of such an HTML form. Example 2. POST Method with HTML Form <form action =" method="post"> First Name: <input type="text" name="name" size="20" maxlength="50"> Second Name: <input type = "text" name = "second_name" size = "20" maxlength = "50"> Matrikel Number: <input type = "text" name = "nr" size = "20" maxlength = "50"> Study Field: <select name="study_field"> <option value="f874">telematics <option value="f860">technical Mathematics <option value="f033523">software Development <option value="f033211">telematics Bachelor <option value="f033221">geomatics </select> <input type="submit" value="register"> </form>

5 Thus, parameters sent to the server are name, second_name, nr, and study_field. Getting Started with Java Servlets Installing Apache Tomcat The first step in working with Java servlets is installing the software, so-called servlet engine, that implements the Java Servlet Specification and provides the Java Servlet API. The reference implementation of servlet engine is Apache Tomcat [Tomcat1999]. The current version of Apache Tomcat is Apache Tomcat is an open source software product released under Apache Software Licence [Apache2000]. Installing Apache Tomcat is quite simple. Firstly, the appropriate version for the operating system must be downloaded. All Apache Tomcat versions might be obtained as source files, or as precompiled binary files. Building the system from source files requires some additional software, which can be obtained from the Apache Java Web site [Jakarta2003]. The complete instructions for buliding and installing Apache Tomcat from the source files can be found on Apache Tomcat Web site. On the other hand, installing the binary version of the system can be accomplished in only few steps. For both Linux and Windows operating systems a similar installation procedure might be applied. Here the Linux procedure is explained, to install the system on Windows some small modifications are needed (e.g. *.bat files instead of *.sh files, c:\tomcat instead of /tomcat, etc.). Decompress the downloaded binary archive into a directory in your file system, lets say in "/tomcat" directory. Change to /tomcat/bin directory and make the start and stop scripts (startup.sh and shutdown.sh) executable. Invoke the start and stop scripts to start/stop the system. Example 3. Installing Tomcat on a Linux machine #installation in directory /tomcat cd /tomcat tar xzf <path-to-tomcat-binary-archive>/jakarta-tomcat tar.gz cd jakarta-tomcat #make scripts executable chmod +x bin/*.sh #start tomcat (windows: use bin/startap.bat) bin/startup.sh #stop tomcat (windows: use bin/shutdown.bat) bin/shutdown.sh

6 There is a Windows installer version available for Windows operating system. To install the system with this binary distribution just double click on the downloaded executable archive and follow the instructions on the screen. A nice feature of this distribution for Windows XP/2000/NT operating system is that the system is automatically installed as a Windows service, which may be controlled from the Managment Console available in Control Panel. Once when the system is running it can be accessed with a standard Web browser under or Compiling and Deploying Java Servlets in Tomcat Since Java servlets are typical Java programs to compile them you must use a standard Java compiler. The CLASSPATH environment variable must include the Java Servlet API, which comes with Apache Tomcat. The library is stored under the common/lib/servlet.jar in the Tomcat installation directory (e.g. /tomcat/common/lib/servlet.jar). After compiling all necessery Java source files servlets need to be deployed in Tomcat. Apache Tomcat works with so-called Web applications. A Web application is a collection of one or more servlets combined with external Java libraries, static resources such as digital images, static HTML pages, etc. to provide a specific functionality. For instance, online shopping application might be realises as a Tomcat Web application. Each Tomcat Web application has the same predefined structure: All Web applications are stored as directories under the webapps directory (e.g. /tomcat/webapps) directory of the Tomcat installation. Web application name is identical with the name of its directory, e.g. a Web application called "onlineshop" is stored in the directory called online-shop (e.g. /tomcat/webapps/onlineshop) and it is accesible via or Static resources of a Web application (e.g. HTML pages, images, etc.) are stored in the Web application directory. There is a special subdirectory called WEB-INF of the Web application directory, e.g. /tomcat/webapps/online-shop/web-inf. The WEB-INF directory contains two subdirectories: classes (e.g. /tomcat/webapps/online-shop/web-inf/classes) and lib (e.g. /tomcat/webapps/web-inf/online-shop/lib) directory. The first of these two subdirectories contains all Java class files required to run a particular Web application. The lib directory contains external Java libraries (e.g. Java archive - jar files) needed to run the Web application. For example, if the Web application connects to a database managment system, the Java library (JDBC driver) needed to establish the connection is placed in the lib directory. There is a special file called web.xml in the WEB-INF directory. This file includes all configuration directives for a particular Web application, in the form of key-value parameters that are paased to a servlet when it is initialized. For

7 example, the username and password for a user of the backend database managment system might be defined in the web.xml file. Further, in this file the typical description of all Java servlets from a particular Web application is provided. This description includes the unique servlet name, name of the Java servlet class, and a number od additional servlet attributes, such as URL mapping for the servlet, and so on. Example 4. Template Structure of Tomcat Web Application -tomcat -webapps -online-shop -WEB-INF -web.xml -lib -*.jar (e.g. mysqlconnector.jar) -classes -*.class (e.g. ShopingCartServlet.class) -*.htm (e.g. navigation.html) -*.gif, *.jpg (e.g. shopping_cart.jpg) Example 5. Typical web.xml file <?xml version="1.0" encoding="iso "?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" " <web-app> <servlet> <servlet-name>shopping Cart</servlet-name> <description>keeps track of items that user bought</description> <servlet-class>shoppingcartservlet</servlet-class> <init-param> <param-name>database-username</param-name> <param-value>dhelic</param-value> </init-param> </servlet> <servlet-mapping>

8 <servlet-name>shopping Cart</servlet-name> <url-pattern>basket</url-pattern> </servlet-mapping> </web-app> Template Servlet Structure The Java Servlet API [JavaServletAPI2003] a number of Java classes which are used for developing of Java servlets. This API consists of two Java packages: javax.servlet and javax.servlet.http. The first package contains Java classes and interfaces which implement a generic servlet behavior, whereas the second javax.servlet.http package provides Java classes and interfaces that handle more specific servlet behaviour in an HTTP based environment. Thus, the most of the time programmers work with the classes from the second package. These two packages provide an object-oriented abstraction of the underlying networking technology. For example, to handle HTTP GET method programmers only need to implement a method in a Java class, to obtain parameters sent by a user they call methods on a high-level Java object representing the request sent by the user, and so on. A Java servlet is a normal Java class which is defined as a subclass of the abstract class HttpServlet from the javax.servlet.http package. The abstract HttpServlet class has a number of public methods, each of them corresponding to an HTTP method, such as GET or POST method. A subclass of the Http Servlet class must implement at least one of these methods to handle the corresponding HTTP method. Here are some of the most important methods from the public interface of the HttpServlet class: doget() method, for handling HTTP GET requests dopost() method, for handling HTTP POST requests dodelete() method, for handling HTTP DELETE requests doput() method, for handling HTTP PUT requests Usually, for generation of dynamic Web pages doget() and/or dopost() methods are implemented. These methods are called by the servlet engine whenever an HTTP request with the corresponding HTTP method is issued to the server. Normally, the servlet engine handles only a single instance of a particular Java servlet. For each new request to this servlet the sevlet engine starts a new thread and invokes the corresponding method of the servlet within the execution context of the new thread. In the most simple case a Java servlet only implements doget() method. Thus, we can create a template servlet structure, which can be used for a rapid devlopment of Java servlets. The following code can be used as such template servlet. Example 6. Template Servlet * Template Servlet

9 * import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import javax.servlet.http.httpsession; import java.io.ioexception; import java.io.printwriter; public class TemplateServlet extends HttpServlet{ // * Handles HTTP GET method. request HTTP request response HTTP response ServletException IOException public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException{ // Use "request" to read incoming parameters, e.g. request.getparameter("query"); // Use "response" to write HTTP headers PrintWriter writer = response.getwriter(); // Use "writer" to send response to the client Two new classes appeared in the above example: HttpServletRequest and HttpSercletResponse class. These two classes provide an abstraction of the HTTP request and response, respectivelly. Thus, they provide methods to obtain parameters submitted by users (e.g. getparameter(name) method of the HttpServletRequest class), to write response to the client (e.g. getwriter() method of the HttpServletResponse class that returns a writer stream for writing response to the client), and similar. Hello World Servlet As the next example that does something useful (e.g. prints HelloWorld with today's date in browser ;=)) we will implement the famous Hello World example. Of course, we will reuse the above template servlet structure and extend it to implemt our desired functionality.

10 Example 7. Hello World Servlet * Hello World Servlet * import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import javax.servlet.http.httpsession; import java.io.ioexception; import java.io.printwriter; import java.util.date; public class HelloWorldServlet extends HttpServlet{ // * Handles HTTP GET method. Sends "HelloWorld" as response to the client. request HTTP request response HTTP response ServletException IOException public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException{ String hello = "Hello World"; response.setcontenttype("text/html"); // set mime type of the response PrintWriter writer = response.getwriter(); writer.println("<html>"); writer.println("\t<head>"); writer.println("\t\t<link rel = \"stylesheet\" type = \"text/css\" href = \"style.css\">"); writer.println("\t\t<title>" + hello + "</title>"); writer.println("\t</head>"); writer.println("\t<body>"); writer.println(hello + " (" + (new Date()) + ")"); writer.println("\t</body>"); writer.println("</html>"); The Hello World example is accessible online at The source code is also avaliable onlne: HelloWorldServlet.java.

11 The first thing we do in the Hello World example is that we set type of the response. To do so we invoke response.setcontenttype() method and provide a mime type as a string argument (e.g. "text/html"). This method sets a corresponding header in the HTTP response, so that the client (e.g. Web browser) knows what kind of data it gets. In our case that data is of course an HTML page. Finally, in the Hello World example we obtain the writer stream of the response object and write our HTML page to that stream. Writing an HTML page to the writer stream requires writing all HTML tags that constitute a valid HTML page to the writer. The first thing to notice in the Hello World example is that writing a servlet is usually related with writing a (possibly) large number of writer.println() statements to produce a valid HTML. Moreover, if we have a number of servlets, or a number of methods that write out HTML we usually end up with a lot of repeating writer.println() statements (e.g. writing document head, style sheet elements, ect.). To simplify the above process the so-called Element Construction Set [ECS2003] was developed within the scope of Apache Jakarta Project [Jakarta2003]. The Element Construction Set supports generation of HTML without need for numerous writer.println() statements. To make your servlets aware of the Element Construction Set you need to add the Java library implementing the Element Construction Set into the lib directory of your web application WEB-INF directory (e.g. /tomcat/webapps/hello/web- INF/lib). The Element Construction Set (ECS) might be obtained from the Example 8. Hello World Servlet with ECS * Hello World Servlet with ECS * import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import javax.servlet.http.httpsession; import org.apache.ecs.document; import org.apache.ecs.doctype; import org.apache.ecs.doctype.html40strict; import org.apache.ecs.html.body; import org.apache.ecs.html.head; import org.apache.ecs.html.title; import org.apache.ecs.html.link; import java.io.ioexception; import java.io.printwriter; import java.util.date;

12 public class ECSHelloWorldServlet extends HttpServlet{ // * Handles HTTP GET method. Sends "HelloWorld" as response to the client. request HTTP request response HTTP response ServletException IOException public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException{ String hello = "Hello World"; response.setcontenttype("text/html"); PrintWriter writer = response.getwriter(); Document document = new Document(); document.setdoctype(new Doctype.Html40Strict()); Title title = new Title(hello); document.settitle(title); Head head = document.gethead(); Body body = document.getbody(); Link link = new Link(); link.setrel("stylesheet"); link.settype("text/css"); link.sethref("style.css"); head.addelement(link); body.addelement(hello + " (" + (new Date()) + ")"); document.output(writer); The Hello World with ECS example is accessible online at The source code is also avaliable onlne: ECSHelloWorldServlet.java. In the new Hello World example we first need to import all the ECS specific classes, such as Document, Doctype.Html40Strict, Body, Title, Link, etc. In the doget() method we don't write directly to the writer stream, but rather create the response as an instance of the Document class, and add elements to that object. Thus, first we add a head element, which contains a title and a link element for a style sheet. At the next step, we add a body element containing our "Hello World" string together with the current date. Finally, we dump the document to the writer stream, thus sending the response to the client. At the first glance the ECS example does not look shorter or even simpler (we need also to learn how to use different ECS classes) than the first Hello World example, but the

13 Hello World example is actually to simple to really see the difference between a servlet with and without ECS. In larger projects, however, the ECS for sure pays off, since you can easily share ECS elements between methods or even between servlets, thus making it possible to reuse huge number of repeating HTML elements. For example, a link element that specifies a style sheet can be easily shared between methods and servlets, and most probably you will need only one link element (i.e. you need only one style sheet for a number of Web pages) for the whole application. Handling Requests with Servlets HTTP Request Headers Usually, each HTTP request contains a number of HTTP headers. The client sets HTTP headers to inform server about its communication preferences, about length of the content submitted, authorization information, cookies, and similar. The HttpServletRequest class represents a Java abstraction of HTTP request, thus providing high-level methods for investigating HTTP headers. The getheader() method accepts as an argument the name of a header and returns its value if the header was submittes by the client. If the header was not included in the client's request then this method returns null. The method getheadernames() returns an iterator over all header names that were submitted by the client. The next example prints out all HTTP request headers submitted by the client. Example 9. Printing HTTP Request Headers * HTTP Headers * import org.apache.ecs.document; import org.apache.ecs.doctype; import org.apache.ecs.doctype.html40strict; import org.apache.ecs.html.body; import org.apache.ecs.html.head; import org.apache.ecs.html.title; import org.apache.ecs.html.link; import org.apache.ecs.html.table; import org.apache.ecs.html.tr; import org.apache.ecs.html.th; import org.apache.ecs.html.td; import org.apache.ecs.html.p; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import javax.servlet.http.httpsession; import java.io.ioexception; import java.io.printwriter;

14 import java.util.date; import java.util.enumeration; public class HeaderServlet extends HttpServlet{ // * Handles HTTP GET method. Prints HTTP headers in an HTML table. HttpServletRequest request HttpServletResponse response ServletException IOException public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException{ response.setcontenttype("text/html"); PrintWriter writer = response.getwriter(); Document document = new Document(); document.setdoctype(new Doctype.Html40Strict()); Title title = new Title("Header Servlet"); document.settitle(title); Head head = document.gethead(); Body body = document.getbody(); Link link = new Link(); link.setrel("stylesheet"); link.settype("text/css"); link.sethref("style.css"); head.addelement(link); Table table = new Table(); // print headers in a table TR table_header = new TR(true); table_header.addelement((new TH(true)).addElement("Key")); table_header.addelement((new TH(true)).addElement("Value")); table.addelement(table_header); Enumeration parameters = request.getheadernames(); while(parameters.hasmoreelements()){ String key = (String) parameters.nextelement(); String value = request.getheader(key); TR table_row = new TR(true); table_row.addelement((new TD(true)).addElement(key)); table_row.addelement((new TD(true)).addElement(value)); table.addelement(table_row); P paragraph = new P(); paragraph.setneedclosingtag(true); paragraph.addelement("http Headers"); body.addelement(paragraph); body.addelement(table);

15 document.output(writer); // * Handles HTTP POST method. Just invokes goget() method. HttpServletRequest request HttpServletResponse response ServletException IOException public void dopost(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException{ doget(request, response); This example is accessible online at The source code is also avaliable onlne: HeaderServlet.java. In the above example we handle also the POST method. However, in the dopost() method we just invoke the doget() method passing parameters that we obtained for the POST request. This can be seen as a standard approach for handling these two methods. Thus, we only implement one of these methods and redirect the other to the implemented method. Of course, we need to take care about some specific issues of POST method, such as processing the data submitted with the POST request. The HttpServletRequest class provides also a number of methods that allow programmers to retrieve information about the context in which a servlet is running, as well as the context of the current request. These methods are further compatible with CGI environement variables, which are the part of the CGI specification. For example, these methods include: getauthtype() for retrieving the type of authorization if an authorization header was supplied. getcontentlength(), which gets the length of the content supplied with the POST method. The same information might be obtained by getheader("content- LENGTH") method, but since this information is very often needed this special method was implemented. getcontenttype(), gets type of the data submitted with the POST method. Again, this information might be obtained through HTTP headers as well. getremoteaddr(), the IP address of the client. getremotehost(), the domain name of the client. getremoteuser(), the username if an authorization header was supplied with the request.

16 getservername(), the domain name where servlet is running. getserverport(), the port on which the server is listening. getserverprotocol(), the name and version of protocol that is used for the request. For complete list of the methods provided by the HttpServletRequest class consult the Java Servlet API documentation at Handling HTML forms HTML forms are often used to allow users to submit data to the server. For instance, to submit a search query to a search engine users type in their search terms in a text field provided by an HTML form. In an online reservation application users wotk with HTML forms to choose their preferable day of travel, travel conditions, and so on. Regarding the HTTP method used to submit the data, these HTML parameters are encoded as URLs (in the case of GET method), or they are submited as the request content (in the case of POST method). Usually, decoding parameters on the server side in the case of CGI programs needed to be accomplished by programmers. These was one of the most tedious part of CGI programming, and one of the reasons for the Java Servlet API developers to include this in the Servlet API. Thus, the HttpServlet Request class provides higl level methods which programmers can call to obtain the parameters submitted by users. Therby the HTTP method used for the request is totally abstracted in the API, thus allowing programmers to obtain parameters in the same way (i.e., by calling the same methods) regardless of the HTTP method used in the request. There are three methods in the HttpServletRequest class to obtain the request parameters: getparameter(), which takes as an argument the name of the parameter from HTML form. This method returns a String if the parameter with the specified name exists, otherwise null is returned. Generally, a parameter submitted by a user might have multiple values. In that case this method returns the first value for this parameter. getparametervalues(), which takes as an argument the name of the parameter from HTML form. This method returns an array of Strings if the parameter with the specified name exists, otherwise null is returned. getparameternames(), which returns an iterator over the names of all parameters submitted by a user. Thus, we might use this method to firstly get all names of parameters, and then we can call other two methods to obtain values of parameters. The next example provides a Java servlet that handles the parameters submitted by a user. For the front-end of this example we have a simple HTML form, which is a registration form that allows students to register for a university course. In this example we use the GET method to submit the data.

17 Example 10. HTML for Students Registration (GET Method) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " <html> <head> <title>form example</title> <meta http-equiv = "Content-type" content = "text/html; charset=iso "> <link rel = "stylesheet" type = "text/css" href = "style.css"> </head> <body> <h2>registration for MMIS</h2> <form action ="/mmis-servlets/form" method="get"> Name: <p> <input type = "text" name = "name" size = "20" maxlength = "50"> </p> Second Name: <p> <input type = "text" name = "second_name" size = "20" maxlength = "50"> </p> Matrikel Number: <p> <input type = "text" name = "nr" size = "20" maxlength = "50"> </p> Study Field: <p> <select name = "study_field"> <option value = "F874">Telematics <option value = "F860">Technical Mathematics <option value = "F033523">Software Development <option value = "F033211">Telematics Bachelor <option value = "F033221">Geomatics </select> </p> <p> <input type = "submit" value = "Register"> </p> </form> </body> </html> This HTML form is accessible online at

18 For submitting the data with the POST method we need to modify the form element of the GET example. The rest of the HTML form is same as before. Example 11. HTML for Students Registration (POST Method) <form action ="/mmis-servlets/form" method="post"> The POST HTML form is accessible online at Finally, we have the Java Servlet that handles the HTML forms. As mentioned in the example above, both of HTTP methods are handled with one and the same Java servlet, where requests including POST method are simple forwarded to the doget() method. Example 12. Java Servlet Handling HTML Forms * Handles parameters submitted by users * import org.apache.ecs.document; import org.apache.ecs.doctype; import org.apache.ecs.doctype.html40strict; import org.apache.ecs.html.body; import org.apache.ecs.html.head; import org.apache.ecs.html.title; import org.apache.ecs.html.link; import org.apache.ecs.html.table; import org.apache.ecs.html.tr; import org.apache.ecs.html.th; import org.apache.ecs.html.td; import org.apache.ecs.html.p; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import javax.servlet.http.httpsession; import java.io.ioexception; import java.io.printwriter; import java.util.date; import java.util.enumeration; public class FormServlet extends HttpServlet{

19 // * Handles HTTP GET method. Prints user parameters in an HTML table. HttpServletRequest request HttpServletResponse response ServletException IOException public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException{ response.setcontenttype("text/html"); PrintWriter writer = response.getwriter(); Document document = new Document(); document.setdoctype(new Doctype.Html40Strict()); Title title = new Title("Form Servlet"); document.settitle(title); Head head = document.gethead(); Body body = document.getbody(); Link link = new Link(); link.setrel("stylesheet"); link.settype("text/css"); link.sethref("style.css"); head.addelement(link); Table table = new Table(); TR table_header = new TR(true); table_header.addelement((new TH(true)).addElement("Key")); table_header.addelement((new TH(true)).addElement("Value")); table.addelement(table_header); Enumeration parameters = request.getparameternames(); while(parameters.hasmoreelements()){ String key = (String) parameters.nextelement(); String value = request.getparameter(key); TR table_row = new TR(true); table_row.addelement((new TD(true)).addElement(key)); table_row.addelement((new TD(true)).addElement(value)); table.addelement(table_row); P paragraph = new P(); paragraph.setneedclosingtag(true); paragraph.addelement("form Variables"); body.addelement(paragraph); body.addelement(table); document.output(writer); //

20 * Handles HTTP POST method. Just invokes goget() method. HttpServletRequest request HttpServletResponse response ServletException IOException public void dopost(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException{ doget(request, response); The source code of this example is avaliable onlne: FormServlet.java. Bibliography Books [HallBrown2003] Marty Hall and Larry Browni. Copyright 1999 Marty Hall Sun Microsystems Press and Prentice Hall PTR. Core Servlets and Java Server Pages. Online Resources [CGI1995] The CGI Specification, Version [JavaServlet2003] The Java Servlet Specification, Version [JavaServletAPI2003] The Java Servlet API, Version [Tomcat1999] Apache Tomcat. [Apache2000] Apache Software Licences. [Jakarta2003] Apache Jakarta Project. [ECS2003] Element Construction Set.

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

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

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

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

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

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

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

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

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

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

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

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

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

Kamnoetvidya Science Academy. Object Oriented Programming using Java. Ferdin Joe John Joseph. Java Session

Kamnoetvidya Science Academy. Object Oriented Programming using Java. Ferdin Joe John Joseph. Java Session Kamnoetvidya Science Academy Object Oriented Programming using Java Ferdin Joe John Joseph Java Session Create the files as required in the below code and try using sessions in java servlets web.xml

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

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

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

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

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

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

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

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

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

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

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

servlets and Java JSP murach s (Chapter 2) TRAINING & REFERENCE Mike Murach & Associates Andrea Steelman Joel Murach

servlets and Java JSP murach s (Chapter 2) TRAINING & REFERENCE Mike Murach & Associates Andrea Steelman Joel Murach Chapter 4 How to develop JavaServer Pages 97 TRAINING & REFERENCE murach s Java servlets and (Chapter 2) JSP Andrea Steelman Joel Murach Mike Murach & Associates 2560 West Shaw Lane, Suite 101 Fresno,

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

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

In servlet, form parsing is handled automatically. You call request.getparameter to get the value of a form parameter.

In servlet, form parsing is handled automatically. You call request.getparameter to get the value of a form parameter. In servlet, form parsing is handled automatically. You call request.getparameter to get the value of a form parameter. You can also call request.getparametervalues if the parameter appears more than once,

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

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

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

Accessing EJB in Web applications

Accessing EJB in Web applications Accessing EJB in Web applications 1. 2. 3. 4. Developing Web applications Accessing JDBC in Web applications To run this tutorial, as a minimum you will be required to have installed the following prerequisite

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

Tutorial: Developing a Simple Hello World Portlet

Tutorial: Developing a Simple Hello World Portlet Venkata Sri Vatsav Reddy Konreddy Tutorial: Developing a Simple Hello World Portlet CIS 764 This Tutorial helps to create and deploy a simple Portlet. This tutorial uses Apache Pluto Server, a freeware

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

Chapter 10 Servlets and Java Server Pages

Chapter 10 Servlets and Java Server Pages Chapter 10 Servlets and Java Server Pages 10.1 Overview of Servlets A servlet is a Java class designed to be run in the context of a special servlet container An instance of the servlet class is instantiated

More information

Welcome To PhillyJUG. 6:30-7:00 pm - Network, eat, find a seat 7:00-7:15 pm - Brief announcements 7:15-8:30 pm - Tom Janofsky's presentation

Welcome To PhillyJUG. 6:30-7:00 pm - Network, eat, find a seat 7:00-7:15 pm - Brief announcements 7:15-8:30 pm - Tom Janofsky's presentation Welcome To PhillyJUG 6:30-7:00 pm - Network, eat, find a seat 7:00-7:15 pm - Brief announcements 7:15-8:30 pm - Tom Janofsky's presentation Web Development With The Struts API Tom Janofsky Outline Background

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

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

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

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

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

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

Customizing ArcIMS Using the Java Connector and Python

Customizing ArcIMS Using the Java Connector and Python Customizing ArcIMS Using the Java Connector and Python Randal Goss The ArcIMS Java connector provides the most complete and powerful object model for creating customized ArcIMS Web sites. Java, however,

More information

CIS 3952 [Part 2] Java Servlets and JSP tutorial

CIS 3952 [Part 2] Java Servlets and JSP tutorial Java Servlets Example 1 (Plain Servlet) SERVLET CODE import java.io.ioexception; import java.io.printwriter; import javax.servlet.servletexception; import javax.servlet.annotation.webservlet; import javax.servlet.http.httpservlet;

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

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

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

CSC309: Introduction to Web Programming. Lecture 8

CSC309: Introduction to Web Programming. Lecture 8 CSC309: Introduction to Web Programming Lecture 8 Wael Aboulsaadat Front Layer Web Browser HTTP Request Get http://abc.ca/index.html Web (HTTP) Server HTTP Response .. How

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

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

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

SDN Community Contribution

SDN Community Contribution SDN Community Contribution (This is not an official SAP document.) Disclaimer & Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces

More information

3. The pool should be added now. You can start Weblogic server and see if there s any error message.

3. The pool should be added now. You can start Weblogic server and see if there s any error message. CS 342 Software Engineering Lab: Weblogic server (w/ database pools) setup, Servlet, XMLC warming up Professor: David Wolber (wolber@usfca.edu), TA: Samson Yingfeng Su (ysu@cs.usfca.edu) Setup Weblogic

More information

CHAPTER 2: A FAST INTRODUCTION TO BASIC SERVLET PROGRAMMING

CHAPTER 2: A FAST INTRODUCTION TO BASIC SERVLET PROGRAMMING Taken from More Servlets and JavaServer Pages by Marty Hall. Published by Prentice Hall PTR. For personal use only; do not redistribute. For a complete online version of the book, please see http://pdf.moreservlets.com/.

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

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

Lab session Google Application Engine - GAE. Navid Nikaein

Lab session Google Application Engine - GAE. Navid Nikaein Lab session Google Application Engine - GAE Navid Nikaein Available projects Project Company contact Mobile Financial Services Innovation TIC Vasco Mendès Bluetooth low energy Application on Smart Phone

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

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

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

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

Handling the Client Request: HTTP Request Headers

Handling the Client Request: HTTP Request Headers Handling the Client Request: HTTP Request Headers 1 Agenda Reading HTTP request headers Building a table of all the request headers Understanding the various request headers Reducing download times by

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

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

WWW Architecture I. Software Architecture VO/KU ( / ) Roman Kern. KTI, TU Graz

WWW Architecture I. Software Architecture VO/KU ( / ) Roman Kern. KTI, TU Graz WWW Architecture I Software Architecture VO/KU (707.023/707.024) Roman Kern KTI, TU Graz 2013-12-04 Roman Kern (KTI, TU Graz) WWW Architecture I 2013-12-04 1 / 81 Web Development Tutorial Java Web Development

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

Web Based Solutions. Gerry Seidman. IAM Consulting

Web Based Solutions. Gerry Seidman. IAM Consulting Web Based Solutions Gerry Seidman Internet Access Methods seidman@iamx.com http://www.iam-there.com 212-580-2700 IAM Consulting seidman@iamx.com http://www.iamx.com 212-580-2700 (c) IAM Consulting Corp.

More information

PRODUCT DOCUMENTATION. Installing and Implementing Enterprise Contact Center Chat RELEASE 5.1

PRODUCT DOCUMENTATION. Installing and Implementing Enterprise Contact Center Chat RELEASE 5.1 PRODUCT DOCUMENTATION Installing and Implementing Enterprise Contact Center Chat RELEASE 5.1 Document and Software Copyrights Copyright 1998 2009 ShoreTel, Inc. All rights reserved. Printed in the United

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

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

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

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

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

Server Side Internet Programming

Server Side Internet Programming Server Side Internet Programming DD1335 (Lecture 6) Basic Internet Programming Spring 2010 1 / 53 Server Side Internet Programming Objectives The basics of servlets mapping and configuration compilation

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

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

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

Getting started with Winstone. Minimal servlet container

Getting started with Winstone. Minimal servlet container Getting started with Winstone Minimal servlet container What is Winstone? Winstone is a small servlet container, consisting of a single JAR file. You can run Winstone on your computer using Java, and get

More information

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p.

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p. Preface p. xiii Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p. 11 Creating the Deployment Descriptor p. 14 Deploying Servlets

More information

Backend. (Very) Simple server examples

Backend. (Very) Simple server examples Backend (Very) Simple server examples Web server example Browser HTML form HTTP/GET Webserver / Servlet JDBC DB Student example sqlite>.schema CREATE TABLE students(id integer primary key asc,name varchar(30));

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

Topics Augmenting Application.cfm with Filters. What a filter can do. What s a filter? What s it got to do with. Isn t it a java thing?

Topics Augmenting Application.cfm with Filters. What a filter can do. What s a filter? What s it got to do with. Isn t it a java thing? Topics Augmenting Application.cfm with Filters Charles Arehart Founder/CTO, Systemanage carehart@systemanage.com http://www.systemanage.com What s a filter? What s it got to do with Application.cfm? Template

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

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

Session 8. Reading and Reference. en.wikipedia.org/wiki/list_of_http_headers. en.wikipedia.org/wiki/http_status_codes

Session 8. Reading and Reference. en.wikipedia.org/wiki/list_of_http_headers. en.wikipedia.org/wiki/http_status_codes Session 8 Deployment Descriptor 1 Reading Reading and Reference en.wikipedia.org/wiki/http Reference http headers en.wikipedia.org/wiki/list_of_http_headers http status codes en.wikipedia.org/wiki/_status_codes

More information

Implementation Architecture

Implementation Architecture Implementation Architecture Software Architecture VO/KU (707023/707024) Roman Kern ISDS, TU Graz 2017-11-15 Roman Kern (ISDS, TU Graz) Implementation Architecture 2017-11-15 1 / 54 Outline 1 Definition

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

Generating the Server Response: HTTP Response Headers

Generating the Server Response: HTTP Response Headers Generating the Server Response: HTTP Response Headers 1 Agenda Format of the HTTP response Setting response headers Understanding what response headers are good for Building Excel spread sheets Generating

More information

Web Application Architecture (based J2EE 1.4 Tutorial)

Web Application Architecture (based J2EE 1.4 Tutorial) Web Application Architecture (based J2EE 1.4 Tutorial) Dr. Kanda Runapongsa (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda Web application, components and container

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

Java.. servlets and. murach's TRAINING & REFERENCE 2ND EDITION. Joel Murach Andrea Steelman. IlB MIKE MURACH & ASSOCIATES, INC.

Java.. servlets and. murach's TRAINING & REFERENCE 2ND EDITION. Joel Murach Andrea Steelman. IlB MIKE MURACH & ASSOCIATES, INC. TRAINING & REFERENCE murach's Java.. servlets and 2ND EDITION Joel Murach Andrea Steelman IlB MIKE MURACH & ASSOCIATES, INC. P 1-800-221-5528 (559) 440-9071 Fax: (559) 440-0963 murachbooks@murach.com www.murach.com

More information

Configuring Tomcat for a Web Application

Configuring Tomcat for a Web Application Configuring Tomcat for a Web Application In order to configure Tomcat for a web application, files must be put into the proper places and the web.xml file should be edited to tell Tomcat where the servlet

More information