2014-09-22

Course Code: BCS – 053

Course Title: Web Programming

Assignment Number: BCA(V) – 053Assign/14-15

Maximum Marks: 100

Weightage: 25%

Last Date of Submission: 15th October, 2014 (For July 2014 Session)

15th April, 2015 (For January 2015 Session)

This assignment has two questions of 80 marks (each section of a question carries same Marks). Answer all the questions. Rest 20 marks are for viva voce. You may use Illustrations and diagrams to enhance explanations. Please go through the guidelines Regarding assignments given in the Program Guide for the format of presentation.Please give precise answers. The word limit for each part is 300 words.

Question 1:
A) How are Web 2.0 technologies different than that of Web 1.0? Explain the use of Mashups in web. Also explain any four new tags of HTML5.

Solution:-
Difference between web 1.0 and web 2.0

The main difference between web 1.0 and web 2.0 is the interactive behavior of online or web communication. The web 1.0 platform is much plain and simple just for displaying or sharing the information over the internet or web platform. It is a one way communication metaphor where the ownership is more concerned rather taking the community based approach for sharing and creating information. Web 1.0 can be compared more likely to be a library where people can just view the information but cannot enhance the information by adding. The user experience for web 1.0 technology is much poor where some image and text are the primary things of any website. In the period of web 1.0 the primary communication channel for any web content was the email only where web 2.0 just changed the whole idea of interactivity. On the other hand web 2.0 is the form of data reading writing and execution over the web platform. User can add content to web site like reviewing any product on amazon’s product page. Communication for any web content is much easier like people can comment or express their feelings about any web content just under the content which is much more visible in the blogging or social networking platforms. User experience for web 2.0 is incredible. People can put anything they want into web sites they are not bound to some sort of images and texts. People can even put videos, interactive sessions like live video stream, audio stream. The whole thing about web 2.0 is rich user experience and services being offered through web platform and the two way communication between the user and the web contents. Web 1.0 was all about the browser but web 2.0 is not all about the browser there are something like web API which can deliver the whole web experience inside the desktop, mobile or any device application.

Conclusion:

From the very beginning of web technology, it has got many versions but primarily web 1.0 and web 2.0 are being focused based on some factors and criteria. Mainly web 2.0 is all about rich internet experience while web 1.0 is limited to information sharing.

Use of Mashup:

A mashup, in web development, is a web page, or web application, that uses content from more than one source to create a single new service displayed in a single graphical interface. For example, you could combine the addresses and photographs of your library branches with a Google map to create a map mashup. The term implies easy, fast integration, frequently using open application programming interfaces (open API) and data sources to produce enriched results that were not necessarily the original reason for producing the raw source data. The term mashup originally comes from British – West Indies slang meaning to be intoxicated, or as a description for something or someone not functioning as intended. In recent English parlance it can refer to music, where people seamlessly combine audio from one song with the vocal track from another—thereby mashing them together to create something new.

The main characteristics of a mashup are combination, visualization, and aggregation. It is important to make existing data more useful, for personal and professional use. To be able to permanently access the data of other services, mashups are generally client applications or hosted online.

New HTML5 Tags:

1. <article> = Specifies an article

2. <hgroup> = Specifies a header for a section or page.
NOTE: - This element has been dropped from W3C HTML5 spec but it is still included in WHATWG Living Standard.
3. <template> = Container for client-side content instantiated during runtime using JavaScript
4. <wbr> = Specifies a line break opportunity for very long words and strings of text with no spaces.

B) Create a simple form that may be used for enrolling into IGNOU programs. The

Form should have relevant drop down lists and other details. You must use CSS. Explain the advantages of using CSS.

Solution:-

Simple form for enrollment into IGNOU

HTML

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head>

<link href=”style.css” type=”text/css” rel=”stylesheet” />

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

<title>Application Form</title>

</head>

<body bgcolor=”#0099CC”>

<style>

table, td, th {

border: 1px;

}

</style>

<div id=”page”>

<div id=”headerimg”><img src=”header2.png” /> </div>

</div>

<form id=”fom”>

<table>

<tr>

<td><b> 1. Programme Code: <input type=”text” name=”firstname” ></td>

<td><b> 2. Enrollment No.(Only for office use): <input type=”text” name=”lastname”></td>

</tr>

<tr>

<td><b> 3. Regional Center Code : <input type=”text” name=”regionalcentercode”></td>

<td><b> 4. Study Center Code : <input type=”text” name=”studycentercode”></td>

<td><b> 5. State Code : <input type=”text” name=”statecode” size=”10″></td>

</tr>

<tr>

<td><b> 6. Medium Code  :</b>

<input type=”radio” name=”dob” size=”8″>English

<input type=”radio” name=”dob” size=”8″>Hindi<br />

Others(If other please specify) : <br /><input type=”text” name=”c3other” size=”20″>

</td>

<td><b>7a.  Are you already registered with IGNOU : </b>

<input type=”radio” name=”dob” size=”8″>Yes

<input type=”radio” name=”dob” size=”8″>No<br />

If yes write the Enrol. No. & Program Code in the boxes below<br/>

Enrollment No. :<input type=”text” name=”enrlno.” size=”10″>

Programme Code :<input type=”text” name=”progcode” size=”10″><br />

<td> <b> 8. Date of Birth :</b><input type=”date” name=”dob” size=”10″><br />

<b> 9.    Nationality  : </b><input type=”radio” name=”dob” size=”8″>Indian<br/>

Others<br />(If other please specify) :<input type=”text” name=”dob” size=”8″>

</td>

</tr>

<tr>

<td><b> 10.  Sex :</b><input type=”radio” name=”dob” size=”8″>Male

<input type=”radio” name=”dob” size=”8″>Female</td>

<td><b> 11. Category  :</b><input type=”radio” name=”dob” size=”8″>GEN

<input type=”radio” name=”dob” size=”8″>ST

<input type=”radio” name=”dob” size=”8″>CS

<input type=”radio” name=”dob” size=”8″>OBC<br />

(In case of OBC student, Please also indicate either)<br />

(i) Cramy Layer<input type=”radio” name=”dob” size=”8″ />

(ii) Non Cramy Layer<input type=”radio” name=”dob” size=”8″ /></td>

<td><b> 12.  Territory Code :</b><br />

<input type=”radio” name=”dob” size=”8″ />Urban

<input type=”radio” name=”dob” size=”8″ />Rural

<input type=”radio” name=”dob” size=”8″ />Tribal

</td>

</tr>

<tr>

<td><b> 13.  Marital Status :</b><br /><input type=”radio” name=”dob”/>Married<input type=”radio” name=”dob”/>Unmarried</td>

<td><b> 14.  Religion:</b>

<select>

<option value=”volvo”>Hindu</option>

<option value=”saab”>Muslim</option>

<option value=”mercedes”>Christian</option>

<option value=”audi”>Sihk</option>

<option value=”volvo”>Parsi</option>

<option value=”saab”>Jain</option>

<option value=”mercedes”>Buddhist</option>

<option value=”audi”>Jews</option>

<option value=”saab”>Others</option>

</select>

</td>

<td><b> 15.  Whether Minority :</b><br /> <input type=”radio” name=”dob”/>Yes

<input type=”radio” name=”dob”/>No

</td>

</tr>

<tr>

<td><b>16.  Social Status :</b><br />

<input type=”radio” name=”dob”/>Ex-serviceman

<input type=”radio” name=”dob”/>War widow<br />

<input type=”radio” name=”dob”/>Not applicable

</td>

<td><b>17.  Whether Kashmiri Migrant:</b> Yes<input type=”radio” name=”dob”/>No<input type=”radio” name=”dob”/></td>

<td></td>

</tr>

<tr>

<td><b>18.  Name of the Candidate</b><br />

First Name :<input type=”text” name=”fname” size=”15″ /><br />

Middle Name :<input type=”text” name=”mname” size=”15″ /><br />

Surename :<input type=”text” name=”sname” size=”15″ /><br />

</td>

<td><b> 19.  Father’s/Husband’s Name/Mother’s Name (Strick out whichever is not applicable)</b><br />

First Name :<input type=”text” name=”fname” size=”15″ /><br />

Middle Name :<input type=”text” name=”mname” size=”15″ /><br />

Surename :<input type=”text” name=”sname” size=”15″ /><br />

</td>

</table>

<b> 20. Course Codes: M.Sc.(DFSM)/MTM/MLIS/MA(Edu)/MCA, MAPY, BLIS/ BA/ BCom/B.Sc./BSW/BTS/PGDDM/PGDMRR/CTE/PGDRD/PGDBP/PGDGPS/ GPDEMA/CAFE/ DCE & BPP (Students who are simultanously opting BPP             along with DMT, DDT, DPVCPO, DVAPFV, DFPT and DWM)</b>

<table>

<tr>

<td><b>(a) M.Sc. (DFSM) : </b><input type=”radio” name=”dob”/>CFN

<input type=”radio” name=”dob”/>CNCC</td>

</tr>

<tr>

<td><b>(b) MTM :</b> <input type=”radio” name=”dob”/>Category 1

<input type=”radio” name=”dob”/>Category 2</td>

</tr>

<tr>

<td><b>(c) MLIS/MAPY (Optional Courses) :</b><input type=”text” name=”dob” size=”20″/><input type=”text” name=”dob” size=”20″/><input type=”text” name=”dob” size=”20″/><input type=”text” name=”dob” size=”20″/></td>

</tr>

<tr>

<td><b> (d)BA/B.Sc./B.Com/BSW/BTS(Foundation Courses) :</b><input type=”text” name=”dob” size=”15″/><input type=”text” name=”dob” size=”15″/><input type=”text” name=”dob” size=”15″/><input type=”text” name=”dob” size=”15″/>

</td>

</tr>

<tr>

<td> <b>(e)  BA/B.Sc./B.Com (Elective Courses)

:</b><input type=”text” name=”dob” size=”20″/><input type=”text” name=”dob” size=”20″/><input type=”text” name=”dob” size=”20″/><input type=”text” name=”dob” size=”20″/><input type=”text” name=”dob” size=”15″/><input type=”text” name=”dob” size=”15″/><input type=”text” name=”dob” size=”15″/>

</td>

</tr>

<tr>

<td><b>(f)   MA (Edu)<br />

Specialised Area : </b>

<input type=”checkbox” name=”hedu” />Higher Education

<input type=”checkbox” name=”hedu” />Educational Technology

<input type=”checkbox” name=”hedu” />Distance Education

<input type=”checkbox” name=”hedu” />Educational Management

</td>

</tr>

<tr>

<td> <b>(g) CTE/DTS/PGDRD PGDDM/PGDMRR(Optional Courses) :</b><input type=”text” name=”dob” size=”15″/><input type=”text” name=”dob” size=”15″/><input type=”text” name=”dob” size=”15″/><input type=”text” name=”dob” size=”15″/>

</td>

</tr>

<tr>

<td> <b>(h)  CAFE/PGDBP(Optional Courses) :</b><input type=”text” name=”dob” size=”25″/><input type=”text” name=”dob” size=”25″/>

</td>

</tr>

<tr>

<td> <b>(i)   DCE/PGDGPS/ PGDEMA/DUL(Optional Courses) :</b><input type=”text” name=”dob” size=”25″/><input type=”text” name=”dob” size=”20″/><input type=”text” name=”dob” size=”25″/>

</td>

</tr>

<tr>

<td> <b>(j)   BPP(Optional Courses) :</b><input type=”text” name=”dob” size=”25″/><input type=”text” name=”dob” size=”25″/>

</td>

</tr>

<tr>

<td> <b>(k)  MCA : </b><input type=”checkbox” name=”dob” size=”10″/>CS-60 A1</td>

</tr>

<tr>

<td> <b>21(a)  Whether a person with disability:</b>

<input id=”showme” type=”radio” name=”dob” size=”10″/>Yes

<input id=”hideme” type=”radio” name=”dob” size=”10″/>No<br />

<p> <b>21(b)  If Person with disability (nature of disability):</b>

<input type=”checkbox” name=”dob” size=”10″/>Speech and Hearing Impairment

<input type=”checkbox” name=”dob” size=”10″/>Low Vision

<input type=”checkbox” name=”dob” size=”10″/>Locomotor Impairment

<input type=”checkbox” name=”dob” size=”10″/>Visual impairment

<input type=”text” name=”dob” size=”10″/>Any other Please specify </p>

</td>

</tr>

<tr>

<td>

<b>22.  Employment Status:</b>

<input type=”radio” name=”dob” size=”10″/>Unemployed

<input type=”radio” name=”dob” size=”10″/>Employed

<input type=”radio” name=”dob” size=”10″/>IGNOU Employee

<input type=”radio” name=”dob” size=”10″/>KVS Employee

</td>

</tr>

<tr>

<td> <b>23.  Details of Scholarship being received if any:<br />

(a) Annual Scholarship Amount: <input type=”text” name=”annual” size=”8″ />

(b) Family income (yearly): <input type=”text” name=”annual” size=”8″ /><br />

(c) Deptt. Offering Scholarship: </b><input type=”radio” name=”deptt.” />Govt. Diptt. <input type=”radio” name=”deptt.” />Others<br />

<b>(d) Below poverty line </b>

<input type=”radio” name=”deptt.” />Yes

<input type=”radio” name=”deptt.” />No<br />

<b>(e)    In case of jail inmates</b>

<input type=”radio” name=”deptt.” />Yes

<input type=”radio” name=”deptt.” />No

</td>

</tr>

<tr>

<td>

<b> 24.  Relevant Qualifications: (Which makes you eligible for the programme)<br /> </b>

(a) Qualification(Code)<input type=”text” name=”qualifictioncode” size=”5″>

(b) Main Subjects<input type=”text” name=”qualifictioncode” size=”5″>

(c) Year of passing

<select id=”year”></select>

(d) Division

<select>

<option value=”first”>1st</option>

<option value=”second”>2nd</option>

<option value=”third”>3rd</option>

<option value=”fourth”>4th</option>

<option value=”pass”>PASS</option>

</select><br />

(e) % of marks<input type=”text” name=”percent” size=”8″>

(f) Board Code<input type=”text” name=”percentd” size=”8″>

</td>

</tr>

<tr>

<td>

<b> 25.  Details of Fees:<br /> </b>

<input type=”radio” name=”cashhchallanofbank” />Cash Challan of Bank

<input type=”radio” name=”cashhchallanofbank” />Bank Draft

</td>

</tr>

<tr>

<td><b>26.  Amount(Add Rs. 200/- in Case of Late fee)<input type=”text” name=”amount” size=”10″ />

DD/Challan No. <input type=”text” name=”amount” size=”15″ />

DD/Challan Date <input type=”date” name=”DD/date” /> <br />

Bank Name : <input type=”text” name=”amount” size=”125″ />

</b>

</td>

</tr>

<tr>

<td> <b>27.  Address for Correspondence (Do not give Post Box No. Leave a blank between each unit of address like House No., Street Name, P.O., etc.)<input type=”text” name=”amount” size=”125″ /><br /></b>

<b>State <select name=slist>

<!– india all states –>

<script>

var states = new Array(“Andaman and Nicobar Islands”, ”Andhra Pradesh”, ”Arunachal Pradesh”, ”Assam”, ”Bihar”, ”Chandigarh”, “Chhattisgarh”, ”Dadra and Nagar Haveli”, ”Daman and Diu”, ”Delhi”, ”Goa”, ”Gujarat”, ”Haryana”, ”Himachal Pradesh”, ”Jammu and Kashmir”, ”Jharkhand”, ”Karnataka”, ”Kerala”, ”Lakshadweep”, “Madhya Pradesh”, ”Maharashtra”, ”Manipur”, ”Meghalaya”, ”Mizoram”,  ”Nagaland”, ”Orissa”, ”Pondicherry”, ”Punjab”, ”Rajasthan”, ”Sikkim”, ”Tamil Nadu”, ”Tripura”, ”Uttaranchal”, ”Uttar Pradesh”, ”West Bengal”);

for(var hi=0; hi<states.length; hi++)

document.write(“<option value=\”"+states[hi]+”\”>”+states[hi]+”</option>”);

</script>

</select>

<b>City: <input type=”text” name=”amount” size=”15″ />

<b> District: <input type=”text” name=”amount” size=”15″ />

<b>  Pin Code: <input type=”text” name=”amount” size=”15″ />

</td>

</tr>

<tr>

<td>

<b>28.  Landline Telephone Number (if any) with STD Code: <input type=”text” name=”landlineno” size=”20″ />

29. Fax No. (if any) with STD Code: <input type=”text” name=”faxno” size=”20″ /><br />

30.  Mobile Number (if any): <input type=”text” name=”mobileno” size=”20″ />

31.  E-mail address/ID (if any): <input type=”text” name=”email” size=”50″ />

</td>

</tr>

<tr>

<td height=”11″ valign=”middle” bgcolor=”#FFFFFF” class=”text”> </td>

<td height=”11″ valign=”middle” bgcolor=”#FFFFFF”> </td>

<td height=”11″ colspan=”5″ valign=”top” nowrap=”" bgcolor=”#F3F3F3″  class=”helpText”> </td>

</tr>

<tr>

<td height=”11″ valign=”middle” bgcolor=”#FFFFFF” class=”text”> </td>

<td height=”11″ valign=”middle” bgcolor=”#FFFFFF”> </td>

<td height=”11″ colspan=”5″ valign=”top” nowrap=”" bgcolor=”#F3F3F3″  class=”helpText”> </td>

</tr>

<tr><td>

<div align=”center”><span><font color=”red”>

<input name=”Submit” type=”submit” class=”FormGOButton” id=”continue” value=”Save and Continue” onclick=”document.pressed=this.value”>

<font color=”red”>

<input name=”Submit” type=”submit” class=”FormGOButton” id=”exit” value=”Temporary Exit” onclick=”document.pressed=this.value” title=”Save and Register Later”>

</font> </font></span> </div>

</td>

</tr>

<tr>

<td height=”15″ colspan=”7″ valign=”middle” class=”text”  background=”heading.gif”> </td>

</tr>

</table>

</form>

<div id=”footer”>Powered by Nise Computers 2014</div>

Style CSS

Advantages of CSS:-

CSS stands for “Cascading Style Sheets“. A single CSS file can contain positioning, layout, font, colors and style information for an entire web site. The file can be referenced by each html file on the site.

Following are Advantages of CSS:-

Making changes to the layout

CSS makes it very easy to change the style of a document. Let’s say we wanted to move the picture in the title of this page to the right by 10 pixels. This would be a nightmare in a table based design. We would have to open every page and alter the table width manually.Fortunately we have used CSS, and all we have to do is open our CSS file which stores the layout of the site, and change the number relating to the position of the image. That will change his position throughout the whole site. The look and layout of a site can be changed beyond recognition just by altering the CSS file. This makes CSS indispensable for large web sites.

File Size

Probably the mostly useful feature of CSS is that all of the style and layout is removed from the html, so the html page size is very much smaller. The CSS file is downloaded just once by the visitor’s browser and re-used for different pages on a web site. This reduces the bandwidth requirements for your server and also ensures a faster download for your visitors.

Search Engines

A search engine robot will normally consider the content in the start of your html code is more important than the text towards the end of the code. For a table based page the contents of the navigation bar will normally show up as the page description in search engine results. With a CSS page the navigation can be moved to the bottom of the source code, so the search engine displays your content instead of your navigation.

Accessibility

Separating style from content makes life very easy for visitors who prefer to view only the content of a web page, or to modify the content. These could be blind or partially sighted people who might use a screen reader to interpret a page.

Consistency

Layout and position of navigation can be completely consistent across a site. This was previously possible only using frames.

C) What are the uses of XML technology? Create at least five instances of your teachers Data using XML. The list may contain name of teacher, her/his qualifications (Starting from graduation degree) and date of joining the school. Each teacher should be assigned an ID as an attribute, and a phone number which should have residence Or mobile as attribute. Also create the DTD for the XML document you have Created.

Solution: -

Uses of XML Technology:

The Extensible Markup Language (XML) is a simple text-based format for representing structured information: documents, data, configuration, books, transactions, invoices, and much more. It was derived from an older standard format called SGML (ISO 8879), in order to be more suitable for Web use. XML is one of the most widely-used formats for sharing structured information today: between programs, between people, between computers and people, both locally and across networks.

A short example:

If you are already familiar with HTML, you can see that XML is very similar. However, the syntax rules of XML are strict: XML tools will not process files that contain errors, but instead will give you error messages so that you fix them. This means that almost all XML documents can be processed reliably by computer software.

Teacher Data using XML:

DTD for Teacher Data XML file

This DTD defines that wherever the CATALOG element is used in the XML code, it should consist of one or more TDATA elements. Likewise, whenever the TDATA element is used, it should include the NAME, Teacher_ID, Qualifications, Joining_date, and Contacts elements.

D) Explain the commands of JavaScript that can be used to modify a HTML Document. Explain how events are handled using JavaScript. Write a program using JavaScript that changes the text WELCOME to lower case and then again to upper case. This cycle of conversion is performed after every 10 seconds.

Solution: -

JavaScript Event Handlers:
Actions by page users trigger event handler commands in the JavaScript. The program will then perform whatever commands are assigned to the event. Common event handlers are listed in the following table.

Event Handler

Action

onAbort

The user stopped loading a page

onBlur

The user moves from an object

onChange

The user changed an object

onClick

The user mouse-clicked an object

onError

An error occurred in the script

onFocus

The user activates an object

onLoad

The object has been loaded

onMouseover

The cursor has moved over the object

onMouseout

The cursor has moved off the object

onSelect

The user selected the object

onSubmit

The user submitted a form

onUnload

The user leaves the window

JavaScript LowerCase to Uppercase Program

The above program will first show the WELCOME text in Uppercase, then the 10 seconds countdown timer will start when 10 seconds finished the welcome text will change in Lowercase as “welcome” this is simple program you can try it by yourself.

E) List 4 tags that are used in WML. Create a simple WML program which should include a text paragraph, a table, an image and any two WML input elements.

Solution: -

List of tags that are used in WML

1. <wml:cancel/>

Renders a WML <postfield> element with a value of cancel. This tag is only valid when nested inside a form tag body. Posting this element causes the Action servlet to bypass calling the associated form bean validate() method.

2. <wml:card/>

This tag renders a card element. This element is not rendered when the tag is executed in WebSphere Portal. This allows writing JSPs that can be used in both the servlet and portlet   environments.

3. <wml:errors/>

Retrieves the set of error messages from the request object with the default                     key of Action.ERROR_KEY or the value specified by attribute name. If                            ActionErrors are found then the errors are displayed. This tag also requires                    the following two message keys in the application scope MessageResources.

errors.header – header that is displayed before the error messages list.

errors.footer – header that is displayed after the error messages list.

4. <wml:form/>

This tag does not render any markup, but it is used to scope beans and                           transactions. The tags used with the body of the form tag can use the                             form bean to populate the input fields.

Simple WML Program Example:

OUTPUT:-



The above program is built in Adobe Dreamweaver under WML page type.

Question 2:

A) Differentiate between 2-tier and 3-tier architectures. Explain any two HTTP methods with the help of an example each. Also explain the concept of web container with the help of an example.

Solution: -

Difference between 2-tier & 3- tier architecture:

Design Consideration

Description

Security

The topic of security is a tough one because arguments can be made either way for 2 vs. 3-tiers. In my experience, the 3-tier architecture has the potential for better security, but if great care isn’t taken during development it frequently ends up less secure. With a 2-tier approach, the application authenticates to and communicates directly to the database, which simplifies the attack surface area and is one less boundary to be concerned about. Depending on the details of the application server, there could be, for example, many complex REST APIs that could each have their own attack weaknesses. This one topic could be covered in a book, so I’m simply calling this one in favor of 2-tier even though direct access to the data sounds unsafe.

Cost

2-tier applications are generally easier to build and because of their lower complexity are less expensive all around.

Ease of maintenance

Although part of cost consideration, ease of maintenance is worth analyzing separately. Keeping the client up to date in a 2-tier architecture can be a trouble point that is not an issue with most 3-tier designs. However, in a 3-tiered architecture, keeping the application tier up to date is much more difficult in the long run. For example, sometimes security patches required to keep the application tier secure are not compatible with your code and require you to make code changes, which can be extensive.

Performance

Performance in a 2-tiered architecture is more sensitive to the hardware the client is running on, as well as the speed of the network connection.

Deployment

In a 3-tiered architecture, typically users point their browsers to the application server to start using the application. However, the setup of that environment can be considerably more complex than setting up a database for the users to connect to and making the installer for the client available.



HTTP Methods:

1) GET Method

A GET request retrieves data from a web server by specifying parameters in the URL portion of the request. This is the main method used for document retrieval. Following is a simple example which makes use of GET method to fetch hello.htm:

2) POST Method

The POST method is used when you want to send some data to the server, for example file update, form data etc. Following is a simple example which makes use of POST method to send a form data to the server which will be processed by a process.cgi and finally a response will be returned:

Web container:

A Web container is a runtime environment for Web applications. It processes servlets, JSP files, and other types of server-side components. Each application server runtime has one logical Web container, which can be modified but not created or removed.

Each Web container provides:

Web container transport chains

The Web container inbound transport chain handles requests. It consists of a TCP inbound channel that provides the connection to the network, an HTTP inbound channel that serves HTTP 1.0 and 1.1 requests, and a Web container channel that sends requests for servlets and JSPs to the Web container for processing.

Servlet processing

when it handles servlets, a Web container creates a request object and a response object and then invokes the servlet service method. The Web container also invokes the servlet destroy method when appropriate and unloads the servlet, after which the JVM™ performs garbage collection.

HTML and other static content processing

Requests for HTML and other static content that are directed to the Web container are served by the Web container inbound chain. However, in most cases, using an external Web server and a Web server plug-in as a Web container interface is more appropriate for a production environment.

Session management

The Web container provides support for the javax.servlet.http.HttpSession interface as described in the API specification for the servlet.

Figure 1 illustrates the Web container and its place in the application server.



B) Explain the JSP life cycle with the help of a diagram. Explain the action elements of JSP with the help of an example each.

Solution: -

The key to understanding the low-level functionality of JSP is to understand the simple life cycle they follow. 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.

The following are the paths followed by a JSP

Compilation

Initialization

Execution

Cleanup

The four major phases of JSP life cycle are very similar to Servlet Life Cycle and they are as follows:

JSP Action elements:-

The <jsp:include> Action: This action lets you insert files into the page being generated. The syntax looks like this:

Example:
Let us define following two files (a)date.jps and (b) main.jsp as follows:

Following is the content of date.jsp file:

Here is the content of main.jsp file:

Now let us keep all these files in root directory and try to access main.jsp. This would display result something like this:

The <jsp:useBean> Action:

The useBean action is quite versatile. It first searches for an existing object utilizing the id and scope variables. If an object is not found, it then tries to create the specified object.

The simplest way to load a bean is as follows:

The <jsp:setProperty> Action:

The setProperty action sets the properties of a Bean. The Bean must have been previously defined before this action. There are two basic ways to use the setProperty action:

You can use jsp:setProperty after, but outside of, a jsp:useBean element, as below:

In this case, the jsp:setProperty is executed regardless of whether a new bean was instantiated or an existing bean was found.

A second context in which jsp:setProperty can appear is inside the body of a jsp:useBean element, as below:

The <jsp:getProperty> Action:

The getProperty action is used to retrieve the value of a given property and converts it to a string, and finally inserts it into the output.

The getProperty action has only two attributes, both of which are required ans simple syntax is as follows:

Example:
Let us define a test bean which we will use in our example:

Compile above code to generated TestBean.class file and make sure that you copied TestBean.class in C:\apache-tomcat-7.0.2\webapps\WEB-INF\classes\action folder and CLASSPATH variable should also be set to this folder:

Now use the following code in main.jsp file which loads the bean and sets/gets a simple String parameter:

Now try to access main.jsp, it would display following result:

The <jsp:forward> Action:

The forward action terminates the action of the current page and forwards the request to another resource such as a static page, another JSP page, or a Java Servlet.

The simple syntax of this action is as follows:

Example:

Let us reuse following two files (a) date.jps and (b) main.jsp as follows:

Following is the content of date.jsp file:

Here is the content of main.jsp file:

Now let us keep all these files in root directory and try to access main.jsp. This would display result something like as below. Here it discarded content from main page and displayed content from forwarded page only.

The <jsp:plugin> Action:

The plugin action is used to insert Java components into a JSP page. It determines the type of browser and inserts the <object> or <embed> tags as needed.

If the needed plugin is not present, it downloads the plugin and then executes the Java component. The Java component can be either an Applet or a JavaBean.

The plugin action has several attributes that correspond to common HTML tags used to format Java components. The <param> element can also be used to send parameters to the Applet or Bean.

Following is the typical syntax of using plugin action:

The <jsp:element> Action,  The <jsp:attribute> Action,   The <jsp:body> Action
The <jsp:element>, lt;jsp:attribute> and <jsp:body> actions are used to define XML elements dynamically. The word dynamically is important, because it means that the XML elements can be generated at request time rather than statically at compile time.

Following is a simple example to define XML elements dynamically:

This would produce following HTML code at run time:

The <jsp:text> Action:

The <jsp:text> action can be used to write template text in JSP pages and documents. Following is the simple syntax for this action:

The body fo the template cannot contain other elements; it can only contain text and EL expressions ( Note:- EL expressions are explained in subsequent chapter). Note that in XML files, you cannot use expressions such as ${whatever > 0}, because the greater than signs are illegal. Instead, use the gt form, such as ${whatever gt 0} or an alternative is to embed the value in a CDATA section.

If you need to include a DOCTYPE declaration, for instance for XHTML, you must also use the <jsp:text> element as follows:

Try above example with and without <jsp:text> action.

C) What is the need of a session in a JSP based website? Explain the URL rewriting, and use of Hidden Objects in the context of session management with the help of examples. List any two methods of session objects and explain each one of them with the help of an example each.

Solution:-

JSP Sessions:-

On a typical web site, a visitor might visit several pages and perform several interactions. If you are programming the site, it is very helpful to be able to associate some data with each visitor.  For this purpose, “session“s can be used in JSP.

A session is an object associated with a visitor.  Data can be put in the session and retrieved from it, much like a Hashtable.  A different s

Show more