Web Application

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Web Application as PDF for free.

More details

  • Words: 1,567
  • Pages: 6
Web Application – set of web pages generated in response to user requests. For example search engines, online stores, auctions, news sites, discussion groups, and games. Because it is a type of client-server application (connected through internet or intranet), the components of a web application are stored on either the client computer or the server computer. These web applications are stored on the server computer which runs software like Apache HTTP Server, namely web servers that enables it to send web pages to web browsers (the clients) that make the request for a particular web page. The web browser provides the user interface for the application, but it does not care if the HTTP response was received from the static HTML file or was dynamically generated by the web application. Its duty is to display the HTTP response obtained as a HTML. The server computer also runs a database management system, for JSP and Servlet applications Oracle and mySQL are two common DB’s. HTML – Hypertext Markup Language is the language that the web browser converts into the web pages of a web application. Static web pages – HTML document that’s stored in a file and does not change as response to the user request. It comes with an extension of .htm or .html. Dynamic web pages – HTML document generated by the web application based on the parameters sent by the client as part of the HTTP request. Web browser and server communicates through internet using the HTTP – Hyper Text Transfer Protocol for sending and receiving message namely the HTTP request and the HTTP response. A servlet and JSP engine or servlet and the JSP container is the software that allows the web server to work with servlets and the JSP. TOMCAT is one of the most popular sevlet and JSP engine. For such a engine to work properly it should be able to access the Java’s SDK. Intro to JSP: embedment of JAVA code within the HTML. When a JSP is requested for the first time, the JSP engine (which is part of the servlet and the JSP engine) converts the JSP into a sevlet (a normal JAVA class extending the HTTPServlet) and compiles the same. Then the JSP loads that servlet into the servlet engine which runs it. For subsequent requests, the JSP engine runs the sevlet that corresponds to the JSP. JSP is mainly for the presentation. Intro to Servlets: embedment of HTML within the JAVA code. A servlet is a java class that runs on a server. Although servlets are commonly used for the web applications, they can also be used for other types of applications like mail or FTP server applications. Servlets are mainly used for the processing required by the web pages.

There are three different types of platforms that can use for developing servlets and JSPs. They are single PC, LAN or the internet. System requirements for these platforms respectively, 1) PC – Java SDK, web server, a servlet and JSP engine (TOMCAT) and a DBMS (mySQL) 2) LAN – small group, then the server can run TOMCAT as both the web server and the servlet and JSP engine, and mySQL. Then the client needs the Java SDK and the servlet.jar file. When run web applications on LAN, it functions as intranet. 3) Internet – large working group, normally will use the Apache as the WebServer and a product like Tomcat as just the servlet and JSP engine. Otherwise this works the same as over LAN. Architecture for JSP and Servlet applications: This architecture includes 3 layers namely Presentation layer, Business rules layer and the Data access layer. 1) Presentation layer: for a typical web application consists of HTML pages and JSPs. 2) Business Rules Layer: for a typical web application consists of servlets and javabeans. The servlets will call other classes to store or to retrieve data (to or ) from a database and they may forward the results to another JSP or a servlet. The javabeans are used to temporarily store and process data, and typically used to define a business object such as a User or Invoice object. 3) Data access Layer: for a typical web application consists of classes that read and write data that’s stored on the server’s disk drive. Note: For a serious web application, the data is usually stored in a relational database. However it may also be stored in binary files or text files or in XML files. ServletConfig.getInitParameter() – to get info specific to a single servlet. ServletContext.getInitParameter() – to get info common to all servlets.

MVC Patterned architecture for a web application: This is the model 2 architecture, where in the model consists of the java-beans, view consists of HTML documents and JSPs and the controller consists of servlets. RequestDispatcher.forward(httpReq, httpResp) – method used to forward the request from the servlet to a JSP. Difference between including the file at translation time and the request time: S.No.

JSP include directive:

JSP include action:

This is to include a file in a JSP at compile time (i.e.) translation time.

This is to include a file in a JSP at runtime or the request time.

Example :

Example :

<%@ include file = “file Location And Name” %>

<jsp:include page = “file Location And Name” flush = “true” %>

3

When the include directive is used, the code in the included file becomes part of the generated servlet. As a result, any changes to the included file don’t appear in the JSP until the JSP is retranslated and recompiled.

When the include action, the code in the included file is not part of the generated servlet. As a result, any changes to the included file appear in the JSP the next time it is requested.

4

When the file is included at the translation time, the included file has access to all variables and methods defined in the JSP, including the request object.

When the file is included at the request time, the included file does not have access to these variables.

1

2

Session information is stored in cookies.

Methods used for working with Session: Methods to add, get and remove objects to a session: HttpSession session = request.getSession(); session.setAttribute(“productCode”, productCode); Cart cartObj = (Cart) session.getAttribute(“productCode”); session.removeAttribute(“productCode”); getAttributeNames() – returns an enumeration object that contains the names of all the attributes in the HttpSession object. getId() – to get the unique session id that the servlet engine generates for each session. setMaxInactiveInterval(int seconds) – time interval to invalidate a session, and to create a session that won’t end until the user closes the browser if a negative value such as -1. invalidate() – this method invalidates the session and unbinds any objects that are bound to it.

Method for urlEncoding: Used when the user disabled per-session cookies. response.encodeURL(“ < URL for the resource of the web application >”);

Methods used for working with Cookies: public Cookie(String cookieName, String cookieValue) – constructor of the cookie class. setMaxAge(int lifeInSecs) – life period for the cookie, the value -1 will make it persession cookie. getName() and getValue() - to get the name wise each cookie and its value. addCookie(Cookie cookieName) - response object’s method to add the cookie to the response object. Note: To delete all persistent-cookies by iterating through the length of the cookies object, set the life period to ‘0’ for each cookie using the methods getName(), getValue(), and setMaxAge(int lifeInSecs).

Four important methods of the Cookie class: 1) setPath(String path) – by default when the user send a cookie, the browser will send it only to the servlets and JSPs within the directory and the sub-directory that sent the cookie. But to make it available to the entire application this method is used with the argument as “/”.

2) setDomain(String domainPattern) – By default, the browser only returns a cookie to the host that sent the cookie. To return a cookie to other hosts within the same domain, a domain pattern can be set like .ads.com. Then the browser will return the cookie to any subdomain of www.ads.com like www.ads.camera.com. 3) setSecure(boolean flag) – by default the browser sends a cookie over a regular connection or an encrypted connection. To protect the cookies that store sensitive data such as passwords or credit card number, by supplying ‘true’ as value to this method, the cookie will be sent over a secure connection. 4) setVersion(int versionNumber) – by default, java creates cookies that use version 0 of the cookie protocol. If required specify the value 1 to use the new version 1 of the cookie protocol.

JDBC Information: Result Set types: Common types are read-only, forward-only. JDBC version 2.0 and 3.0 supports scrollable and updateable result-sets also.

Prepared Statements: 1) When you use the prepared statements in your java programs, the database server only has to check for the syntax and prepare an execution plan for each SQL statement. 2) To specify the parameters for an SQL statements use the ‘?’, and to supply the values for those parameters use the ‘set’ method of the java.sql.PreparedStatement interface. 3) To execute a SELECT statement use the executeQuery() method and to execute any UPDATE or DELETE statement use the executeUpdate() method.

ResultSetMetaData: This type of object contains information about the result set including the number of columns and the names of the columns. To get those information use the getColumnCount() and getColumnName() methods.

Related Documents

Web Application
November 2019 26
Web Application
November 2019 30
Web Base Application
November 2019 4