1. www.ignousolvedassignments.com
Course Code: BCS – 053
Course Title: Web Programming
Assignment Number: BCA(V) – 053Assign/14-15
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
2. www.ignousolvedassignments.com
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>
16. www.ignousolvedassignments.com
<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 –>
22. www.ignousolvedassignments.com
#footer {
border: 1px groove #aaaaaa;
/* clear: both; background: blue;
color: White; padding: 0; */
background-color: #FFFFFF;
width: 1024px;
margin-left: auto;
margin-right: auto;
box-shadow: 0px 0px 20px 3px #d3d3d3;
border-radius: 4px;
text-align: center;
/* vertical-align: middle; line-height: normal;
margin: 0; position: fixed; bottom: 0px; width: 100%; */
}
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
23. www.ignousolvedassignments.com
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: -
24. www.ignousolvedassignments.com
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:
<part number="1976">
<name>Windscreen Wiper</name>
<description>The Windscreen wiper
automatically removes rain
from your windscreen, if it
should happen to splash there.
It has a rubber <ref part="1977">blade</ref>
which can be ordered separately
if you need to replace it.
</description>
</part>
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.
27. www.ignousolvedassignments.com
</CATALOG>
DTD for Teacher Data XML file
<!DOCTYPE CATALOG [
<!ELEMENT CATALOG (TDADA*)
<!ELEMENT TDADA (NAME,Teacher_ID,Qualifications,
Joining_date,Contacts,)>
<!ELEMENT NAME (#PCDATA)>
<!ELEMENT Teacher_ID (#PCDATA)>
<!ELEMENT Qualifications (#PCDATA)>
<!ELEMENT Joining_date (#PCDATA)>
<!ELEMENT Contacts (#PCDATA)>
]>
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.
28. www.ignousolvedassignments.com
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
29. www.ignousolvedassignments.com
<!DOCTYPE html>
<html>
<body>
<p> WELLCOME..</p><br>
<span id="countdown" class="timer"></span>
<p id="demo"></p>
<script>
function myFunction() {
var str = "WELLCOME..";
var res = str.toLowerCase();
document.getElementById("demo").innerHTML = res;
}
var seconds = 10;
{
function secondPassed() {
var minutes = Math.round((seconds - 30)/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
30. www.ignousolvedassignments.com
remainingSeconds = "0" + remainingSeconds;
}
document.getElementById('countdown').innerHTML
= minutes + ":" + remainingSeconds;
if (seconds == 0) {
clearInterval(countdownTimer);
document.getElementById('countdown').innerHTML = myFunction();
} else {
seconds--;
}
}
}
var countdownTimer = setInterval('secondPassed()', 100);
</script>
</body>
</html>
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.
31. www.ignousolvedassignments.com
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:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC
"-//WAPFORUM//DTD WML 1.3//EN"
"http://www.wapforum.org/DTD/wml13.dtd">
<wml>
<card>
<p>
This is Image. <img src="welcome.wbmp" alt="Image"/>
<img src="friend.wbmp" alt="Image"/>
<img src="smile.wbmp" alt="Image"/><br/>
32. www.ignousolvedassignments.com
Enter Following Information:<br/>
Name : <input name="name" size="12"/><br/>
Roll no. : <input name="age" size="12" format="*N"/><br/>
Class : <input name="sex" size="12"/> <br/>
<select>
<optgroup title="India">
<option value="delhi">Delhi</option>
<option value="mumbai">Mumbai</option>
<option value="hyderabad">Hyderabad</option>
</optgroup>
</select>
<table columns="3" align="LCR">
<tr>
<td>Col 1</td>
<td>Col 2</td>
<td>Col 3</td>
</tr>
<tr>
<td>A</td>
34. www.ignousolvedassignments.com
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
35. www.ignousolvedassignments.com
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.
36. www.ignousolvedassignments.com
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:
GET /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
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:
POST /cgi-bin/process.cgi HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
37. www.ignousolvedassignments.com
Host: www.tutorialspoint.com
Content-Type: text/xml; charset=utf-8
Content-Length: 88
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://clearforest.com/">string</string>
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.
38. www.ignousolvedassignments.com
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
39. www.ignousolvedassignments.com
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:
<p>
Today's date: <%= (new java.util.Date()).toLocaleString()%>
</p>
Here is the content of main.jsp file:
<html>
<head>
<title>The include Action Example</title>
</head>
40. www.ignousolvedassignments.com
<body>
<center>
<h2>The include action Example</h2>
<jsp:include page="date.jsp" flush="true" />
</center>
</body>
</html>
Now let us keep all these files in root directory and try to access main.jsp. This would
display result something like this:
The include action Example
Today's date: 12-Sep-2010 14:54:22
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:
<jsp:useBean id="name" />
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:
<jsp:useBean id="myName" ... />
...
<jsp:setProperty name="myName" property="someProperty" .../>
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:
<jsp:useBean id="myName" ... >
41. www.ignousolvedassignments.com
...
<jsp:setProperty name="myName" property="someProperty" .../>
</jsp:useBean>
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:
<jsp:useBean id="myName" ... />
...
<jsp:getProperty name="myName" property="someProperty" .../>
Example:
Let us define a test bean which we will use in our example:
/* File: TestBean.java */
package action;
public class TestBean {
private String message = "No message specified";
public String getMessage() {
return(message);
}
public void setMessage(String message) {
this.message = message;
42. www.ignousolvedassignments.com
}
}
Compile above code to generated TestBean.class file and make sure that you copied
TestBean.class in C:apache-tomcat-7.0.2webappsWEB-INFclassesaction 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:
<html>
<head>
<title>Using JavaBeans in JSP</title>
</head>
<body>
<center>
<h2>Using JavaBeans in JSP</h2>
<jsp:useBean id="test" class="action.TestBean" />
<jsp:setProperty name="test" property="message"
value="Hello JSP..." />
<p>Got message....</p>
<jsp:getProperty name="test" property="message" />
</center>
</body>
</html>
Now try to access main.jsp, it would display following result:
Using JavaBeans in JSP
Got message....
Hello JSP...
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:
<jsp:forward page="Relative URL" />
Example:
43. www.ignousolvedassignments.com
Let us reuse following two files (a) date.jps and (b) main.jsp as follows:
Following is the content of date.jsp file:
<p> Today's date: <%= (new java.util.Date()).toLocaleString()%> </p>
Here is the content of main.jsp file:
<html>
<head>
<title>The include Action Example</title>
</head>
<body>
<center>
<h2>The include action Example</h2>
<jsp:forward page="date.jsp" />
</center>
</body>
</html>
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.
Today's date: 12-Sep-2010 14:54:22
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:
44. www.ignousolvedassignments.com
<jsp:plugin type="applet" codebase="dirname" code="MyApplet.class"
width="60" height="80">
<jsp:param name="fontcolor" value="red" />
<jsp:param name="background" value="black" />
<jsp:fallback>
Unable to initialize Java Plugin
</jsp:fallback>
</jsp:plugin>
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:
<@page language="java" contentType="text/html"%>
<html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:jsp="http://java.sun.com/JSP/Page">
<head>
<title>Generate XML Element</title>
</head>
<body>
<jsp:element name="xmlElement">
<jsp:attribute name="xmlElementAttr">
Value for the attribute
</jsp:attribute>
<jsp:body>
Body for XML element
</jsp:body>
</jsp:element>
</body>
</html>
This would produce following HTML code at run time:
45. www.ignousolvedassignments.com
<html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:jsp="http://java.sun.com/JSP/Page">
<head><title>Generate XML Element</title></head>
<body>
<xmlElement xmlElementAttr="Value for the attribute">
Body for XML element
</xmlElement>
</body>
</html>
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:
<jsp:text>Template data</jsp:text>
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.
<jsp:text><![CDATA[<br>]]></jsp:text>
If you need to include a DOCTYPE declaration, for instance for XHTML, you must also
use the <jsp:text> element as follows:
<jsp:text><![CDATA[<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">]]>
</jsp:text>
<head><title>jsp:text action</title></head>
<body>
46. www.ignousolvedassignments.com
<books><book><jsp:text>
Welcome to JSP Programming
</jsp:text></book></books>
</body>
</html>
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 set of data is kept for each visitor to
the site.
Here is a set of pages that put a user’s name in the session, and display it elsewhere.
First we have a form, let us call it GetName.html
<HTML>
<BODY>
<FORM METHOD=POST ACTION="SaveName.jsp">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20>
<P><INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
The target of the form is “SaveName.jsp”, which saves the user’s name in the
session. Note the variable “session“. This is another variable that is normally made
available in JSPs, just like out and request variables. (In the @page directive, you can
indicate that you do not need sessions, in which case the “session” variable will not be
made available.)
47. www.ignousolvedassignments.com
<% String name = request.getParameter( "username" );
session.setAttribute( "theName", name ); %>
<HTML>
<BODY>
<A HREF="NextPage.jsp">Continue</A>
</BODY>
</HTML>
The SaveName.jsp saves the user’s name in the session, and puts a link to another
page, NextPage.jsp.
NextPage.jsp shows how to retrieve the saved name.
<HTML>
<BODY>
Hello, <%= session.getAttribute( "theName" ) %>
</BODY>
</HTML>
If you bring up two different browsers (not different windows of the same browser), or run
two browsers from two different machines, you can put one name in one browser and
another name in another browser, and both names will be kept track of.
The session is kept around until a timeout period. Then it is assumed the user is no
longer visiting the site, and the session is discarded.
48. www.ignousolvedassignments.com
What Is URL Rewriting?
If you were writing a letter to your bank, you would probably open your word processor
and create a file named something like lettertobank.doc. The file might sit in
your Documents directory, with a full path
likeC:WindowsusersjulieDocumentslettertobank.doc. One file path = one document.
Similarly, if you were creating a banking website, you might create a page
named page1.html, upload it, and then point your browser
tohttp://www.mybanksite.com/page1.html. One URL = one resource. In this case, the
resource is a physical Web page, but it could be a page or product drawn from a CMS.
URL rewriting changes all that. It allows you to completely separate the URL from the
resource. With URL rewriting, you could have
http://www.mybanksite.com/aboutus.html taking the user to …/page1.html or to
…/about-us/ or to …/about-this-website-and-me/ or to …/youll-never-find-out-about-me-
hahaha-Xy2834/. Or to all of these. It’s a bit like shortcuts or symbolic links on your hard
drive. One URL = one way to find a resource.
With URL rewriting, the URL and the resource that it leads to can be completely
independent of each other. In practice, they’re usually not wholly independent: the URL
usually contains some code or number or name that enables the CMS to look up the
resource. But in theory, this is what URL rewriting provides: a complete separation.
For More Ignou Solved Assignments Please Visit - www.ignousolvedassignments.com
Connect on Facebook :
http://www.facebook.com/pages/IgnouSolvedAssignmentscom/346544145433550
Subscribe and Get Solved Assignments Direct to your Inbox :
http://feedburner.google.com/fb/a/mailverify?uri=ignousolvedassignments_com