Industrial Training A Report Submitted in Partial fulfillment for the award of Bachelor of Engineering in Computer Science & Engineering Submitted to RAJIV GANDHI PROUDYOGIKI VISHWAVIDYALAYA BHOPAL (M.P) WEB DESIGNING Submitted by Manish Sen [0126CS081051] DEPARTMET OF COMPUTER SCIENCE & ENGINEERING
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Industrial Training
A ReportSubmitted in Partial fulfillment for the award of
Bachelor of Engineering in Computer Science & Engineering
DEPARTMET OF COMPUTER SCIENCE & ENGINEERINGTHAKRAL COLLEGE OF
TECHNOLOGY, BHOPAL (M.P.)SESSION Dec-2011
Company Profile:
Quality Policy :
“ HCL are committed to provide quality training, projects and consultancy with students and industry centric requirements and by continually improving the quality management system”
ORGANIZATION CHART
HCL is India's pioneer in Internet and eCommerce and offers integrated end-to-end solutions with a comprehensive range of products and services, for both the Business to Consumer (B2C) and Business to Business (B2B) segments, that cover the four critical cornerstones of the Net: Connectivity, Content, Commerce and Community.
HCL’s, mission is to "Make the Internet work for you."
HCL enable this through the products, services and technology that it offer. And in the comprehensive suite of Business to Consumer and Business to Business eCommerce solutions.
HCL’s cutting edge B2B services including connectivity solutions like Electronic Data Interface, Virtual Private Networks, Security Services, Network Management Services as well as eSolutions services that include Internet Consulting, Solutions
SOFTWARE DEVELOPERS / FACULTY
DIRECTOR
PROJECT INCHARGE
GUEST FACULTY
PEON
OFFICE INCHARE
COUNSELOR
LAB INSTRUCTER
Architectures, Design and Development of Solutions, Hosting and Management Services and eCommerce products, are relied upon by leading Corporates in India.
HCL Statement of Purpose
HCL’s purpose is to make a qualitative difference to the lives of millions of people and organisations by harnessing the power of India and of the Internet. HCL will do this by empowering them with the potential of the Internet and by leveraging the capabilities of Indian Knowledge Resources.
HCL Statement of Vision
HCL’s vision is to be the dominant and profitable India centric Internet company by: Building on India's unique advantages. Being the leader in terms of market share, quality, revenue, growth and gross
margins. Adding value to our stakeholders: namely customers, peers and associates. Being enablers and catalysts of the Internet for positive change.
HCL’s Credo
I will always treat others with dignity, courtesy and respect. I will work like an entrepreneur with urgency in thought and action. I will put customer needs first, delivering quality solutions that are of value
to them. I will always pursue excellence in my work. I will be open, honest and sincere with colleagues, customers, vendors and
everyone I deal with. I will always do what I have committed to do. I will always remember that I am part of a team.
HCL CENTER
Hcl Career Development Center Bhopal (Ph 4094357,4094852)
Introduction:
During the industrial training the topics and knowledge about the technologies which we came to know are as follow:
Web Technologies Enterprise Technologies Benefits of Web Application over Desktop Scope of Web application Architecture of Web Application Ingredients of web application Client side & Server side Technologies
Web Technologies:
Servlets Java Server Pages (JSP) Java Server Faces (JSF)
Enterprise Technologies
Enterprise Java Beans
Benefits of Web Application over Desktop
No geographical constraints No software required on the client side (only browser is needed) Multiple users Distributed Architecture Easy Maintenance Security
Scope of Web application
Internet (WAN) / Intranet (LAN) / Extranet (MAN)
Architecture of Web Application
3-tier (Web Technologies)
Front End (HTML/Applet) Middleware (Servlets/JSP/JSF) Back End
n-tier (Enterprise Technologies)
Front End (HTML/Applet)
Front End
Middleware
Back End
Middleware (Servlets/JSP/JSF) Business Logic (EJB) Back End
Client side & Server side Technologies
HTML Used for designing / user interface Client Side Scripting Validation of data on client machine. Example
New User Cascading Style Sheets Used for formatting multiple web pages
DHTML = HTML + Client side Scripting + Cascading Style Sheets
Server Side Technologies
Server Side ScriptingGenerates dynamic web pages that include security, database &
customization.
Database
Front End
Back End
Business logic
Middleware
mobile
Web tech.Front End
Ingredients of web application
Client side: HTML, JavaScript, CSS
Software required on client: Browser (IE)
Server side: Servlets/ JSP / JSF
Software required on server: Web Server, Database
HTML
+ HTML is an acronym of Hypertext Markup Language.+ In markup languages the text is marked in within TAGS.+ These TAGS are in pairs, they have an opening TAG & closing TAG.
<B> Hello World </B>
+ All markup languages are derived from “SGML” (Standard Generalized Markup Language).
+ Example: HTML, WML, XML.
Definition+ HTML is a collection of pre-defined TAGS taken from SGML that defines
the display attribute of the data.+ XML is a collection of user-defined TAGS taken from SGML that defines the
storage attribute of the data.
NOTE: These things have been defined by W3C “World Wide Web Consortium”.We are going to study HTML TAGS under the following categories:
1. Basic TAGS2. Formatting TAGS3. Lists4. Tables5. Inter and Intra document Links6. Forms7. Frames
Basic TAGS
NOTE: HTML is not case sensitive.
<HTML>…</HTML> + This TAG marks the beginning & end of HTML document.+ HTML document is divided in 2 parts
1. Head2. Body
<HEAD>…</HEAD>+ This TAG marks the beginning & end of HEAD part of HTML document.
<BODY>…</Body>+ This TAG marks the beginning & end of BODY part of HTML document.
<TITLE>…</TITLE>+ This TAG defines the title of the HTML document.+ This TAG should always be written within HEAD part.
Software requirement for HTML: Browser (IE)
Steps to create & execute an HTML document
1. Open Notepad.2. Type the HTML document.
<HTML><Head>
<Title> First Page </title></head><Body>
This is my first page.</Body>
</HTML>3. Save it as AnyName.html or AnyName.htm4. Open Browser5. File | Open | <Browse the HTML file>6. To view the HTML code
View | Source OR Context Menu | View Source7. To refresh an HTML page
View | Refresh OR F5
Formatting TAGS
+ Html supports 6 levels of heading starting from H1 to H6<H1> this is for Heading 1 </H1><H2> this is for Heading 2 </H2><h3> this is for Heading 3 </h3><h4> this is for Heading 4 </h4><h5> this is for Heading 5 </h5><h6> this is for Heading 6 </h6>
+ The difference is in size. Default Alignment is “left”.<H1 ALIGN = “Right”> Heading One </H1> TAG+ <H1>…</H1> TAG, H1 is element, ALIGN is attribute.+ An element can have more than one attribute separated by “SPACE”.
<B> This is for Bold </B><I> This is for Italic </I><u> This is for Underline </u><B><I><u> This is for Bold, Italic and Underline </u></I></B><strike> Strike Through </strike> Strike Through<blink> For blinking text </blink> (Netscape only)<font> specifies, font name, size & color </font>
<font name = “Arial, Algerian” size = 4> Hello </font>
1st preference 2nd preference else default
<font name = “Arial, Algerian” size = 4 color =”red”> Hello </font><font color = “#ff0000”> hello </font>
Format = #rrggbbrr, gg, bb can go from 00 to ff (0 to 255)
<pre> This is for pre-formatted text </pre><pre>
One Two ThreeFour Five Six
</pre><P>This is for paragraph </p><p ALIGN="Justify"> This is for paragraph </p>+ <P>…</p> is the only TAG supporting justified alignment.<BR> this is for line break<hr> This is for horizontal Ruler<hr width = 30%> + <hr> has default alignment “CENTER”.+ <BR>, <hr> are known as empty TAGS.
Superscript 2<sup>2</sup> 22
Subscript H<sub>2</sub>O H2O<address> This is used for writing web addresses </address>EX. <address> [email protected] </address><code> This is used for writing coding within document </code><code>
int a, b; <BR>a = 10; <BR>b = 20; <BR>
</code>
<marquee> This is for scrolling text </marquee>+ Attributes are bgcolor, width, direction, behavior (alternate)
Lists in HTML
HTML supports 3 types of List1. Ordered List2. Unordered List3. Definition List
Ordered List<ol>
<LI> This is Point one | 1. This is Point One<LI> This is Point one | 2. This is Point One<LI> This is Point one | 3. This is Point One
</ol>
ol: ordered listli: list index
<ol start = 6><LI> This is Point one | 6. This is Point One<LI> This is Point one | 7. This is Point One<LI> This is Point one | 8. This is Point One
</ol>
Unordered Listul: unordered list<UL>
<LI> This is Point one<LI> This is Point one<LI> This is Point one
</UL>
This is Point one This is Point one This is Point one
Definition List<dl><dt>Term </dt>
<dd> definition </dd><dt>HTML </dt>
<dd> Hypertext Markup Language </dd><dt>CGI </dt>
<dd> Common Gateway Interface</dd></dl>
Links in HTML
There are 2 types of Links1. Inter-document links (between 2 pages)2. Intra-document links (within a page)
To create links HTML provides <a>.....</a> Attributes:
To create intra document link1. Name the Part of the page
<a NAME="LinkName"> -----Data------ </a>2. Create a link for it.<a href="#LinkName"> Link </a>
Images+ Calling Images within HTML
To call image within HTML <img> is used<img>Attributes:src: Specifies source fileborder: specifies border widthwidth: specifies width of imageheight: specifies height of imagealt: specifies alternative text
Tables in HTML
< TABLE >…</TABLE>Marks beginning and end of Table
<TR>…</TR>Marks beginning and end of Table Row
<TH>…</TH>Marks beginning and end of Table Heading Cell
<TD>…</td>Marks beginning and end of Table Data Cell
< TABLE >…</TABLE>Attributes of table are:
width: Specifies table widthcellspacing: Specifies space between 2 cellscellpadding: Specifies space within a cellbgcolor: Specifies background colorborder: Specifies border width
<TD>…</TD> and <TH>…</TH>Attributes are:
bgcolor: Specifies background coloralign: Can be left, right or centervalign: Can be top, bottom or centercolspan: Number of columns to coverrowspan: Number of rows to cover
<frameset>…</frameset>+ This TAG is used to divide browser window in parts (rows and columns)+ This TAG is supported only by IE. Netscape does not support this TAG.+ This TAG should be written within HEAD part of HTML document.
Forms+ To create Forms in HTML < FORM >...</FORM> is used.+ Objective is to take input from user.< FORM >…</FORM>
+ marks the beginning & end of HTML form.Attributes of < FORM >...</FORM> are
Name: Specifies form namemethod: GET or POST
GET is used to fetch details from serverPOST is used to send details to server
action: Specifies the server side file to be called
HTML provides the following form elements
1. Text: To accept single line text2. TextArea: To accept multiline text3. Password: To accept passwords4. Button: To Trigger an action5. Submit: Special button used for form submission. (Calls the file mentioned in action attribute of FORM TAG) 6. Reset: Special button used for clearing contents of a form7. Hidden: To create a hidden form field.8. Checkbox: To select one or more options9. Radio: To select one out of multiple10. Select: To select one or more options
<Input>…</Input>+ It is used to create text, password, button, submit, reset, radio, checkbox, hidden.
Attributes: + type: can be text, password, button, submit, reset, radio, checkbox, hidden
+ name: specifies input name + value: specifies value for text, password, radio, checkbox and hidden. Also specifies caption of button, submit or reset + checked: only for radio and checkbox + size: specifies visible width of text, password + maxlength: maximum num. of characters in text or password.
<TextArea>.....</TextArea>
+ It is used to create multiline text.Attributes are:
rows: specifies no. of rowscolumns: specifies no. of columnsname: specifies name of textarea
+ It is used as substitute for radio & checkbox.Attributes are:
Name: specifies select nameMultiple: specifies that more than one option can be selected.Size: specifies visible no. of rows.
Servlets
+ Servlets are small programs written in Java executed in server. They are the server side applets.
+ Objective of servlets is to generate dynamic web pages. These dynamic web pages include security, user preferences & customization.
Software Requirements + Web Technologies
+ J2SE 5.0+ Web Server (Apache Tomcat*, JRun, Resin)+ Database
+ Enterprise Technologies+ J2EE 5.0This includes Java application server that is capable to execute both web &
enterprise applications and a database called Derby database.
Steps for installation 1. Install JDK 1.52. Set the path
+ Every request/response carries some data & headers.+ The headers that are delivered from client to server are called request headers.+ The headers that are delivered from server to client are called response headers.+ One of the important request headers is method.
+ Method can contain 7 possible values.1. GET
+ It is used to fetch details from server.+ Most browsers limit the data to 240 characters but IE 6 can support up to 1024 characters.+ This data is known as “Query String”.+ This gets appended at the end of the URL.+ Format
?var1=value1&var2=value2+ Query String starts with “?” and is separated by “&” and contains variables and its values.+ It is the default method.+ It is not a safe method as data is visible at address bar, history, favorites, and server log files.
2. POST+ It is used to send details to server.+ It can carry any size of data.+ This data is not visible.It is a safe method.
3. PUT+ It is used to place file on server.
4. DELETE+ It is used to delete file from server.
5. HEADER+ To check response header.
6. TRACE+ To check request header.
response
Web Server
DBA
Client
Browser Server Side
Services
request
Server
Makes use of
calls
Servlets
Receives request
Servlet Basics
+ Any servlet created by the user should implement Servlet interface.+ This done indirectly by inheriting GenericServlet or HttpServlet. + HttpServlet is also a derived class of GenericServlet.+ GenericServlet can give response to all requests including Http request.
+ GenericServlet and its supporting classes come from javax.servlet package.+ HttpServlet and its supporting classes come from javax.servlet.http package.+ Both these packages come from Tomcat 4.1 servlet.jarTomcat 5.5 servlet-api.jarSun Application Server j2ee.jar
There are 3 methods in the lifecycle of Servlet
public void init()// It is used for initialization// called only once when the Servlet is loaded in Web Servers memorypublic void service(ServletRequest req, ServletResponse res)// it is called for each Requestpublic void destroy()// It is used for releasing of resources.// called when the web server is closed.
Request+ To work on Request Servlet provides “HttpServletRequest”. + It comes from javax.servlet.http package.+ Request carries data & headers.String getParameter(String name)String[] getParameterValues(String name)Enumeration getParameterNames()
C:\Windows\Desktop>javap javax.servlet.http.HttpServletRequest + Used to list all the methods in the specified class
Execution of a Servlet+ There are 3 ways to execute/invoke a Servlet.
Server Client+ To work on response, servlet provides “HttpServletResponse”.+ This class comes from javax.servlet.http package.+ There are two things carried along with response.
1. Data2. Headers
Response Headers+ Allow: methods allowed by server+ Cache-Control:
Possible value can be:public, private, no-cache, no-store, must-revalidate, proxy-revalidate, max-age =XXX,
s-max-age =XXX (in seconds)setHeader(“Cache-Control”, “no-cache”);setHeader(“Pragma”, “no-cache”);+ Connection: keep-alive, closed
+ Content-Encoding+ Content-Language+ Content-Length+ Content-Type+ Expires+ Last-Modified+ Location: If changed what is the new location+ Pragma+ Refresh: specifies the time in seconds after which the page should be refreshed.
To set response header two methods are there1) General 2) Specific
General Method setHeader(String name, String value)setIntHeader(String name, int value)setDateHeader(String name, int value)
Specific MethodssetContentType(String contenttype)setContentLength(int length)
The HTTP Status Codes
HTTP 1.1 status codes can be classified in 5 gengeral categories 100-199:
Codes in 100’s are informational, indicating that client should respond with other action.
200-299:Codes in 200’s signify, that response was successful.
300-399:Values in the 300’s are used for files that have moved and usually include a location header indicating the new address.
400-499:Values in 400’s indicates an error by client.
500-599:Codes in the 500’s signify an error by server.
public void sendRedirect(String url)Pre-requisites
+ PrintWriter should not be fetched and Content-Type should not be set. Reason: we are directing it so we should not fetch stream.+404
public void sendError(int code, String msg)
Cookies
+ Cookies are textual information stored by server on client machine.+ Maximum a client can have 20 cookies per site, 300 cookies in all and maximum
size per cookie is 4KB.Objective Of Cookie
Identification and CustomizationBenefits Of Cookies
+ Identifying a user during an e-commerce session.+ Remembering user name and password.+ Customizing sites+ Focusing Advertising
Some Problems with Cookies+ Security issues
To Delete all CookiesTools | Internet Options | Temporary internet files | Delete Cookies
Sending Cookies
1. Create a cookie objectCookie c = new Cookie(“Name”, “Value”);2. Define the maximum age.c.setMaxAge(60*60*24*7); //seconds (1 week)3. Placing the cookie object into the HTTP response header.response.addCookie(c);
NOTE: These characters can’t be used in cookie value:[ ] ( ) = “ / ? @ : ;
Reading Cookies from Client1. Call request.getCookies methodCookie cookies[] = request.getCookies();2. Loop down the array, calling getName on each one until you find the cookie of
interest.for(int i = 0; i<cookies.length; i++){
String s =cookies[i].getName();if(s.equals(“Names”)){
val = s.getValue();break;
}}
Types of Cookies1. Session Cookie2. Persistent Cookie+ If no maxage is defined the maxage is -1 and it is a session cookie.
Objective: To transfer data between pagesMethods of Session Tracking
1. Cookies2. URL Rewriting 3. Hidden form fields
Basics of Session Tracking1. Accessing the session object associated with the current request.2. Looking up the information associated with a session.3. Storing information in a session.4. Discarding session data.
1. Accessing the session object associated with the current requestTwo methods – fetch or create
HttpSession session = request.getSession(); //falseThis means fetch the session and don’t create a new session.HttpSession session = request.getSession(true);This means create a new session, data in the session will be lost.
HttpSession session = request.getSession(false);This means fetch the session and don’t create a new session.
2. Looking up the information associated with a sessionObject value = session.getAttribute(“Name”);
3. Storing information in a sessionsession.setAttribute(“Name”, “Value”);
Cookies v/s Session Tracking+ Objective of cookies is customization whereas session Tracking is used for
Transfering data from one page to another.+ Cookies can be persistent whereas session Tracking is always temporary.+ Cookies share the data in the form of text whereas session store the data in the
form of Object.+ There are some constraints with cookies (max 20), there are no such constraints
with session.
Servlet Collaboration
+ Joining more than 1 servlet to generate the output.+ Obsolete Technologies
+ SSi (Server side Include)+ Servlet Chaining+ Servlet Tunnelling
+ Techniques of collaboration + Forward (Chaining & Tunnelling)+ Include (SSi)
+ To work on collaboration servlet provides RequestDispatcher class+ This class comes from javax.servlet.http package.
Collaboration ---------------- Forward+ works as a substitute to chaining & tunnelling.1. Fetch the RequestDispatcher2. Forward the control.
Sharing of data in Web Scope1. Page (Default)2. Request (Between 2 pages)3. Session (Between multiple pages for a single client)4. Application (Between mulitple pages for a multiple client)
name varchar2(20), aname varchar2(20), pub varchar2(20), price number(8,2));
CREATE SEQUENCE books_seq START WITH 1;
+ Create all table and sequence+ Create a DSN by the name “emp”
Resource Bundle+ Based on unicode character System that java supports.
Steps to implement Resource Bundles
+ We create a text file by the extension .properties.+ This text file contains pairs of key and values.+ We obtain the reference of the property in the servlet.+ Instead of using values directly, we fetch the values from property file by giving
the key.ResourceBundle bundle = Resource.getBundle(“NameOfPropertyFile”, locale);
+ ResourceBundle class comes from java.util package.+ getBundle takes two arguments -- name and locale (region)+To fetch value from property file
String value = bundle.getString(“key”);Benefits + Centralised updates
+ Internationalization (i18n)+ Changing labels without compilation
ListenersApplication Scope
+ Servlets 2.3 provides listeners for working on application scope.These listeners are:
javax.servlet.ServletContectListenerprovides handlers for context creation and destroy
javax.servlet.ServletContextAttributeListenerprovides handlers for context attributes added, removed and
replaced. javax.servlet.ServletContextListener
public void contextIntialized(ServletContextEvent sce)public void contextDestroyed(ServletContextEvent sce)
NOTE: Since SimpleServlet and MyContextListener are two independent programs hence the listener has to be told when to be executed hence its details are provided in the Web.xml with few tags as followed.<listener>
<listener-class>MyContextListener</listener-class> </listener>Also the entry made by the listener is on the server side not on the client side in our case the System.out.println refers to the Server.log file located in C:\Sun\Appserver\Domains\Domain1\Logs
Filter Chaining+ write filter-name and filter-class for every process in both <filter>
and <filter-mapping>
JSP(Java Server Pages)
+ JSP like servlets is also used to generate dynamic web pages.+ These dynamic web pages includes security, user preferences (customization) &
database.
+ JSP is called as reverse engineering of servlets.Servlet HTML within JavaJSP Java within HTML
+ It is also called cooked up servlets.
Steps to create & execute a JSP program1. Open Notepad2. Type the program3. Save it: Extension should be .jsp.
Eg. First.jsp4. Copy the .jsp file to <webserver-root> | Webapps | root5. Open browser
http://localhost:8080/First.jspThe simplest JSP program is to make an HTML file & make its extension as jsp & execute it.NOTE: The web server should be running.
Need & Benefits of JSP Need
1. It is hard to write & maintain HTML.2. You cannot make use of standard HTML tools.3. The HTML is inaccessible to non-java developers
Benefits1. It is easier to write & maintain HTML.2. You can make use of standard HTML tools.3. You can divide up development team.
LifeCycle of JSPJSP operations in various Scenarios
Expressions+ It is used to display value of a variable/objects.
Syntax:<%= Expressions %>
These variables/objects can be:1. Pre-defined 2. User-defined
Pre-defined objectsrequest HttpServletRequestresponse HttpServletResponseout JSPWriter (Advanced version of PrintWriter)session HttpSessionapplication ServletContextconfig ServletConfigpage this (Current page)
Scriplets
+ It is used to write set of java statements within JSP page.Syntax
<%Java Statements
%>Declarations
+ It is used to declare member data or member functions within class that is created on conversion of JSP to servlet.Syntax
<%! Field declaration %/><%! Method declaration %/>
Expression:1. Expressions.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
The page directive lets you define one or more of the following attributes: import contentType pageEncoding session isELIgnored (JSP 2.0 only) buffer autoflush info errorPage isErrorPage isThreadSafe language extends
The IMPORT attribute+ By default the servlet import
+ The default buffer size is server specific, but it should be less than 8 Kb.+ Incase of buffereing data can be forceably flushed using response.flushBuffer()
The INFO Attribute+ The info attribute defines a string that can be retrieved from the servlet by means
of the getServletInfo method.<%@ page info = “some msg”%>
The ERRORPAGE & ISERRORPAGE Attribute+ The errorPage attribute specifies a JSP page that should process any exceptions
thrown but not caught in the current page.<%@ page errorPage = “RelativeURL”%>
+ The exception thrown will automatically be available to the designated error page by means of the “exception” variable.
+ The isErrorPage attribute indicates whether or not the current page can act as the error page for another JSP page.<%@page isErrorPage = “true”%><%@page isErrorPage = “false”%> <%--Default--%>
The EXTENDS Attribute+ The extends attribute designates the superclass of the servlet that will be
generated for the JSP page.<%@ page extends = “package.class”%>
The LANGUAGE Attribute+ The language attribute is intended to specify the scripting language being used.
<%@ page language = “java”%>+ Java is both the default & the only legal choice.
The ISTHREADSAFE Attribute+ The isThreadsafe attribute controls whether the servlet that results from the JSP
page will allow concurrent access (the default) or will gurantee that no servlet instance processes more than one request at a time (isThreadSafe = “false”)<%@ page isThreadSafe = “false”%><%@ page isThreadSafe = “true”%> <%--Default--%>
3. Calling external files in JSP
JSP:INCLUDE Action+ This helps you include the output of a page at request time.+ The following types of output can be included in a JSP page.
+ The content of an HTML document.+ The content of a plain text document.+ The output of the JSP page.+ The output of a servlet.
Attributes:+ page: specifies URL of the page to be included.+ flush: whether the main page should be flushed prior to inclusion, default: false.
The JSP:PARAM element+ At the sending end<jsp:include page = “relative-url”>
<jsp:params><jsp:param name = “bgcolor” value = “yellow” /><jsp:param name = “bgcolor” value = “yellow” />
</jsp:params></jsp:include>
+ <jsp:params>…</jsp:params> is used when more than one parameters are to be used.
Including files at Page Translation Time: The INCLUDE directive+ The include directive is used to include a file in the JSP document at the time the
document is translated into servlet (which is typically the first time it is accessed)Syntax:
<%@ include file = “relative-url”%>
4. Calling Applets wintin JSP
<jsp:plugin>…</jsp:plugin>Attributes of jsp:plugin
Type: applet/beanCode: specifies .class fileWidth: specifies width of applet.
Height: specifies height of applet.name: specifies name of applet.
+ To pass parameters to applet<jsp:param>
Name: specifies parameter nameValue: specifies parameter value
+ for multiple parameters<jsp:param> is written within
<jsp:params>…</jsp:params>+ Incase the browser does not support java <jsp:fallback> can be used to work as alternative.<jsp:plugin type = “Applet” code = “MyApplet.class” width = 300 height = 300>NOTE: All class files used by Applet should be stored within webapps/root directory
4. Using Java Beans Components within JSP+ Benefits of Beans+ Creating Beans+ Installing Bean classes into server+ Accessing Bean Properties+ Explicitly setting bean properties+ Automatically setting bean properties from request parameters
Using beans basic Syntax JSP:USEBEAN
+ It is used to create a bean object.Attributes are:
JSP:GETPROPERTY+ This element reads and outputs the value of a bean property.Attributes are:name: specifies bean object nameproperty: specifies property name
<jsp:getProperty name = “beanName” property = “PropertyName” /> JSP:SETPROPERTY
+ This element modifies a bean property, it calls setXxx().Attributes are:name: specifies bean object nameproperty: specifies property namevalue: specifies new value
<jsp:setProperty name = “beanName” property = “PropertyName” value = “propertyValue” />Installing Bean ClassesNOTE: All beans should be packaged.Webapps | root | web-inf | classes | package
5. MVC using RequestDispatcher
MVC Model: data (Bean)View: presentation/rendering (JSP)Controller: combines model with view (Servlet)
MVC applications can be classified in 2 categories:1. MVC Type 1 (Impure MVC)2. MVC Type 2 (Pure MVC)
MVC Type 2 ensures not even 1 scriplet/expression/declaration with JSP. JSP should be used only & only for output.MVC Type 2 can be implemented in multiple ways:
1. RequestDispatcher2. Struts3. Java Server Faces (JSF)
Objective: Implementing pure MVC using RequestDispatcherPre-requisties
1. <web server-root> | conf2. Open web.xml in notepad.3. F3 (find) | invoker & remove the comments4. Save the file & restart the server
6. EL (Expression Language)+ El is an important feature of JSP 2.0 not of 1.2.+ EL stands for Expression Language.+ EL is used for evaluating & outputting the values of java objects that are stored in
standard locations.+ The two important features of EL are
1. Evaluating2. Outputting
# Benefits of EL+ Concise access to stored objects .+ Shorthand notation for bean properties.+ Simple access to collection elements + Succint (short) access to request parameters, cookies, and other request data.+ A small but useful set of simple operators.+ Conditional output.+ Automatic type conversion.+ Empty values instead of error messages.
7. JSTL (Java Server Tag Libraries)+ Can be in the form of
1. pre-defined TAG/Standard TAG Library2. User-defined TAG/Custom TAG Library
1. Create your own TAG in the form of a file+ The name of the file will be the name of the TAG.+ Extension of this file should be .tag.+ This file can be stored in any of the directories within web-inf directory.+ This Directory (where .tag files are stored) is refered as tag library
2. Call this directory within your JSP page.<%@ taglib prefix = “tags” tagdir = “/web-inf/tags” %>Over here,
prefix: It is used to refer tags from tag librarytagdir: it specifies the directory name (location)
8. jdbc (Benefits of ConnectionPool)
+ Limiting/Sharing number of connections+ Speed+ Centralized update for all database operations
Data:static final int MAX_CONNECTIONS = 20;static Vector connections = null;
// creates pool of MAX_CONNECTIONS if connection is null.public void removeAllConnections()// executes loop (size of vector) and closes all connections and set vector to null.public Connection getConnection()// fetches a single connection from vector, if vector is not null and size if greater than 0public void putConnection(Connection)// adds a connection back to pool and notifies.public static ConnectionPool getInstance()// returns a common object of ConnectionPool if existing, else it creates and returns
//first personConnectionPool cp;cp = ConnectionPool.getInstance();cp.initialize();Connection con = cp.getConnection();
//Statement//executeQuery or executeUpdate
cp.putConection(con);//second person
ConnectionPool cp;cp = ConnectionPool.getInstance();cp.initialize();Connection con = cp.getConnection();
//Statement//executeQuery or executeUpdate
cp.putConection(con);
Assignments given:Design Forms:-
After the form is crafted, how the form will be appear, just design it on the paper. Ex In our project, a single form allows –
o Inserting data into tableo Updating data already existing in tableo Viewing of data available in tableo Deleting data from table
Design structure of forms with command buttons on it.
sql4="update Course set name='"+ name + "',ctype='"+ctype +"',duration='"+ duration +"',semester="+semester + " where id="+ Integer.parseInt(request.getParameter("hiddenid"));
sql5="delete from Course where id IN("+ request.getParameter("hidSelDel") +") ";System.out.println(sql5);stmt.executeUpdate(sql5);response.sendRedirect("../servlet/Course");
}catch(Exception e){
out.println("Sorry failed 2 delete values from the database" + e.getMessage());
Remaining servlets were similar with there respective details. In our Project, the designing of the form will appear like –
Lesson learned: I have learned during the training session the language ADVANCE JAVA and how to design the WEB PAGES and how to make the web sites in the web.