Internet Technologies 6 - Servlets I. F. Ricci 2010/2011
|
|
- Joy Greene
- 5 years ago
- Views:
Transcription
1 Internet Technologies 6 - Servlets I F. Ricci 2010/2011
2 Content Basic Servlets Tomcat Servlets lifecycle Servlets and forms Reading parameters Filtering text from HTML-specific characters Reading headers Sending compressed content Differentiating among browsers Referer Most of the slides were made available by www. coreservlets.com
3 Servlet Roles Read the explicit data sent by the client Read the implicit HTTP request data sent by the browser Generate the results Send the explicit data (i.e., the document) to the client Send the implicit HTTP response data
4 HelloWorld import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Very simplistic servlet that generates plain text. * <P> * Taken from More Servlets and JavaServer Pages * from Prentice Hall and Sun Microsystems Press, * * 2002 Marty Hall; may be freely used or adapted. */ public class HelloWorld extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getwriter(); out.println("hello World"); code
5 Servlet Architecture HTTP Request HTTP Response Servlet Container Java Virtual Machine (JVM) Servlet 1 Servlet 2 Client Web Web Server Servlet n
6 Installing and Running Tomcat Tomcat is distributed as a ZIP archive tomcat.apache.org unzip the download file, for instance into a rootlevel directory: C:\apache-tomcat To run Tomcat you'll need to tell it where to find your J2SE SDK installation Set the JAVA_HOME environment variable to C:\Program Files\Java\jdk1.6.0_04 To run Tomcat: open a command window change directory to Tomcat's bin directory Type startup
7 Tomcat Directory Structure Tomcat binaries: startup, shutdown All jar libraries: e.g. servlet-api.jar Configuration files: e.g. when you build your application in Netbeans a new file is added to indicate where is deployed (e.g., C:\apachetomcat \conf \Catalina\localhost \coresjsp.xml) Directories of the web applications deployed here, possibly generated by.war files deployed here (with a web.xml file)
8 Catalina Base Go to netbeans: tools>servers to look at these details
9 web.xml <?xml version="1.0" encoding="iso "?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" " <web-app> <servlet> <servlet-name>bob</servlet-name> <servlet-class>helloworld</servlet-class> </servlet> <servlet-mapping> <servlet-name>bob</servlet-name> <url-pattern>/helloworld</url-pattern> </servlet-mapping> </web-app>
10 Compiling and deploying Create a directory in \webapps called hello Create a directory in \webapps\hello called WEB-INF and then a subdirectory classes where to put the sources and the compiled files Set the classpath C:\>set CLASSPATH=\apache-tomcat \common \lib\servlet-api.jar Compile C:\>javac HelloWorld.java Deploy the web.xml file in C:\apachetomcat \webapps\hello\WEB-INF Or use an IDE (Netbeans) separating sources (web directory) and deployment (build directory).
11 Starting Tomcat /bin/startup.bat or startup.sh Point Browers to should see default page All the Docs are there on the default page! Check out the examples pages, good tutorials
12 Basic Servlet Structure Here's the outline of a basic servlet that handles GET and POST requests in the same way: import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SomeServlet extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getwriter(); // Use "out" to send content to browser public void dopost(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { doget(request, response);
13 HelloWorld HTML import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloServlet2 extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { response.setcontenttype("text/html"); PrintWriter out = response.getwriter(); String doctype = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n"; out.println(doctype + "<HTML>\n" + "<HEAD><TITLE>Hello (2)</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1>Hello</H1>\n" + "</BODY></HTML>"); code
14 Some Simple HTML-Building Utilities public class ServletUtilities { public static final String DOCTYPE = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">"; public static String headwithtitle(string title) { return(doctype + "\n" + "<HTML>\n" + "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n");... Don t go overboard Complete HTML generation packages usually work poorly The JSP framework is a better solution code
15 HelloServlet3: Packages and Utilities package coreservlets; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloServlet3 extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { response.setcontenttype("text/html"); PrintWriter out = response.getwriter(); String title = "Hello (3)"; out.println(servletutilities.headwithtitle(title)+ "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1>" + title + "</H1>\n" + "</BODY></HTML>"); code
16 The Servlet Life Cycle (Servlet Interface) init Executed once when the servlet is first loaded Not called for each request service Called in a new thread by server for each request Dispatches to doget, dopost, etc. Do not override this method! doget, dopost, doxxx Handles GET, POST, etc. requests Override these to provide desired behavior destroy Called when server deletes servlet instance Not called after each request. javadoc
17 Example of usage of init If a servlet get a request for a url with the http header if-modified-since: Mon, 12 Nov :00:00 GMT It can check if something has really changed the output after that date if not the servlet sends back a reply: HTTP/ Not Modified And the browser shows the cashed url The servlet must only implement the following method to know when it has been modified the last time: public long getlastmodified(httpservletrequest request) The app server will call it when a client requests the servlet And will send back a result only if the page was modified (according to the value returned by the method) after Mon, 12 Nov :00:00 GMT
18 Code The init method set the time the page was modified public void init() throws ServletException { // Round to nearest second (i.e, 1000 milliseconds) modtime = System.currentTimeMillis()/1000*1000; for(int i=0; i<numbers.length; i++) { numbers[i] = randomnum(); An then overwrite the method that tells when the page was modified public long getlastmodified(httpservletrequest request) { return(modtime); LotteryNumbers code
19 Calls to the servlet The page was modified after 8:00:00 GMT The page was not modified after 9:00:00 GMT
20 Calls to the servlet You can do the same experiments with a telnet connection (e.g., using putty)
21 HTML Form <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD><TITLE>A Sample Form Using GET</TITLE></HEAD> <BODY> <H2 ALIGN="CENTER">A Sample Form Using GET</H2> <FORM ACTION=" <CENTER> First name: <INPUT TYPE="TEXT" NAME="FirstName" VALUE=""><BR/> Last name: <INPUT TYPE="TEXT" NAME="LastName" VALUE=""><P> <INPUT TYPE="SUBMIT"> </CENTER> </FORM> </BODY> </HTML> form
22 Reading form data in servlets request.getparameter( FirstName") Returns URL-decoded value of first occurrence of FirstName parameter in query string Works identically for GET and POST requests Returns null if no such parameter is in query data request.getparametervalues( FirstName") Returns an array of the URL-decoded values of all occurrences of FirstName parameter in query string Returns a one-element array if param is not repeated Returns null if no such parameter is in the query request.getparameternames() or request.getparametermap() Returns Enumeration or Map of request parameters Usually reserved for debugging.
23 Reading parameters import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class ServletForm extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { response.setcontenttype("text/html"); PrintWriter out = response.getwriter(); out.println("<!doctype HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" + "<HTML>\n" + "<HEAD><TITLE>ServletForm</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=\"CENTER\">ServletForm</H1>\n" + "<UL>\n" + "<LI><B>FirstName</B>: "+ request.getparameter("firstname")+"\n"+ "<LI><B>LastName</B>: "+ request.getparameter("lastname")+"\n"+ "</UL>\n" + "</BODY></HTML>"); public void dopost(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { doget(request, response); ServletForm code
24 Example: reading all parameters getform postform
25 Reading All Parameters public class ShowParameters extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { response.setcontenttype("text/html"); PrintWriter out = response.getwriter(); String doctype = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n"; String title = "Reading All Request Parameters"; out.println(doctype + "<HTML>\n" + "<HEAD><TITLE>"+title + "</TITLE></HEAD>\n"+ "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=CENTER>" + title + "</H1>\n" + "<TABLE BORDER=1 ALIGN=CENTER>\n" + "<TR BGCOLOR=\"#FFAD00\">\n" + "<TH>Parameter Name<TH>Parameter Value(s)"); code
26 Reading All Parameters Enumeration paramnames = request.getparameternames(); while(paramnames.hasmoreelements()) { String paramname = (String)paramNames.nextElement(); out.print("<tr><td>" + paramname + "\n<td>"); String[] paramvalues = request.getparametervalues(paramname); if (paramvalues.length == 1) { String paramvalue = paramvalues[0]; if (paramvalue.length() == 0) out.println("<i>no Value</I>"); else out.println(paramvalue); else { out.println("<ul>"); for(int i=0; i<paramvalues.length; i++) { out.println("<li>" + paramvalues[i]); out.println("</ul>"); out.println("</table>\n</body></html>");
27 Reading All Parameters public void dopost(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { doget(request, response);
28 Filtering Strings for HTML-Specific Chars You cannot safely insert arbitrary strings into servlet output < and > can cause problems anywhere & and " can cause problems inside of HTML attributes You sometimes cannot manually translate The string is derived from a program excerpt or another source where it is already in some standard format The string is derived from HTML form data Failing to filter special characters from form data makes you vulnerable to cross-site scripting attack.
29 Filtering Strings for HTML-Specific Chars public class ServletUtilities { public static String filter(string input) { if (!hasspecialchars(input)) { return(input); StringBuffer filtered = new StringBuffer(input.length()); char c; for(int i=0; i<input.length(); i++) { c = input.charat(i); switch(c) { case '<': filtered.append("<"); break; case '>': filtered.append(">"); break; case '"': filtered.append("""); break; case '&': filtered.append("&"); break; default: filtered.append(c); return(filtered.tostring()); code
30 No Filtering public class BadCodeServlet extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { out.println(doctype + "<HTML>\n" + "<HEAD><TITLE>"+title+"</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=\"CENTER\">" + title + "</H1>\n"+ "<PRE>\n" + getcode(request) + "</PRE>\n" + "Now, wasn't that an interesting sample\n" + "of code?\n" + "</BODY></HTML>"); protected String getcode(httpservletrequest request) { return(request.getparameter("code")); Spaces and line breaks are preserved code
31 Special Chars: no filtering form calling the badservlet
32 Servlet that does Filtering public class GoodCodeServlet extends BadCodeServlet { protected String getcode(httpservletrequest request) { return (ServletUtilities.filter(super.getCode(request))); //get the code as in the super class and then do the filter code
33 Filtering goodservlet
34 A Typical HTTP Request GET /servlet/search?keywords=servlets+jsp HTTP/1.1 Accept: image/gif, image/jpg, */* Accept-Encoding: gzip Connection: Keep-Alive Cookie: userid=id Host: Referer: User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) You need to understand HTTP to be effective with servlets and JSP
35 Reading Request Headers General methods of the HttpServletRequest getheader(string name) the first one with that name getheaders(string name) all occurrences of the header getheadernames Specialized methods of the HttpServletRequest getcookies getauthtype and getremoteuser getcontentlength getcontenttype getdateheader getintheader Related info getmethod, getrequesturi, getquerystring, getprotocol
36 Checking For Missing Headers HTTP 1.0 All request headers are optional HTTP 1.1 Only Host is required Conclusion Always check that request.getheader is non-null before trying to use it String val = request.getheader("some- Name"); if (val!= null) {
37 All Request Headers (Firefox) Call servlet
38 Request Headers (Internet Explorer)
39 Making a Table of Request Headers public class ShowRequestHeaders extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { out.println (doctype + "<HTML>\n" + "<HEAD><TITLE>"+title+"</TITLE></HEAD>\n"+ "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=\"CENTER\">" + title + "</H1>\n" + "<B>Request Method: </B>" + request.getmethod() + "<BR>\n" + "<B>Request URI: </B>" + request.getrequesturi() + "<BR>\n" + "<B>Request Protocol: </B>" + request.getprotocol() + "<BR><BR>\n" + code
40 Request Headers (Continued) "<TABLE BORDER=1 ALIGN=\"CENTER\">\n" + "<TR BGCOLOR=\"#FFAD00\">\n" + "<TH>Header Name<TH>Header Value"); Enumeration headernames = request.getheadernames(); while(headernames.hasmoreelements()) { String headername = (String)headerNames.nextElement(); out.println("<tr><td>" + headername); out.println(" <TD>"+request.getHeader(headerName)); out.println("</table>\n</body></html>"); /** Since this servlet is for debugging, have it * handle GET and POST identically. */ public void dopost(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { doget(request, response);
41 Common HTTP 1.1 Request Headers Accept Indicates MIME types browser can handle Can send different content to different clients. For example, PNG files have good compression characteristics but are not widely supported in browsers. A servlet could check to see if PNG is supported, sending <IMG SRC="picture.png"...> if it is supported, and <IMG SRC="picture.gif"...> if not. Accept-Encoding Indicates encodings (e.g., gzip or compress) browser can handle. See following example
42 Common HTTP 1.1 Request Headers Authorization User identification for password-protected pages Instead of HTTP authorization, use HTML forms to send username/password and store info in session object - this approach is usually preferable because standard HTTP authorization results in a small, terse dialog box that is unfamiliar to many users Servers have high-level way to set up password-protected pages without explicit programming in the servlets.
43 Common HTTP 1.1 Request Headers Connection In HTTP 1.0, keep-alive means browser can handle persistent connection - in HTTP 1.1, persistent connection is default Persistent connections mean that the web server can reuse the same socket over again for requests very close together from the same client (e.g., the images associated with a page, or cells within a framed page). Servlets can't do this unilaterally; the best they can do is to give the web server enough info to permit persistent connections - they should set Content-Length response header.
44 Common HTTP 1.1 Request Headers Cookie Gives cookies previously sent to client Use getcookies, not getheader (we shall do that in a next lecture) Host Indicates host given in original URL This is a required header in HTTP 1.1 This fact is important to know if you write a custom HTTP client (e.g., WebClient we used before) or telnet to a server and use the HTTP/1.1 version.
45 Common HTTP 1.1 Request Headers If-Modified-Since Indicates client wants page only if it has been changed after specified date Don t handle this situation directly; implement getlastmodified instead See lottery-number example we have already shown Referer URL of referring Web page Useful for tracking traffic; logged by many servers Can also be used to let users set preferences and then return to the page they came from Can be easily spoofed; don't let this header be sole means of deciding how much to pay sites that show your banner ads Some browsers (Opera), ad filters (Web Washer), and personal firewalls (Norton) screen out this header.
46 Common HTTP 1.1 Request Headers User-Agent Best used for identifying category of client Web browser vs. I-mode cell phone, etc. For Web applications, use other parameters if possible Again, can be easily spoofed We shall touch this later
47 Sending Compressed Web Pages Dilbert used with permission of United Syndicates Inc.
48 Sending Compressed Pages: GzipUtilities.java public class GzipUtilities { public static boolean isgzipsupported (HttpServletRequest request) { String encodings = request.getheader("accept-encoding"); return((encodings!= null) && (encodings.indexof("gzip")!= -1)); public static boolean isgzipdisabled (HttpServletRequest request) { String flag = request.getparameter("disablegzip"); return((flag!= null)&& // if the parameter is not null (!flag.equalsignorecase("false"))); // and not "false" public static PrintWriter getgzipwriter (HttpServletResponse response) throws IOException { return(new PrintWriter (new GZIPOutputStream (response.getoutputstream()))); code
49 Sending Compressed Pages: LongServlet.java public class LongServlet extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { response.setcontenttype("text/html"); // Change the definition of "out" depending on // whether or not gzip is supported. PrintWriter out; if (GzipUtilities.isGzipSupported(request) &&!GzipUtilities.isGzipDisabled(request)) { out = GzipUtilities.getGzipWriter(response); response.setheader("content-encoding", "gzip"); else { out = response.getwriter(); code
50 Sending Compressed Pages: LongServlet.java out.println (doctype + "<HTML>\n" + "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=\"CENTER\">" + title + "</H1>\n"); String line = "Blah, blah, blah, blah, blah. " + "Yadda, yadda, yadda, yadda."; for(int i=0; i<10000; i++) { out.println(line); out.println("</body></html>"); out.close();
51 Sending Compressed Pages: Results Uncompressed (28.8K modem), Firefox, Netscape and Internet Explorer: > 50 seconds Compressed (28.8K modem), Firefox, Netscape and Internet Explorer: < 5 seconds Caution: be careful about generalizing benchmarks call call
52 Differentiating Among Different Browser Types Use User-Agent only when necessary Otherwise, you will have difficult-to-maintain code that consists of tables of browser versions and associated capabilities Check for null The header is not required by the HTTP 1.1 specification, some browsers let you disable it (e.g., Opera), and custom clients (e.g., Web spiders or link verifiers) might not use the header at all To differentiate among Firefox, Netscape, and Internet Explorer, check for MSIE, not Mozilla Both Firefox and Internet Explorer say Mozilla at the beginning of the header Note that the header can be faked If a client fakes this header, the servlet cannot tell the difference.
53 Differentiating Among Different Browser Types public class BrowserInsult extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { response.setcontenttype("text/html"); PrintWriter out = response.getwriter(); String title, message; // Assume for simplicity that Firefox and IE are // the only two browsers. String useragent = request.getheader("user-agent"); if ((useragent!= null) && (useragent.indexof("msie")!= -1)) { title = "Microsoft Minion"; message = "Welcome, O spineless slave to the " + "mighty empire."; else { title = "Hopeless Firefox Rebel"; message = "Enjoy it while you can. " + "You <I>will</I> be assimilated!"; code
54 Differentiating Among Browser Types (Result) call
55 Referer The Referer header designates the location of the page users were on when they clicked on a link No Referer is set if the user typed the address of the page You can customize a page depending on how the user reached it Customize the layout of a page according to the site that link to Change the content if the user come from the same domain or another domain Supply a link to go back Track the effectiveness of a banner or a link.
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 informationServlet 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 informationAdvanced 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 informationSession 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 informationServlet 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 informationCHAPTER 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 informationFirst 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 informationServer 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 informationHTTP Request Handling
Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 5049 Advanced Internet Technology Lab Lab # 5 HTTP Request Handling El-masry March, 2014 Objectives To be familiar
More informationIn 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 informationSession 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 informationServlets1. 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 informationAdvanced 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 informationAN OVERVIEW OF SERVLET AND JSP TECHNOLOGY
AN OVERVIEW OF SERVLET AND JSP TECHNOLOGY Topics in This Chapter Understanding the role of servlets Building Web pages dynamically Looking at servlet code Evaluating servlets vs. other technologies Understanding
More informationJAVA 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 informationJAVA SERVLET. Server-side Programming PROGRAMMING
JAVA SERVLET Server-side Programming PROGRAMMING 1 AGENDA Passing Parameters Session Management Cookie Hidden Form URL Rewriting HttpSession 2 HTML FORMS Form data consists of name, value pairs Values
More informationServlets 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 informationUsing 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 informationHANDLING THE CLIENT REQUEST: FORM DATA
HANDLING THE CLIENT REQUEST: FORM DATA Topics in This Chapter Reading individual request parameters Reading the entire set of request parameters Handling missing and malformed data Filtering special characters
More information2. 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 informationsessionx 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 informationJava 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 informationINTRODUCTION 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 informationServlet 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 informationJava 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&' () - #-& -#-!& 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 informationWeb 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 informationServlets. 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 informationThis 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 informationLAB 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 informationHandling Cookies. Agenda
Handling Cookies 1 Agenda Understanding the benefits and drawbacks of cookies Sending outgoing cookies Receiving incoming cookies Tracking repeat visitors Specifying cookie attributes Differentiating between
More informationLecture 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 informationIntroduction 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 informationWHITE LABELING IN PROGRESS ROLLBASE PRIVATE CLOUD
W HI TEPAPER www. p rogres s.com WHITE LABELING IN PROGRESS ROLLBASE PRIVATE CLOUD In this whitepaper, we describe how to white label Progress Rollbase private cloud with your brand name by following a
More informationAdvanced 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 informationForm Data trong Servlet
Form Data trong Servlet Bạn gặp phải nhiều tình huống mà cần truyền một số thông tin từ trình duyệt của bạn tới Web Server và sau đó tới chương trình backend của bạn. Trình duyệt sử dụng hai phương thức
More informationServlets 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 informationThe 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 informationTo 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 informationEnterprise 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 informationBerner 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 informationHandout 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 informationUNIT-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 informationSupplement 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 informationGenerating 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 informationIntroduction. 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 informationServlets.
Servlets Servlets Servlets are modules that extend Java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used
More informationServletConfig 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 informationDatabase 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 informationThe 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 informationJava 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 informationIntroduction. 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 informationHttpServlet ( 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 informationcore programming Servlets Marty Hall, Larry Brown
core programming Servlets 1 2001-2003 Marty Hall, Larry Brown http:// 2 Servlets Agenda Overview of servlet technology First servlets Handling the client request Form data HTTP request headers Generating
More informationIntroduction 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 information1.264 Lecture 15. Web development environments: JavaScript Java applets, servlets Java (J2EE) Active Server Pages
1.264 Lecture 15 Web development environments: JavaScript Java applets, servlets Java (J2EE) Active Server Pages Development environments XML, WSDL are documents SOAP is HTTP extension UDDI is a directory/registry
More informationInternet Technologies 5-Dynamic Web. F. Ricci 2010/2011
Internet Technologies 5-Dynamic Web F. Ricci 2010/2011 Content The "meanings" of dynamic Building dynamic content with Java EE (server side) HTML forms: how to send to the server the input PHP: a simpler
More informationGENERATING THE SERVER RESPONSE: HTTP STATUS CODES
GENERATING THE SERVER RESPONSE: HTTP STATUS CODES Topics in This Chapter Format of the HTTP response How to set status codes What the status codes are good for Shortcut methods for redirection and error
More informationAJP. 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 informationCSC309: 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 informationSERVLETS 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 informationUnit 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 informationModule 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 informationPreview from Notesale.co.uk Page 6 of 132
15. SERVLET HANDLING DATE... 80 Getting Current Date & Time... 81 Date Comparison... 82 Date Formatting using SimpleDateFormat... 82 Simple DateFormat Format Codes... 83 16. SERVLETS PAGE REDIRECTION...
More informationLab 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 informationJava4570: 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 informationSession 10. Form Dataset. Lecture Objectives
Session 10 Form Dataset Lecture Objectives Understand the relationship between HTML form elements and parameters that are passed to the servlet, particularly the form dataset 2 10/1/2018 1 Example Form
More informationServlet. 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 informationOutline. Servlets. Functions of Servlets. Overview. The Advantages of Servlets Over. Why Build Pages Dynamically? Traditional CGI
Outline Servlets Overview of servlet technology First servlets Handling the client request Form data HTTP request headers Generating the server response HTTP status codes HTTP response headers Handling
More informationWelcome 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 informationConfiguring 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 informationHandling Cookies. For live Java EE training, please see training courses at
Edited with the trial version of 2012 Marty To Hall remove this notice, visit: Handling Cookies Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/csajsp2.html
More informationCOMP9321 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 informationServlets 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 informationSSC - 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 informationservlets 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 informationINTERNET 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 informationTutorial: 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 informationJava E-Commerce Martin Cooke,
Java E-Commerce Martin Cooke, 2002 1 Plan The web tier: servlets life cycle Session-management TOMCAT & ANT Applet- communication The servlet life-cycle Notes based largely on Hunter & Crawford (2001)
More informationHTTP Protocol and Server-Side Basics
HTTP Protocol and Server-Side Basics Web Programming Uta Priss ZELL, Ostfalia University 2013 Web Programming HTTP Protocol and Server-Side Basics Slide 1/26 Outline The HTTP protocol Environment Variables
More informationCSC309: 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 informationChapter 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 informationServlets Overview
Servlets 605.481 1 Overview 2 1 A Servlet s Job Read explicit data sent by client (form data) Read implicit data sent by client (request headers) Generate the results Send the explicit data back to client
More informationEnterprise 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 informationLearningPatterns, Inc. Courseware Student Guide
Fast Track to Servlets and JSP Developer's Workshop LearningPatterns, Inc. Courseware Student Guide This material is copyrighted by LearningPatterns Inc. This content shall not be reproduced, edited, or
More informationCOMP9321 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 informationServlet. 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 informationDatabase 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 informationJavaServer 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 informationAdvanced Topics in Operating Systems. Manual for Lab Practices. Enterprise JavaBeans
University of New York, Tirana M.Sc. Computer Science Advanced Topics in Operating Systems Manual for Lab Practices Enterprise JavaBeans PART III A Web Banking Application with EJB and MySQL Development
More informationJava Card 3 Platform. Peter Allenbach Sun Microsystems, Inc.
Java Card 3 Platform Peter Allenbach Sun Microsystems, Inc. Agenda From plastic to Java Card 3.0 Things to know about Java Card 3.0 Introducing Java Card 3.0 Java Card 3.0 vs. Java SE Java Card 3.0 vs.
More information3. 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 informationSERVLET 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 informationChettinad 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 informationJdbcResultSet.java. import java.sql.*;
1)Write a program to display the current contents of the tables in the database where table name is Registration and attributes are id,firstname,lastname,age. JdbcResultSet.java import java.sql.*; public
More informationServlet 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 informationUnit-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 informationCS506 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 informationIntroduction to Server-Side Technologies
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
More informationStateless -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