Servlet And JSP. Mr. Nilesh Vishwasrao Patil, Government Polytechnic, Ahmednagar. Mr. Nilesh Vishwasrao Patil

Size: px
Start display at page:

Download "Servlet And JSP. Mr. Nilesh Vishwasrao Patil, Government Polytechnic, Ahmednagar. Mr. Nilesh Vishwasrao Patil"

Transcription

1 Servlet And JSP, Government Polytechnic, Ahmednagar

2 Servlet : Introduction Specific Objectives: To write web based applications using servlets, JSP and Java Beans. To write servlet for cookies and session tracking.

3 Web and Web Application Web consists of billions of clients and server connected through wires and wireless networks. The web clients make requests to web server. The web server receives the request, finds the resources and return the response to the client.

4 Web Application A web application is an application accessible from the web. A Web application is a web site with dynamic functionality on the server. Google, Facebook, Twitter are examples of web applications. A web application is composed of web components like Servlet, JSP, Filter etc. and other components such as HTML. The web components typically execute in Web Server and respond to HTTP request.

5 HTTP HTTP is a protocol that clients and servers use on the web to communicate. It is similar to other internet protocols such as SMTP(Simple Mail Transfer Protocol) and FTP(File Transfer Protocol) but there is one fundamental difference. HTTP is a stateless protocol. The client sends an HTTP request and the server answers with an HTML page to the client, using HTTP.

6 HTTP

7 HTTP methods Method Name OPTIONS GET HEAD POST DELETE CONNECT Description Request for communication options that are available on the request/response chain. Request to retrieve information from server using a given URI. Identical to GET except that it does not return a message-body, only the headers and status line. Request for server to accept the entity enclosed in the body of HTTP method. Request for the Server to delete the resource. Reserved for use with a proxy that can switch to being a tunnel. PUT This is same as POST, but POST is used to create, PUT can be used to create as well as update. It replaces all current representations of the target resource with the uploaded content.

8 HTTP methods GET Request Data is sent in header to the server Get request can send only limited amount of data Get request is not secured because data is exposed in URL Get request can be bookmarked and is more efficient. POST Request Data is sent in the request body Large amount of data can be sent. Post request is secured because data is not exposed in URL. Post request cannot be bookmarked.

9 Anatomy of HTTP GET Request Get request contains path to server and the parameters added to it.

10 Anatomy of HTTP POST Request Post requests are used to make more complex requests on the server. For instance, if a user has filled a form with multiple fields and the application wants to save all the form data to the database. Then the form data will be sent to the server in POST request body, which is also known as Message body.

11 Servlet : Introduction Servlet technology is used to create web application (resides at server side and generates dynamic web page). Servlet is Java program which run on web server and responding to request of clients (Web browser). Servlet technology is robust and scalable because of java language.

12 Servlet Web applications are helper applications that resides at web server and build dynamic web pages. A dynamic page could be anything like a page that randomly chooses picture to display or even a page that displays the current time.

13 Servlet : Defined in many ways Servlet is a technology i.e. used to create web application. Servlet is an API that provides many interfaces and classes including documentations. Servlet is an interface that must be implemented for creating any servlet. Servlet is a class that extend the capabilities of the servers and respond to the incoming request. It can respond to any type of requests. Servlet is a web component that is deployed on the server to create dynamic web page.

14 Servlet : Defined

15 CGI(Common Gateway Interface) CGI(Common Gateway Interface) programming was used to create web applications. Here's how a CGI program works : User clicks a link that has URL to a dynamic page instead of a static page. The URL decides which CGI program to execute. Web Servers run the CGI program in seperate OS shell. The shell includes OS enviroment and the process to execute code of the CGI program. The CGI response is sent back to the Web Server, which wraps the response in an HTTP response and send it back to the web browser.

16 CGI(Common Gateway Interface)

17 CGI(Common Gateway Interface) For each request, it starts a new process. Disadvantages: If number of clients increases, it takes more time for sending response. For each request, it starts a process and Web server is limited to start processes. It uses platform dependent language e.g. C, C++, perl. High response time because CGI programs execute in their own OS shell. CGI is not scalable. CGI programs are not always secure or object-oriented. It is Platform dependent.

18 Contrast of process vs. thread Process Takes more time to create More secure More fault tolerant Thread Takes less time to create Offers multiple threads of execution Share information with other threads Less secure More vulnerable to crashes

19 Servlet: Advantages over CGI

20 Servlet: Advantages over CGI Less response time because each request runs in a separate thread. Servlets are scalable. Servlets are robust and object oriented. Servlets are platform independent.

21 Servlet Terminologies HTTP: Http is the protocol that allows web servers and browsers to exchange data over the web. It is a request response protocol. Http uses reliable TCP connections by default on TCP port 80. It is stateless means each request is considered as the new request. In other words, server doesn't recognize the user by default.

22 Servlet A Java Servlet is a Java object that responds to HTTP requests. It runs inside a Servlet container.

23 Servlet A Servlet is part of a Java web application. A Servlet container may run multiple web applications at the same time, each having multiple servlets running inside.

24 Servlet A Java web application can contain other components than servlets. It can also contain Java Server Pages (JSP), images, text files, documents, Web Services etc.

25 HTTP Request and Response The browser sends an HTTP request to the Java web server. The web server checks if the request is for a servlet. If it is, the servlet container is passed the request. The servlet container will then find out which servlet the request is for, and activate that servlet. The servlet is activated by calling the Servlet.service()method. Once the servlet has been activated via the service() method the servlet processes the request, and generates a response. The response is then sent back to the browser.

26 Servlet Containers Java servlet containers are usually running inside a Java web server. Example: Tomcat, GlasssFish, Jboss etc. Container: It provides runtime environment for JavaEE (j2ee) applications. It performs many operations that are given below: Life Cycle Management Multithreaded support Security etc.

27 Server Server: It is a running program or software that provides services. Two types Web Server: Web server contains only web or servlet container. It can be used for servlet, jsp, struts, jsf etc. It can't be used for EJB. Example of Web Servers are: Apache Tomcat and Resin. Application Server: Application server contains Web and EJB containers. It can be used for servlet, jsp, struts, jsf, ejb etc. Ex: Jboss, Glassfish, Weblogic, Websphere

28 Content Type Content Type: Content Type is also known as MIME (Multipurpose internet Mail Extension) Type. It is a HTTP header that provides the description about what are you sending to the browser. text/html text/plain application/msword application/vnd.ms-excel application/jar application/pdf application/octet-stream application/x-zip images/jpeg video/quicktime

29 Types of Servlet Generic Servlet: It is in javax.servlet.genericservlet package It is protocol independent. HTTP Servlet It is in javax.servlet.httpservlet package Built-in HTTP protocol support.

30 Types of Servlet Generic Servlet Package: javax.servlet HTTP Servlet Package: javax.servlet.http It is protocol independent servlet It uses service() method for handling request-response. It is protocol dependent specifically only HTTP protocol requestresponse handle. It uses methods like dopost(), doget()

31 Servlet life cycle Managed by :. Each servlet instance is loaded once. Each execution happens in a separate thread Three methods: init() : call only once to initialize servlet. service() : Call for every request. destroy() : call only once Method service() is invoked every time a request comes it. It spawns off threads to perform doget or dopost based on the method invoked.

32 Servlet life cycle 1. Load Servlet Class. 2. Create Instance of Servlet. 3. Call the servlets init() method. 4. Call the servlets service() method. 5. Call the servlets destroy() method. Note: Step 1,2,3 executed only once when servlet is initially loaded. By default servlet is not loaded until first request is received for it. Step 4 executed N -times whenever http request comes Step 5 executed to destroy servlet means unload servlet class

33 Servlet life cycle

34 Servlet life cycle

35 Servlet API Servlet API consists of two important packages that encapsulates all the important classes and interface, namely : javax.servlet javax.servlet.http javax.servlet and javax.servlet.http packages represent interfaces and classes for servlet API.

36 Servlet Interface: javax.servlet Interfaces Servlet ServletConfig Description Declare life cycle methods for servlet. To implement this interface we have to extends GenericServlet or HttpServlet classes. Helps servlet to get initialization parameter means startup information, basic information about servlet. ServletContext Allows servlet to log events and access information about their environment ServletRequest ServletResponse Used to read data from client Used to sent data to client

37 Servlet Classes: javax.servlet Classes GenericServlet ServletInputStream ServletOutputStream ServletException UnavailableException Description Used to create servlet (Protocol independent) Provides an input stream for reading requests from client. This class supports an output stream for writing responses to a client For handling exception: Error Occurred For handling exception: generate when servlet not available

38 Servlet Interface: javax.servlet.http Classes HttpServlet HttpServletRequest HttpServletResponse HttpSession Description Used to create http servlet (Protocol dependent) It enables servlets to read data from an HTTP request It enables servlets to write data to an HTTP response It allows to read and write session data. Cookie Cookie class allows state information to be stored on a client machine

39 Servlet Interface: Methods

40 GenericServlet class It implements Servlet, ServletConfig and Serializable interfaces. It provides the implementation of all the methods of these interfaces except the service method(you have to write code in your servlet class for this method). GenericServlet class can handle any type of request so it is protocol-independent.

41 ServletConfig interface Object of ServletConfig created by the web container for each servlet. This object can be used to get configuration information from web.xml file. Advantage: No need to edit the servlet file if information is modified from the web.xml file.

42 ServletConfig interface public String getinitparameter(string name):returns the parameter value for the specified parameter name. public Enumeration getinitparameternames():returns an enumeration of all the initialization parameter names. public String getservletname():returns the name of the servlet. public ServletContext getservletcontext():returns an object of ServletContext.

43 ServletConfig interface

44 ServletContext interface An object of ServletContext is created by the web container at time of deploying the project (web application). This object can be used to get configuration information from web.xml file. There is only one ServletContext object per web application.

45 ServletContext interface If any information is shared to many servlet, it is better to provide it from the web.xml file using the <context-param> element. Usage: The object of ServletContext provides an interface between the container and servlet. The ServletContext object can be used to get configuration information from the web.xml file. The ServletContext object can be used to set, get or remove attribute from the web.xml file. The ServletContext object can be used to provide inter-application communication.

46 ServletContext interface <context-param> <param-name>dname</param-name> <param-value> sun.jdbc.odbc.jdbcodbcdriver</param-value> </context-param>

47 ServletContext interface

48 ServletConfig Vs ServletContext Config One object per servlet Context Object is global to entire web application Object is created when servlet class is loaded It destroy when servlet is destroyed or upload the class. Object is created when web application deployed It will destroyed when web application is un-deployed or removed. Config object is public to particular servlet only. It can share information between the servlet

49 HttpServlet It extends GenericServlet class and implements Servlet, ServletConfig and Serializable interface. It provides http specific methods such as doget, dopost, dohead, dotrace etc.

50 HttpServlet

51 Implementation A Java Servlet is just an ordinary Java class which implements the interface javax.servlet.servlet; The easiest way to implement this interface is to extend either the class GenericServlet or HttpServlet.

52 Example

53 Implementation When an HTTP request arrives at the web server, targeted for your Servlet, the web server calls your Servlet's service() method. The service() method then reads the request, and generates a response which is sent back to the client (e.g. a browser).

54 Implementation:HTTP The javax.servlet.http.httpservlet class is a slightly more advanced base class than the GenericServlet The HttpServlet class reads the HTTP request, and determines if the request is an HTTP GET, POST, PUT, DELETE, HEAD etc. and calls one the corresponding method.

55 Implementation: HTTP

56 HttpRequest: Interface This interface present in javax.servlet.http.httprequest The purpose of the HttpRequest object is to represent the HTTP request a browser sends to your web application.

57 HttpRequest: Parameters Thus, anything the browser may send, is accessible via the HttpRequest. We can read initialization parameters also using HttpServletRequest object with getinitparameter method.

58 HttpRequest: Parameters Also we can use same (following) code if request parameters is send through body part of the Http request. If the browser sends an HTTP GET request, the parameters are included in the query string in the URL. If the browser sends an HTTP POST request, the parameters are included in the body part of the HTTP request.

59 HttpRequest: Header The request headers are name, value pairs sent by the browser along with the HTTP request. The request headers contain information about e.g. what browser software is being used, what file types the browser is capable of receiving etc. In short, at lot of meta data around the HTTP request. Above example reads the Content-Length header sent by the browser.

60 HttpRequest: InputStream If the browser sends an HTTP POST request, request parameters and other potential data is sent to the server in the HTTP request body. If does not have sent data in parameters means may be binary data, that time we will require InputStream for accessing request body come from client. InputStream requestbodyinput = request.getinputstream(); NOTE: You will have to call this method before calling any getparameter() method.

61 HttpRequest: Session It is possible to obtain the session object from the HttpRequest object too. The session object can hold information about a given user, between requests. So, if you set an object into the session object during one request, it will be available for you to read during any subsequent requests within the same session time scope.

62 HttpResponse: Interface This interface is present in java.servlet.http package. The purpose of the HttpResponse object is to represent the HTTP response of web application sends back to the browser.

63 HttpResponse: Writing HTML To send HTML back to the browser, you have to obtain the a PrintWriter from the HttpResponse object.

64 HttpResponse: Headers Headers must be set before any data is written to the response. Examples: Syntax: response.setheader("header-name", "Header Value"); Set Content type: response.setheader("content-type", "text/html"); Writing text response.setheader("content-type", "text/plain"); PrintWriter writer = response.getwriter(); writer.write("this is just plain text"); Content-length response.setheader("content-length", "31642");

65 HttpResponse: Writing Binary Data We can also write binary data back to the browser instead of text. For instance, we can send an image back, a PDF file or a Flash file or something like that. First we have to set content type. And need to use following code: OutputStream outputstream = response.getoutputstream(); outputstream.write(...);

66 HttpResponse: Redirecting We can redirect the browser to a different URL from your servlet. You cannot send any data back to the browser when redirecting response.sendredirect(" Or Another servlet file call response.sendredirect( HelloServlet");

67 HttpSession The HttpSession object represents a user session. A user session contains information about the user across multiple HTTP requests. When a user enters your site for the first time, the user is given a unique ID to identify his session by. This ID is typically stored in a cookie or in a request parameter.

68 HttpSession We can store values in the session object, and retrieve them later. Do it in following way: session.setattribute("username", "theusername"); This code sets an attribute named "username", with the value "theusername". To read the value again: String username = (String) session.getattribute("username"); Values stored in the session object are stored in the memory of the servlet container.

69 HttpSession: In Clusters If we have an architecture with 2 web servers in a cluster, keep in mind that values stored in the session object of one server, may not be available in the session object on the other server. The solution to this problem would be one of: Do not use session attributes. Use a session database, into which session attributes are written, and from which it is read. Use sticky session, where a user is always sent to the same server, throughout the whole session.

70 HttpSession: Example Create one HTML file: index.html which send user name and password to the servlet file. Create two servlet file, one will save user name into session and that session information is send to another servlet. This example will shows the session tracking.

71 RequestDispatcher The RequestDispatcher class enables your servlet to "call" another servlet from inside another servlet. We can obtain a RequestDispatcher from the HttpServletRequest object. The above code obtains a RequestDispatcher targeted at whatever Servlet (or JSP) that is mapped to the URL /anotherurl.simple.

72 RequestDispatcher You can call the RequestDispatcher using either its include() or forward() method. The forward() method intended for use in forwarding the request, meaning after the response of the calling servlet has been committed. You cannot merge response output using this method. The include() method merges the response written by the calling servlet, and the activated servlet. This way you can achieve "server side includes" using the include().

73 Servlet: Load on start up The <servlet> element has a sub-element called <load-on-startup> which you can use to control when the servlet container should load the servlet. If you do not specify a <load-on-startup> element, the servlet container will typically load your servlet when the first request arrives for it. By setting a <load-on-startup> element, you can tell the servlet container to load the servlet as soon as the servlet container starts. Remember, the servlets init() method is called when the servlet is loaded. <load-on-startup>1</load-on-startup>

74 Cookie HTTP Cookies are little pieces of data that a web application can store on the client machine of users visiting the web application. Typically up to 4 kilo bytes(kb) of data can be store. We can write cookies using HttpServletResponse object: Example: Cookie cookie = new Cookie("myCookie", "mycookievalue"); response.addcookie(cookie);

75 Cookie By default, each request is considered as a new request. In cookies technique, we add cookie with response from the servlet. So cookie is stored in the cache of the browser. After that if request is sent by the user, cookie is added with request by default. Thus, we recognize the user as the old user.

76 Cookie: Types Non-persistent cookie: It is valid for single session only. It is removed each time when user closes the browser. Persistent cookie: It is valid for multiple session. It is not removed each time when user closes the browser. It is removed only if user logout or sign-out or clear cookies/cache memory of browsers.

77 Cookie: Pros/Cons Advantages: Simplest technique of maintaining the state. Cookies are maintained at client side. Disadvantages It will not work if cookie is disabled from the browser. Only textual information can be set in Cookie object.

78 Cookie: Constructor javax.servlet.http.cookie class provides the functionality of using cookies. It provides a lot of useful methods for cookies. Constructor Cookie() Cookie(String name, String value) Description constructs a cookie. constructs a cookie with a specified name and value.

79 Cookie: Methods Useful methods: Method public void setmaxage(int expiry) public String getname() Description Sets the maximum age of the cookie in seconds. Returns the name of the cookie. public String getvalue() public void setname(string name) public void setvalue(string value) Returns the value of the cookie. changes the name of the cookie. changes the value of the cookie.

80 Cookie: Methods Other methods: public void addcookie(cookie ck):method of HttpServletResponse interface is used to add cookie in response object. public Cookie[] getcookies():method of HttpServletRequest interface is used to return all the cookies from the browser.

81 Cookie: How to create? Creating cookie object Cookie ck=new Cookie("user", Sandip"); Adding cookie in the response response.addcookie(ck);//

82 Cookie: For delete Cookies Deleting value of cookie Cookie ck=new Cookie("user",""); Changing the maximum age to 0 seconds ck.setmaxage(0); Adding cookie in the response response.addcookie(ck);

83 Cookie: To get Cookies Cookie ck[]=request.getcookies(); for(int i=0;i<ck.length;i++) { } out.print("<br>"+ck[i].getname()+" "+ck[i].getvalue()); //printing name and value of cookie

84 Cookie: Example

85 Cookie: Example 1. Create one Html file which send user name to first servlet. First servlet file set cookies of that user name and call second servlet file. Second servlet file retrieve name of user from cookies instead of from session.

86 Servlet Filter A filter is an object that is invoked at the preprocessing and post processing of a request. It is mainly used to perform filtering tasks such as conversion, logging, compression, encryption and decryption, input validation etc. The servlet filter is pluggable, i.e. its entry is defined in the web.xml file, if we remove the entry of filter from the web.xml file, filter will be removed automatically and we don't need to change the servlet.

87 Servlet Filter Usage of Filter: recording all incoming requests logs the IP addresses of the computers from which the requests originate conversion data compression encryption and decryption input validation etc

88 Servlet Filter Advantages Filter is pluggable. One filter don't have dependency onto another resource. Less Maintenance.

89 Servlet Filter Three interfaces of Filter API: present in javax.servlet package Filter FilterChain FilterConfig Filter tag is used in web.xml file

90 Applet Servlet Communication URLConnection class is used.

91 MCQ Which is of the following are classes and which are interfaces? 1. Servlet 2. ServletConfig 3. ServletRequest 4. ServletResponse 5. HttpServlet 6. GenericServlet 7. Cookies 8. Session

92 MCQ What is returntype of the getsession() method? 1. Session 2. int 3. HttpSession 4. boolean 5. void

93 MCQ Javax.servlet packages does not have: 1. HttpServlet 2. ServletConfig 3. ServletContext 4. Servlet 5. HttpServletRequest 6. ServletResponse 7. HttpServletResponse 8. Cookies

94 MCQ Javax.servlet packages does not have: 1. HttpServlet 2. ServletConfig 3. ServletContext 4. Servlet 5. HttpServletRequest 6. ServletResponse 7. HttpServletResponse 8. Cookies

95 MCQ Which is correct package for HttpServlet and HttpServletResponse? 1. javax.servlet.*; 2. javax.servlet.http.*; 3. javax.servlet.httpservlet.*; 4. java.lang.*;

96 MCQ Which of the following method is invoked when Http post request? 1. dopost() 2. dopostcall() 3. dohttppost() 4. doput() 5. dotrace() 6. dopostoptions()

97 MCQ Which of the following method is invoked when Http post request? 1. dopost() 2. dopostcall() 3. dohttppost() 4. doput() 5. dotrace() 6. dopostoptions()

98 JSP (Java Server Pages) Java Server Pages (JSP) is a server-side programming technology. It enables the creation of dynamic, platformindependent method for building Web-based applications. JSP have access to the entire family of Java APIs, including the JDBC API to access enterprise databases.

99 JSP (Java Server Pages) JSP technology is used to create web application just like Servlet technology. It can be thought of as an extension to servlet because it provides more functionality than servlet. A JSP page consists of HTML tags and JSP tags. The jsp pages are easier to maintain than servlet because we can separate designing and development. It provides some additional features such as Expression Language, Custom Tag etc.

100 JSP (Java Server Pages) JSP is a technology for developing web pages that support dynamic content which helps developers insert java code in HTML pages by making use of special JSP tags, most of which start with <% and end with %> A JSP component is a type of Java servlet that is designed to fulfill the role of a user interface for a Java web application. Using JSP, you can collect input from users through web page forms, present records from a database or another source, and create web pages dynamically

101 Advantages of JSP over Servlet Extension to Servlet: JSP technology is the extension to servlet technology. We can use all the features of servlet in JSP. In addition to, we can use implicit objects, predefined tags, expression language and Custom tags in JSP, that makes JSP development easy.

102 Advantages of JSP over Servlet Easy to maintain: JSP can be easily managed because we can easily separate our business logic with presentation logic. In servlet technology, we mix our business logic with the presentation logic.

103 Advantages of JSP over Servlet Fast Development: No need to recompile and redeploy: If JSP page is modified, we don't need to recompile and redeploy the project. The servlet code needs to be updated and recompiled if we have to change the look and feel of the application.

104 JSP Lifecycle Translation of JSP Page Compilation of JSP Page Class loading (class file is loaded by the class loader) Instantiation (Object of the Generated Servlet is created). Initialization ( jspinit() method is invoked by the container). Reqeust processing ( _jspservice() method is invoked by the container). Destroy ( jspdestroy() method is invoked by the container).

105 JSP Lifecycle A JSP life cycle can be defined as the entire process from its creation till the destruction which is similar to a servlet life cycle with an additional step which is required to compile a JSP into servlet. Compilation Initialization Execution Cleanup

106 JSP Lifecycle

107 JSP Lifecycle JSP Compilation: Involves three steps Parsing the JSP. Turning the JSP into a servlet. Compiling the servlet. JSP Initialization: public void jspinit(){ // Initialization code... } JSP Execution: void _jspservice(httpservletrequest request, HttpServletResponse response) { // Service handling code... } JSP Cleanup: public void jspdestroy() { // Your cleanup code goes here. }

108 JSP Working

109 JSP Working

110 JSP Scriptlet 1. Java server pages are required to store in..(webapps/root) 2. Does tomcat server required to restart to see updated JSP page.. (YES/NO)

111 JSP Scriptlet A scriptlet can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language. Syntax <% code fragment %> Also can be write <jsp:scriptlet> code fragment </jsp:scriptlet>

112 Hello World or First JSP Program Create Dynamic web project in eclipse. Create one index.jsp file in WebContent folder. Write code in <% out.print(2*4); %> Run Project on Tomcat server.

113 JSP Declarations A declaration declares one or more variables or methods that you can use in Java code later in the JSP file. You must declare the variable or method before you use it in the JSP file. Syntax: Or: Ex: <%! declaration; [ declaration; ]+... %> <jsp:declaration> code fragment </jsp:declaration> <%! int i = 0; %> <%! int a, b, c; %> <%! Circle a = new Circle(2.0); %>

114 JSP Scriptlet and Declaration Jsp Scriptlet Tag The jsp scriptlet tag can only declare variables not methods. Jsp Declaration Tag The jsp declaration tag can declare variables as well as methods. The declaration of scriptlet tag is placed inside the _jspservice() method. The declaration of jsp declaration tag is placed outside the _jspservice() method.

115 JSP Expressions The code placed within JSP expression tag is written to the output stream of the response. So we need not write out.print() to write data. It is mainly used to print the values of variable or method.

116 JSP Expressions Syntax: Or: Ex: <%= expression %> <jsp:expression> expression </jsp:expression> <p> Today's date: <%= (new java.util.date()).tolocalestring()%></p> <%= "welcome to jsp" %> Current Time: <%= java.util.calendar.getinstance().gettime() %>

117 JSP Expressions: Example <html> <body> <%! int cube(int n){ return n*n*n*; } %> <%= "Cube of 3 is:"+cube(3) %> </body> </html>

118 JSP Expressions: Example <html> <html> <body> <%! int data=50; %> <%= "Value of the variable is:"+data %> </body> </html>

119 Implicit Objects/Pre-defined Variables There are 9 jsp implicit objects. These objects are created by the web container that are available to all the jsp pages. No need to create these objects or declared. It will automatically access in each page of jsp.

120 Implicit Objects Object out request response config application session pagecontext page exception Type JspWriter HttpServletRequest HttpServletResponse ServletConfig ServletContext HttpSession PageContext Object Throwable

121 Implicit Objects: out For writing any data to the buffer, JSP provides an implicit object named out. In case of servlet you need to write: PrintWriter out=response.getwriter(); But in JSP, we don't need to write this code. Ex: <% out.print( Hello World ); %>

122 Implicit Objects: request The JSP request is an implicit object of type HttpServletRequest i.e. created for each jsp request by the web container. It can be used to get request information such as parameter, header information, remote address, server name, server port, content type, character encoding etc. Ex: <% String name=request.getparameter("uname"); out.print("welcome "+name); %>

123 Implicit Objects: response response is an implicit object of type HttpServletResponse. The instance of HttpServletResponse is created by the web container for each jsp request. Ex: <% response.sendredirect(" %>

124 Implicit Objects: config config is an implicit object of type ServletConfig. This object can be used to get initialization parameter for a particular JSP page. The config object is created by the web container for each jsp page. Generally, it is used to get initialization parameter from the web.xml file Ex: <% String driver=config.getinitparameter("dname"); %>

125 Implicit Objects: application application is an implicit object of type ServletContext. The instance of ServletContext is created only once by the web container when application or project is deployed on the server. This object can be used to get initialization parameter from configuaration file (web.xml). Ex: <% String driver=application.getinitparameter("dname"); %>

126 Implicit Objects: session session is an implicit object of type HttpSession. The Java developer can use this object to set and get attribute or to get session information. Ex: Suppose index.html which call welcome.jsp by sending user name. <html> <body> <form action="welcome.jsp"> <input type="text" name="uname"> <input type="submit" value="go"><br/> </form> </body> </html>

127 Implicit Objects: session Wecome.jsp read user name from request parameter, set session and call another jsp. <html> <body> <% String name=request.getparameter("uname"); out.print("welcome "+name); session.setattribute("user",name); <a href="second.jsp">second jsp page</a> %> </body> </html>

128 Implicit Objects: session Second jsp page, will get information from session and identify user. <html> <body> <% String name=(string)session.getattribute("user"); out.print("hello "+name); %> </body> </html>

129 JSP Directives The jsp directives are messages that tells the web container how to translate a JSP page into the corresponding servlet. There are three types of directives: page directive include directive taglib directive Syntax of JSP Directive <%@ directive attribute="value" %>

130 JSP Directives: Page The page directive defines attributes that apply to an entire JSP page. Syntax of JSP Directive page attribute="value" %>

131 JSP Directives: Page Attributes of JSP page directive import contenttype extends info buffer language iselignored isthreadsafe autoflush session pageencoding errorpage iserrorpag

132 JSP Directives: Page import The import attribute is used to import class, interface or all the members of a package. It is similar to import keyword in java class or interface Ex: <html> <body> <%@ page import="java.util.date" %> Today is: <%= new Date() %> </body> </html

133 JSP Directives: Page Content type contenttype attribute defines the MIME(Multipurpose Internet Mail Extension) type of the HTTP response. The default value is "text/html;charset=iso ". Ex: <html> <body> page contenttype=application/msword %> Today is: <%= new java.util.date() %> </body> </html>

134 JSP Directives: Page extends The extends attribute defines the parent class that will be inherited by the generated servlet. It is rarely used. Ex: page extends="mypackage.sampleclass"%>

135 JSP Directives: Page info This attribute simply sets the information of the JSP page which is retrieved later by using getservletinfo() method of Servlet interface. It is rarely used. Ex: <html> <body> page info="composed by Sonoo Jaiswal" %> Today is: <%= new java.util.date() %> </body> </html>

136 JSP Directives: session For setting session: true/false By-default: true Ex: page session="true"%> Or page session="false"%>

137 JSP Directives: include The include directive is used to include the contents of any resource it may be jsp file, html file or text file. The include directive includes the original content of the included resource at page translation time. Advantage: code reusability. Syntax: include file="resourcename" %> Ex: <html><body> include file="header.html" %> Today is: <%= java.util.calendar.getinstance().gettime() %> </body></html>

138 JSP Directives: taglib JSP taglib directive is used to define a tag library that defines many tags. We use the TLD (Tag Library Descriptor) file to define the tags. Syntax: <%@ taglib uri="uriofthetaglibrary" prefix="prefixoftaglibrary" %> Ex: In this example, we are using our tag named currentdate. To use this tag we must specify the taglib directive so the container may get information about the tag. <html><body> <%@ taglib uri=" prefix="mytag" %> <mytag:currentdate/> </body></html>

139 JSP API Two packages: javax.servlet.jsp javax.servlet.jsp.tagext javax.servlet.jsp: It has two interfaces and many classes Interfaces: JspPage HttpJspPage Classes JspWriter PageContext JspFactory JspEngineInfo JspException JspError

140 JspPage & HttpJspPage Interface

141 JspPage & HttpJspPage Interface JspPage Interface: According to the JSP specification, all the generated servlet classes must implement the JspPage interface. It extends the Servlet interface. It provides two life cycle methods. public void jspinit(): public void jspdestroy() HttpJspPage Interface: The HttpJspPage interface provides the one life cycle method of JSP. It extends the JspPage interface. public void _jspservice()

Unit 5 JSP (Java Server Pages)

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

More information

Advantage of JSP over Servlet

Advantage of JSP over Servlet JSP technology is used to create web application just like Servlet technology. It can be thought of as an extension to servlet because it provides more functionality than servlet such as expression language,

More information

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

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

More information

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

Java Server Pages JSP

Java Server Pages JSP Java Server Pages JSP Agenda Introduction JSP Architecture Scripting Elements Directives Implicit Objects 2 A way to create dynamic web pages Introduction Separates the graphical design from the dynamic

More information

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming PSD1B Advance Java Programming Unit : I-V PSD1B- Advance Java Programming 1 UNIT I - SYLLABUS Servlets Client Vs Server Types of Servlets Life Cycle of Servlets Architecture Session Tracking Cookies JDBC

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

Servlet Fudamentals. Celsina Bignoli

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

More information

JAVA SERVLET. Server-side Programming INTRODUCTION

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

More information

Experiment No: Group B_2

Experiment No: Group B_2 Experiment No: Group B_2 R (2) N (5) Oral (3) Total (10) Dated Sign Problem Definition: A Web application for Concurrent implementation of ODD-EVEN SORT is to be designed using Real time Object Oriented

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

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

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

More information

Questions and Answers

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

More information

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 4 Java Server Pages

Unit 4 Java Server Pages Q1. List and Explain various stages of JSP life cycle. Briefly give the function of each phase. Ans. 1. A JSP life cycle can be defined as the entire process from its creation till the destruction. 2.

More information

Introduction to JSP and Servlets Training 5-days

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

More information

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

Advance Java. Configuring and Getting Servlet Init Parameters per servlet

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

More information

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

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

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

More information

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

Unit-4: Servlet Sessions:

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

More information

COMP9321 Web Application Engineering

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

More information

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

SNS COLLEGE OF ENGINEERING, Coimbatore

SNS COLLEGE OF ENGINEERING, Coimbatore SNS COLLEGE OF ENGINEERING, Coimbatore 641 107 Accredited by NAAC UGC with A Grade Approved by AICTE and Affiliated to Anna University, Chennai IT6503 WEB PROGRAMMING UNIT 04 APPLETS Java applets- Life

More information

Enterprise Computing with Java MCA-305 UNIT II. Learning Objectives. JSP Basics. 9/17/2013MCA-305, Enterprise Computing in Java

Enterprise Computing with Java MCA-305 UNIT II. Learning Objectives. JSP Basics. 9/17/2013MCA-305, Enterprise Computing in Java Enterprise Computing with Java MCA-305 UNIT II Bharati Vidyapeeth s Institute of Computer Applications and Management, New Delhi-63, by Ms. Ritika Wason UII. # Learning Objectives JSP Basics and Architecture:

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

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

ADVANCED JAVA COURSE CURRICULUM

ADVANCED JAVA COURSE CURRICULUM ADVANCED JAVA COURSE CURRICULUM Index of Advanced Java Course Content : 1. Basics of Servlet 2. ServletRequest 3. Servlet Collaboration 4. ServletConfig 5. ServletContext 6. Attribute 7. Session Tracking

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

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

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

More information

The Servlet Life Cycle

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

More information

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

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

More information

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

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

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

About the Authors. Who Should Read This Book. How This Book Is Organized

About the Authors. Who Should Read This Book. How This Book Is Organized Acknowledgments p. XXIII About the Authors p. xxiv Introduction p. XXV Who Should Read This Book p. xxvii Volume 2 p. xxvii Distinctive Features p. xxviii How This Book Is Organized p. xxx Conventions

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

Fast Track to Java EE

Fast Track to Java EE Java Enterprise Edition is a powerful platform for building web applications. This platform offers all the advantages of developing in Java plus a comprehensive suite of server-side technologies. This

More information

Enterprise Java Unit 1- Chapter 3 Prof. Sujata Rizal Introduction to Servlets

Enterprise Java Unit 1- Chapter 3 Prof. Sujata Rizal Introduction to Servlets 1. Introduction How do the pages you're reading in your favorite Web browser show up there? When you log into your favorite Web site, how does the Web site know that you're you? And how do Web retailers

More information

Java Server Pages. Copyright , Xiaoping Jia. 7-01/54

Java Server Pages. Copyright , Xiaoping Jia. 7-01/54 Java Server Pages What is Java Server Pages (JSP)? HTML or XML pages with embedded Java code to generate dynamic contents. a text-based document that describes how to process a request and to generate

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

UNIT -5. Java Server Page

UNIT -5. Java Server Page UNIT -5 Java Server Page INDEX Introduction Life cycle of JSP Relation of applet and servlet with JSP JSP Scripting Elements Difference between JSP and Servlet Simple JSP program List of Questions Few

More information

One application has servlet context(s).

One application has servlet context(s). FINALTERM EXAMINATION Spring 2010 CS506- Web Design and Development DSN stands for. Domain System Name Data Source Name Database System Name Database Simple Name One application has servlet context(s).

More information

Java servlets CSCI 470: Web Science Keith Vertanen Copyright 2013

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

More information

JavaServer Pages. Juan Cruz Kevin Hessels Ian Moon

JavaServer Pages. Juan Cruz Kevin Hessels Ian Moon Page 1 of 14 JavaServer Pages Table of Contents 1. Introduction What is JSP? Alternative Solutions Why Use JSP? 2. JSP Process Request Compilation Example 3. Object Instantiation and Scope Scope Synchronization

More information

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

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

More information

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

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

Table of Contents. Introduction... xxi

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

More information

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

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

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

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

More information

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

First Simple Interactive JSP example

First Simple Interactive JSP example Let s look at our first simple interactive JSP example named hellojsp.jsp. In his Hello User example, the HTML page takes a user name from a HTML form and sends a request to a JSP page, and JSP page generates

More information

DVS WEB INFOTECH DEVELOPMENT TRAINING RESEARCH CENTER

DVS WEB INFOTECH DEVELOPMENT TRAINING RESEARCH CENTER DVS WEB INFOTECH DEVELOPMENT TRAINING RESEARCH CENTER J2EE CURRICULUM Mob : +91-9024222000 Mob : +91-8561925707 Email : info@dvswebinfotech.com Email : hr@dvswebinfotech.com 48, Sultan Nagar,Near Under

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

Basic Principles of JSPs

Basic Principles of JSPs 5 IN THIS CHAPTER What Is a JSP? Deploying a JSP in Tomcat Elements of a JSP Page Chapter 4, Basic Principles of Servlets, introduced you to simple Web applications using servlets. Although very useful

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

PES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II

PES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II PES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II Subject Name: Advanced JAVA programming Subject Code: 13MCA42 Time: 11:30-01:00PM Max.Marks: 50M ----------------------------------------------------------------------------------------------------------------

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

SCWCD Study Guide Exam: CX

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

More information

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

JSP - SYNTAX. Any text, HTML tags, or JSP elements you write must be outside the scriptlet. Following is the simple and first example for JSP:

JSP - SYNTAX. Any text, HTML tags, or JSP elements you write must be outside the scriptlet. Following is the simple and first example for JSP: http://www.tutorialspoint.com/jsp/jsp_syntax.htm JSP - SYNTAX Copyright tutorialspoint.com This tutorial will give basic idea on simple syntax ie. elements involved with JSP development: The Scriptlet:

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

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

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

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

COMP9321 Web Application Engineering

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

More information

JAVA MICROSERVICES. Java Language Environment. Java Set Up. Java Fundamentals. Packages. Operations

JAVA MICROSERVICES. Java Language Environment. Java Set Up. Java Fundamentals. Packages. Operations Java Language Environment JAVA MICROSERVICES Object Oriented Platform Independent Automatic Memory Management Compiled / Interpreted approach Robust Secure Dynamic Linking MultiThreaded Built-in Networking

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

1Z Java EE 6 Web Component Developer Certified Expert Exam Summary Syllabus Questions

1Z Java EE 6 Web Component Developer Certified Expert Exam Summary Syllabus Questions 1Z0-899 Java EE 6 Web Component Developer Certified Expert Exam Summary Syllabus Questions Table of Contents Introduction to 1Z0-899 Exam on Java EE 6 Web Component Developer Certified Expert... 2 Oracle

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

ive JAVA EE C u r r i c u l u m

ive JAVA EE C u r r i c u l u m C u r r i c u l u m ive chnoworld Development Training Consultancy Collection Framework - The Collection Interface(List,Set,Sorted Set). - The Collection Classes. (ArrayList,Linked List,HashSet,TreeSet)

More information

Ch04 JavaServer Pages (JSP)

Ch04 JavaServer Pages (JSP) Ch04 JavaServer Pages (JSP) Introduce concepts of JSP Web components Compare JSP with Servlets Discuss JSP syntax, EL (expression language) Discuss the integrations with JSP Discuss the Standard Tag Library,

More information

Java- EE Web Application Development with Enterprise JavaBeans and Web Services

Java- EE Web Application Development with Enterprise JavaBeans and Web Services Java- EE Web Application Development with Enterprise JavaBeans and Web Services Duration:60 HOURS Price: INR 8000 SAVE NOW! INR 7000 until December 1, 2011 Students Will Learn How to write Session, Message-Driven

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

Advanced Java Programming

Advanced Java Programming Advanced Java Programming Length: 4 days Description: This course presents several advanced topics of the Java programming language, including Servlets, Object Serialization and Enterprise JavaBeans. In

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

Data Source Name (Page 150) Ref: - After creating database, you have to setup a system Data Source Name (DSN).

Data Source Name (Page 150) Ref: - After creating database, you have to setup a system Data Source Name (DSN). CS 506 Solved Mcq's Question No: 1 ( M a r k s: 1 ) DSN stands for. Domain System Name Data Source Name (Page 150) Ref: - After creating database, you have to setup a system Data Source Name (DSN). Database

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

JavaServer Pages. What is JavaServer Pages?

JavaServer Pages. What is JavaServer Pages? JavaServer Pages SWE 642, Fall 2008 Nick Duan What is JavaServer Pages? JSP is a server-side scripting language in Java for constructing dynamic web pages based on Java Servlet, specifically it contains

More information

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

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

More information

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format. J2EE Development Detail: Audience www.peaksolutions.com/ittraining Java developers, web page designers and other professionals that will be designing, developing and implementing web applications using

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

JSP MOCK TEST JSP MOCK TEST III

JSP MOCK TEST JSP MOCK TEST III http://www.tutorialspoint.com JSP MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to JSP Framework. You can download these sample mock tests at your local

More information

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0 Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0 QUESTION NO: 1 To take advantage of the capabilities of modern browsers that use web standards, such as XHTML and CSS, your web application

More information

A Gentle Introduction to Java Server Pages

A Gentle Introduction to Java Server Pages A Gentle Introduction to Java Server Pages John Selmys Seneca College July 2010 What is JSP? Tool for developing dynamic web pages developed by SUN (now Oracle) High-level abstraction of Java Servlets

More information

JavaEE Interview Prep

JavaEE Interview Prep Java Database Connectivity 1. What is a JDBC driver? A JDBC driver is a Java program / Java API which allows the Java application to establish connection with the database and perform the database related

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

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

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

LTBP INDUSTRIAL TRAINING INSTITUTE

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

More information

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

LearningPatterns, Inc. Courseware Student Guide

LearningPatterns, 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 information

Component Based Software Engineering

Component Based Software Engineering Component Based Software Engineering Masato Suzuki School of Information Science Japan Advanced Institute of Science and Technology 1 Schedule Mar. 10 13:30-15:00 : 09. Introduction and basic concepts

More information

directive attribute1= value1 attribute2= value2... attributen= valuen %>

directive attribute1= value1 attribute2= value2... attributen= valuen %> JSP Standard Syntax Besides HTML tag elements, JSP provides four basic categories of constructors (markup tags): directives, scripting elements, standard actions, and comments. You can author a JSP page

More information

Watch Core Java and Advanced Java Demo Video Here:

Watch Core Java and Advanced Java Demo Video Here: Website: http://www.webdesigningtrainingruchi.com/ Contact person: Ranjan Raja Moble/Whatsapp: +91-9347045052 / 09032803895 Dilsukhnagar, Hyderabad Email: webdesigningtrainingruchi@gmail.com Skype: Purnendu_ranjan

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

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

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

More information