Web Technologies
Web Technologies
------------------------------------------------------------------------------------------------------------
AIM: Design the static web pages required for an online book store web site.
1) HOME PAGE
DESCRIPTION:
• Top frame : Logo and the college name and links to Home page, Login page, Registration
page,
• Left frame : At least four links for navigation, which will display the catalogue of
respective links.
For e.g.: When you click the link “CSE” the catalogue for CSE Books should be displayed
in the Right frame.
• Right frame: The pages to the links in the left frame must be loaded here. Initially this
page contains description of the web site.
PROGRAM:
Homepage
<head>
<frameset rows="20%,*">
<frame src="topframe.html"name="f1">
<frameset cols="20%,*">
<frame src="leftframe.html"name="f2">
</frameset>
</frameset>
</head>
OUTPUT:
<html>
<body>
<p>
</p>
<br>
<p>
<h2> nbsp;
Home
</a>
login
</a>
registration
</a>
nbsp;
Catalogue
</a>
Cart
</a>
</h2>
</p>
</body>
</html>
Leftframe:
<html>
<body>
</body>
</html>
Right frame:
<html>
<body bgcolor="pink">
<p>
<h3> <font face="monotype corsiva" color=blue> This is the online
book store developed by students of SVIST.It contains book catalogue of various branches like
cse,ece,eee,civil </font></h3>
</p>
</body>
</html>
OUTPUT:
2) LOGIN PAGE
DESCRIPTION:
PROGRAM:
<html>
<head>
</head>
<body background=”E:\1.jpg”>
<label>
</label>
<label>
<input type="reset">
</form>
</body>
</html>
OUTPUT:
DESCRIPTION:
The catalogue page should contain the details of all the books available in the web site
in a table.
PROGRAM:
<html>
<body>
<center>
<table border=1>
<tr>
</tr>
<tr>
</img>
</td>
<td>
<pre>
book:XML Bible
Author:winston
Publisher:Wiesley
</font>
</pre>
</td>
</td>
</tr>
<tr>
</img>
<td>
<pre>
book:Java 2
Author:Watson
Publisher:BPB publications
</font>
</pre>
</td>
</td>
</tr>
</table> </center>
</body>
</html>
OUTPUT:
Thus the home page, login page, catalogue page for the online book store are created
successfully
Week-2
------------------------------------------------------------------------------------------------------------
AIM: Design of the cart page and the registration page required for online book store.
4) CART PAGE
DESCRIPTION:
The cart page contains the details about the books which are added to the cart.
PROGRAM:
<html>
<body>
<center><br><br><br>
<img src=”E:\aa.jpg”>
<thead>
<tr>
<th>Book name</th>
<th>quantity</th>
<th>amount</th>
</tr>
</thead>
<tr>
<td>java 2</td>
<td>$45</td>
<td>2</td>
<td>$70</td>
</tr>
<tr>
<td> $20</td>
<td> 5</td>
<td> $40</td>
</tr>
</th>
</tr>
</table>
</center>
</html>
OUTPUT:
DESCRIPTION:
1)Name(Textfield)
2) Password (password field)
PROGRAM:
<html>
<body>
<center>
<form>
<label>name</label>
<label>password</label>
<label>phone no</label>
<label>Sex</label>
<select>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select>
<option>jan</option>
<option>feb</option>
<option>mar</option>
<option>apr</option>
<select>
<option>1980</option>
<option>1981</option>
<option>1982</option>
<option>1983</option>
</center>
</body>
</html>
OUTPUT:
Thus the registration and cart pages for online book store pages are created successfully
------------------------------------------------------------------------------------------------------------
AIM: Write JavaScript to validate the following fields of the above registration page.
1. Name (Name should contains alphabets and the length should not be less than 6
characters).
2. Password (Password should not be less than 6 characters length).
3. E-mail id (should not contain any invalid and must follow the standard pattern
[email protected])
One of the most common situations that come up is having an HTML form for
users to enter data. Normally, we might be interested in the visitor’s name, phone number
and email address, and so forth. However, even if we are very careful about putting some
regx=new RegExp(“fish|fow1”);
Functions:
test(string)- Tests a string for pattern matches. This method returns a Boolean that indicates
whether or not the specified pattern exists within the searched string. This is the most
commonly used method for validation. It updates some of the properties of the parent RegExp
object following a successful search.
exec(string)- Executes a search for a pattern within a string. If the pattern is not found, exec()
returns a null value. If it finds one or more matches it returns an array of the match results. It
also updates some of the properties of the parent RegExp object
PROGRAM:
Valid.js
function fun()
var pwdv=document.forms[0].pwd.value;
var emailv=document.forms[0].email.value;
var phv=document.forms[0].ph.value;
var ruser=userreg.exec(userv);
var remail=emailreg.exec(emailv);
var rph=phreg.exec(phv);
return true;
else
return false;
Register.html
<html>
<body>
<center>
<fieldset>
<legend>Registration</legend>
<pre>
</pre>
</form>
</body>
<script src="valid.js"></script>
</html>
RESULT:
Thus the home page, login page, catalogue page for the online book store are created
successfully
------------------------------------------------------------------------------------------------------------
AIM:
Design a web page using CSS (Cascading Style Sheets) which includes the following:
1) Use different font, styles: In the style definition you define how each selector should
work .Then, in the body of your pages, you refer to these selectors to activate the styles.
2) Set a background image for both the page and single elements on the page.
3) Control the repetition of the image with the background-repeat property
DESCRIPTION:
Syntax
The CSS syntax is made up of three parts: a selector, a property and a value:
selector {property: value}
The selector is normally the HTML element/tag you wish to define, the property is the
attribute you wish to change, and each property can take a value. The property and value
are separated by a colon, and surrounded by curly braces:
body {color: black}
External Style Sheet
An external style sheet is ideal when the style is applied to many pages. With an
external style sheet, you can change the look of an entire Web site by changing one file.
Each page must link to the style sheet using the <link> tag. The <link> tag goes inside
the head section:
<head>
href="mystyle.css" />
</head>
The browser will read the style definitions from the file mystyle.css, and format the document
according to it.
PROGRAM:
Cas.css:
a:link{color:black;}
a:visited{color:pink;}
a:active{color:red;}
a:hover{color:green;}
.right {
text-align:center;
text-decoration:underline;
font-weight:bold;
color:blue;
font-size:30; }
.image {
text-align:left;
font-family:"monotype corsiva";
font-weight:10;
.image1 {
background-attachment:fixed;
background-repeat:no-repeat;
width:150;
height:150; }
table { align:center;border:10;
border-style:ridge;
border-color:yellow;}
htm.html:
<html>
<head>
.xlink{ text-decoration:none;font-weight:bold;cursor:crosshair;}
.ylink{text-decoration:underline;font-weight:bold;cursor:help;}
</style>
</head>
<body class="image">
<p style="text-align:right;">
</p>
<p class="right">SVIST</p>
<div style="position:relative;font-size:90px;z-index:5;color:purple;">SVIST</div>
<div style="position:relative;font-size:90px;z-index:1;color:purple;">SVIST</div>
<tr>
<td> Fruits</td>
<td> Mango</td>
</tr>
</table>
</html>
OUTPUT:
RESULT: Thus different style of CSS and different type of the properties are applied.
DESCRIPTION:
PROGRAM:
XML document (bookstore.xml)
<bookstore>
<book>
<title>web programming</title>
<author>chrisbates</author>
<ISBN>123-456-789</ISBN>
<publisher>wiley</publisher>
<edition>3</edition>
<price>350</price>
</book>
<book>
<title>internet worldwideweb</title>
<author>ditel&ditel</author>
<ISBN>123-456-781</ISBN>
<edition>3</edition>
<price>450</price>
</book>
</bookstore>
Bookstore.xml
<bookstore>
<book>
<author>chrisbates</author>
<ISBN>123-456-789</ISBN>
<publisher>wiley</publisher>
<edition>3</edition>
<price>350</price>
</book>
<book>
<title>internet worldwideweb</title>
<author>ditel&ditel</author>
<ISBN>123-456-781</ISBN>
<publisher>person</publisher>
<edition>3</edition>
<price>450</price>
</book>
</bookstore>
<xs:element name="bookstore">
<xs:sequence>
<xs:complexType>
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Bookstore.xml
<book>
<title>web programming</title>
<author>chrisbates</author>
<ISBN>123-456-789</ISBN>
<publisher>wiley</publisher>
<edition>3</edition>
<price>350</price>
</book>
<book>
<title>internet worldwideweb</title>
<author>ditel&ditel</author>
<ISBN>123-456-781</ISBN>
<publisher>person</publisher>
<edition>3</edition>
<price>450</price>
</book>
</bookstore>
PROGRAM:
XML:
<?xml version="1.0"?>
<book>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
XSL:
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="red">
<th align="left">title</th>
<th align="left">author</th>
</tr>
<xsl:for-each select="bookstore/book">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
</xsl:when>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="author"/></td>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
OUTPUT:
RESULT: Thus the XML stylesheets are successfully used to display the content in a table format.
------------------------------------------------------------------------------------------------------------
VISUAL BEANS:
AIM: Create a simple visual bean with a area filled with a color.
The shape of the area depends on the property shape. If it is set to true then the
shape of the area is Square and it is Circle, if it is false.
The color of the area should be changed dynamically for every mouse click. The color
should also be changed if we change the color in the “property window “.
DESCRIPTION:
A Bean is a JavaBeans component. Beans are independent, reusable software modules.
Beans may be visible objects, like AWT components, or invisible objects, like queues and stacks.
A builder/integration tool manipulates Beans to create applets and applications.
Events
An event allows your Beans to communicate when something interesting happens.
There are three parts to this communication:
EventObject
The event source defines when and where an event will happen. Classes register
themselves as interested in the event, and they receive notification when the event happens. A
series of methods patterns represents the registration process:
Properties
Simple - As the name implies, simple properties represent the simplest of the four. To
create a property, define a pair of set/get routines. Whatever name used in the pair of
routines, becomes the property name
Indexed - An indexed property is for when a single property can hold an array of values.
The design pattern for these properties is:
public void setPropertyName (PropertyType[] list)
Bound – A bean that has the bound property generates an event when the property is
changed. The event is of type propertyChangeEvent and is sent to objects that
previously registered an interest in receiveing such notifications. In order for the
notification to happen, you need to maintain a watch list for
PropertyChangeEvents via the PropertyChangeSupport class. First, you
have to create a list of listeners to maintain:
private PropertyChangeSupport changes =
PropertyChangeListener p) {
changes.addPropertyChangeListener (p);
PropertyChangeListener p) {
changes.removePropertyChangeListener (p);
import java.awt.*;
import java.awt.event.*;
public Colors()
addMouseListener(new MouseAdapter(){
change(); }
});
rectangular=false;
setSize(100,100);
change();
return rectangular;
this.rectangular=flag;
repaint();
color=randomColor();
repaint();
int r=(int)(255*Math.random());
int g=(int)(255*Math.random());
int b=(int)(255*Math.random());
Dimension d=getSize();
int h=d.height;
int w=d.width;
g.setColor(color);
g.fillRect(0,0,w-1,h-1);
else
g.fillOval(0,0,w-1,h-1);
OUTPUT:
Program 2:
Convert.java
package sunw.demo.convert;
import java.awt.*;
import java.awt.event.*;
public convert()
setSize(100,1000);
return dollars;
this.dollars=value;
this.rupees=value;
return rupees;
dollarvalue= value();
repaint();
return rupees*dollars;
g.setColor(Color.red);
g.drawString(String.valueOf(dollarvalue),10,10);
Convert.mf
Name: sunw/demo/convert/convert.class
Program 3:
package sunw.demo.colors;
import java.awt.*;
import java.awt.event.*;
addMouseListener(new MouseAdapter() {
change();
});
setSize(100,100);
count++;
repaint();
Dimension d = getSize();
int h = d.height;
int w = d.width;
g.setColor(Color.red);
g.fillRect(0,0,100,100);
g.setColor(Color.blue);
g.drawString(String.valueOf(count),50,50);
Mouseclick.mft
Java-Bean: True
Output
Result
Thus the Mouse Clicks bean is created successfully
DESCRIPTION:
You must set the JAVA_HOME environment variable to tell Tomcat where to find
Java. Failing to properly set this variable prevents Tomcat from handling JSP pages. This
variable should list the base JDK installation directory, not the bin subdirectory.
On Windows XP, you could also go to the Start menu, select Control Panel, choose System, click
on the Advanced tab, press the Environment Variables button at the bottom, and enter the
JAVA_HOME variable and value directly as:
Name: JAVA_HOME
Value: C:\jdk
Name: JAVA_HOME
Value: install_dir/common/lib/servlet-api.jar
<DefaultContext reloadable="true"/>
Be sure to make a backup copy of server.xml before making the above change.
To enable the invoker servlet, uncomment the following servlet and servlet-
mapping elements in install_dir/conf/web.xml. Finally, remember to make a backup copy
of the original version of this file before you make the changes.
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
...
</servlet>
...
<servlet-mapping>
OUTPUT:
OUTPUT
Thus week-1 and week-2 pages are accessed using the TOMCAT web server successfully.
------------------------------------------------------------------------------------------------------------
Read the user id and passwords entered in the Login form (week1) and authenticate
with the values (user id and passwords) available in the cookies.
If he is a valid user (i.e., user-name and password match) you should welcome him by
name (user-name) else you should display “You are not an authenticated user “.
Use init-parameters to do this. Store the user-names and passwords in the webinf.xml and
access them in the servlet by using the getInitParameters() method.
home.html:
<html>
<head>
<title>Authentication</title>
</head>
<body>
<form action="ex1">
<label>Username </label>
<input type="text"size="20" name="user"><br><br>
password<input type="text" size="20" name="pwd"><br><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Example1.java
import javax.servlet.*;
import java.io.*;
public class Example1 extends GenericServlet
{
private String user1,pwd1,user2,pwd2,user3,pwd3,user4,pwd4,user5,pwd5;
public void init(ServletConfig sc)
{
user1=sc.getInitParameter("username1");
user2=sc.getInitParameter("username2");
pwd2=sc.getInitParameter("password2");
user3=sc.getInitParameter("username3");
pwd3=sc.getInitParameter("password3");
user4=sc.getInitParameter("username4");
pwd4=sc.getInitParameter("password4");
}
Public void service(ServletRequest req,ServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
user5=req.getParameter("user");
pwd5=req.getParameter("pwd");
if((user5.equals(user1)&&pwd5.equals(pwd1))||(user5.equals(user2)&&pwd5.equals(pwd2))||(user5
.equals(user3)&&pwd5.equals(pwd3))||(user5.equals(user4)&&pwd5.equals(pwd4)))
out.println("<p> welcome to"+user5.toUpperCase());
else
out.println("You are not authorized user");
}
}
web.xml:
<web-app>
<servlet>
<servlet-name>Example</servlet-name>
OUTPUT:
Create a table which should contain at least the following fields: name, password,
email-id, phone number (these should hold the data from the registration form).
Practice 'JDBC' connectivity.
Write a java program/servlet/JSP to connect to that database and extract data from the
tables and display them. Experiment with various SQL queries.
Insert the details of the users who register with the web site, whenever a new user clicks
the submit button in the registration page (week2).
DESCRIPTION:
PROGRAM:
Registration.html:
<html>
<head>
<title>Registration page</title>
</head>
<body bgcolor="#00FFFf">
<form METHOD="POST" ACTION="register">
<CENTER>
<table>
<center>
<tr> <td> Username </td>
<td><input type="text" name="usr"> </td> </tr>
<tr><td> Password </td>
<td><input type="password" name="pwd"> </td> </tr>
<tr><td>Age</td>
<td><input type="text" name="age"> </td> </tr>
<tr> <td>Address</td>
<td> <input type="text" name="add"> </td> </tr>
<tr> <td>email</td>
Login.html
<html>
<head>
<title>Registration page</title>
</head>
<body bgcolor=pink> <center> <table>
<form METHOD="POST" ACTION="authent">
<tr> <td> Username </td>
<td><input type="text" name="usr"></td> </tr>
<tr> <td> Password </td>
<td> <input type="password" name="pwd"> </td> </tr>
<tr> <td align=center colspan="2"><input type="submit" value="submit"></td> </tr>
</table> </center>
</form>
</body>
</html>
Ini.java:
import javax.servlet.*;
import java.sql.*;
import java.io.*;
public class Ini extends GenericServlet
web.xml:
<web-app>
<servlet>
<servlet-name>init1</servlet-name>
<servlet-class>Ini</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>init1</servlet-name>
<url-pattern>/regis</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT:
Thus a table is created and the details are entered into the table using jdbc from the
registration form successfully.
DESCRIPTION:
JSP scripting elements let you insert Java code into the servlet that will be generated from
the current JSP page. There are three forms:
1. Expressions of the form <%= expression %> that are evaluated and inserted into the
output,
2. Scriptlets of the form <% code %> that are inserted into the servlet's service
method, and
3. Declarations of the form <%! code %> that are inserted into the body of the servlet
class, outside of any existing methods.
Each of these is described in more detail below.
JSP Expressions
A JSP expression is used to insert Java values directly into the output. It has the following
form:
• session, the HttpSession associated with the request (if any); and
• out, the PrintWriter (a buffered version of type JspWriter) used to send output to
the client.
JSP Scriptlets
If you want to do something more complex than insert a simple expression, JSP
scriptlets let you insert arbitrary code into the servlet method that will be built to generate the
page. Scriptlets have the following form:
<%
String queryData = request.getQueryString();
out.println("Attached GET data: " + queryData);
%>
Note that code inside a scriptlet gets inserted exactly as written, and any static
HTML (template text) before or after a scriptlet gets converted to print statements. This
means that scriptlets need not contain complete Java statements, and blocks left open can
affect the static HTML outside of the scriptlets.
JSP Declarations
A JSP declaration lets you define methods or fields that get inserted into the main body
of the servlet class (outside of the service method processing the request). It has the following
form:
AIM: Extract data from the tables and display them in the catalogue page using JDBC.
DESCRIPTION:
Create tables in the database which contain the details of items (books in our case like
Book name, Price, Quantity, Amount)) of each category. Modify your catalogue page (week 2) in
such a way that you should connect to the database and extract data from the tables and
display them in the catalogue page using JDBC.
PROGRAM:
Retrieve.java:
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
import java.util.*;
public class Retrieve extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res) throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@195.100.101.158:1521:cclab","scott","tiger");
Statement s=con.createStatement();
ResultSet r=s.executeQuery("select * from cart");
catch(ClassNotFoundException cl)
{
out.println("class not found"+cl);
}
}
}
web.xml:
<web-app>
<servlet>
<servlet-name>set</servlet-name>
<servlet-class>Cartenter</servlet-class>
</servlet>
RESULT:
The data is extracted from the tables and displayed in the catalogue page using JDBC