Web Technologies Lab Manual
Web Technologies Lab Manual
Web Technologies Lab Manual
MANUAL
DEPARTMENT OF INFORMATION
TECHNOLOGY
WEB TECHNOLOGIES LAB MANUAL
Prepared by: A.P.V.D.L.Kumar, B.Tech,
<style type="text/css">
OUTPUT:
10
OUTPUT: (Leftframe.html)
OUTPUT: (RightFrame.html)
11
<!Program for creating Left frame it contains at least four links for navigation, which
will display the catalogue of respective links(Leftframe.html)-->
<html>
<body fontsize="5" bgcolor=#85697 >
<center>
<a href="cse.html" target=showframe><h2>CSE</h2></a><br><br>
<a href="ece.html" target=showframe><h2>ECE</h2></a><br><br>
<a href="eee.html" target=showframe><h2>EEE</h2></a><br><br>
<a href="civil.html" target=showframe><h2>CIVIL</h2></a><br><br>
</body>
</center>
</html>
<!Program for creating Right frame: The pages to the links in the left frame must be
loaded here. Initially this page contains description of the web site(RightFrame.html)-->
12
OUTPUT:
13
<!Program for creating the login page it contains the fields Login, Password text
boxes and submit, reset buttons. (Login.html)-->
<html>
<head>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
14
14
OUTPUT:
15
<!Program for creating the Catalogue page should contain the details of all the books
available in the web site in a table. The details should contain the following: 1. Snap shot
16
17
</tr>
<tr>
<td>
<table width="60%" align="center">
<tr>
<td></td>
<td align="left">$63</td>
<td align="right"><input type="button" value="ADD TO CART"/></td>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
18
18
19
OUTPUT:
20
21
22
23
OUTPUT:
24
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
</select>
<tr>
<td align="right">Email-ID:<font color="red"><sup>*</sup></font></td>
<td align="left"><input type="text" maxlength="40" size="35" name="ename">
</tr>
<tr>
<td align="right">Phone number:<font color="red"><sup>*</sup></font></td>
<td align="left"><input type="text" maxlength="40" size="35" name="phn">
</tr>
<tr>
<td align="right">Languages known:</td>
<td align="left"><input type="checkbox" name="hb" value="en">English</td>
<td align="left"><input type="checkbox" name="hb" value="te">Telugu</td>
</tr>
<tr>
<td></td>
<td align="left"><input type="checkbox" name="hb" value="hi">Hindi</td>
<td align="left"><input type="checkbox" name="hb" value="ta">Tamil</td>
</tr>
<tr>
<td align="right">Address:<font color="red"><sup>*</sup></font></td>
<td align="left"><textarea rows="6" cols="20" name="add">
</textarea> </td>
</tr>
<tr>
<td align="right">About us:</td>
<td align="left"><textarea rows="8" cols="30" name="abu"></textarea> </td>
</tr>
<tr>
<td></td>
<td align="left"><input type="checkbox" name="xx" value="yy">I Agree with terms and
Conditions</td>
</tr>
<tr> <td></td>
<td align="left"><input type="SUBMIT" value="SUBMIT"></td>
<td align="right"><input type="RESET" value="RESET"></td>
</tr>
</table>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
25
25
</body>
OUTPUT: (cse.html)
OUTPUT: (ece.html)
26
<!--link code for CSE, it shows CSE Books should be displayed in the Right
frame(cse.html)-->
<html>
<body bgcolor=pink>
<h1><center>CSE TEXTBOOKS</center>
<img src="F:\APVDL KUMAR\WEEK1,2\ai.jpg"><b>THIS IS AI TEXTBOOK</b></h1>
</body>
</html>
<!--link code for ECE, it shows ECE Books should be displayed in the Right
frame(ece.html)-->
<html>
<body bgcolor="#E9CFEC">
<center><B><H1>ECE TEXTBOOKS</H1></B></center>
<img src="F:\APVDL KUMAR\WEEK1,2\ece.jpg" width=100>
<b>THIS IS ECE TEXTBOOK</b>
</body>
</html>
<!--link code for EEE, it shows EEE Books should be displayed in the Right
frame(eee.html)-->
<html>
<body bgcolor="#8EEBEC">
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
27
27
OUTPUT:
28
WEEK 3:
AIM: VALIDATION:
Write JavaScript to validate the following fields of the above registration page.
2. 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])
4. Phone number (Phone number should contain 10 digits only).
Note: You can also validate the login page with these parameters.
<!Program for validating the username (Name should contains alphabets and the
length should not be less than 6 characters)(uservalid.html) -->
<html>
<head>
<title>validating a textbox</title>
<script language="javascript">
function button_click()
{
var fname=f.fname.value;
var spchar = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~";
if(fname.length<6)
{
alert("first name atleast 6 characters");
}
if(fname!="")
{
for (var i=0;i<fname.length;i++)
{
if(spchar.indexOf(fname.charAt(i)) != -1)
{
alert ("Userid should not have special characters");
f.fname.value="";
f.fname.focus();
return false;
}
}
}
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
29
29
if(fname.length>=6)
alert("valid username");
}
</script>
<body>
<center>
<form name="f">
<table>
<h2 align="center">USER NAME VALIDATION</h2>
<tr>
<td align="right">USERNAME:</td>
<td><input type="text" name="fname" maxlength=20 size=30></td>
</tr>
<br>
OUTPUT:
30
<tr>
<td></td>
<td><input type="button" value="SUBMIT" onClick="button_click()"></td></tr>
</form>
</table>
</center>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
31
31
</body>
</html>
OUTPUT:
32
33
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
34
34
<!Program for E-mail id validation(should not contain any invalid and must follow
the standard pattern-)(emailvalid.html)-->
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
35
35
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
36
36
37
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
38
38
WEEK-4:
AIM: Design a web page using CSS (Cascading Style Sheets) which includes the following:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
39
39
Then, in the body of your pages, you refer to these selectors to activate the styles.
<!Program for creating inline style sheets(inline.html)-->
<head>
<title>inline style sheet</title>
</head>
<body>
normal bold:<b>web technologies</b><br>
after applying inline style
<b style="color:red;font-size:22px;font-family:arial;text-decoration:underline">Web
technologies</b>
</body>
</html>
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
40
40
2. Set a background image for both the page and single elements on the page.
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
41
41
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
42
42
43
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
44
44
A:link
45
46
47
<html>
<head>
<title>Layers Demo</title>
</head>
<body>
LAYER 1 ON TOP
<div style="position:relative;font-size:50px;z-index:2;">LAYER1</div>
<div style="position:relative;top:-50;left:5;color:red;font-size:80px;zindex:1;">LAYER2</div>
LAYER 2 ON TOP
<div style="position:relative;font-size:50px;z-index:3;">LAYER1</div>
<div style="position:relative;top:-50;left:5;color:red;font-size:80px;zindex:4;">LAYER2</div>
</body>
</html>
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
48
48
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
50
50
WEEK-5:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
51
51
52
53
54
WEEK-6:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
55
55
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 .
Procedure:
Developing a Simple Bean Using the BDK:
This section presents an example that shows how to develop a simple Bean and
connect it to other components via the BDK.
Our new component is called the Colors Bean. It appears as either a circle or square that is
filled with a color. A color is chosen at random when the Bean begins execution. A public
method can be invoked to change it. Each time the mouse is clicked on the Bean, another
random color is chosen. There is one boolean read/write property that determines the shape.
The BDK is used to lay out an application with one instance of the Colors Bean
Create a New Bean
Here are the steps that you must follow to create a new Bean:
1. Create a directory for the new Bean.
2. Create the Java source file(s).
3. Compile the source file(s).
4. Create a manifest file.
5. Generate a JAR file.
6. Start the BDK.
7. Test.
The following sections discuss each of these steps in detail.
Create a Directory for the New Bean:
You need to make a directory for the Bean. To follow along with this example, create
D:\kumar\week6\. Then change to that directory.
OUTPUT:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
56
56
57
58
change();
}
public boolean getsquare() {
return square;
}
public void setSquare(boolean flag) {
this.square = flag;
repaint();
}
public void change()
{
color = randomColor();
repaint();
}
private Color randomColor()
{
int r = (int)(255*Math.random());
int g = (int)(255*Math.random());
int b = (int)(255*Math.random());
return new Color(r, g, b);
}
public void paint(Graphics g)
{
Dimension d = getSize();
int h = d.height;
int w = d.width;
g.setColor(color);
/*g.setColor(getForeground());*/
if(square) {
g.fillRect(40, 40, 80, 80);
}
else {
g.fillOval(30, 30, 80, 80);
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
59
59
}
}
}
Compile the source code to create a class file. Type the following:
D:\kumar\week6>javac Colors.java on the command prompt
Create a Manifest File:
You must now create a manifest file. First, switch to the D:\kumar\week6 directory. This
is the directory in which the manifest files for the BDK demos are located. Put the
source code for your manifest file in the file colors.mft. It is shown here:
Name: Colors. class
Java-Bean: True
(Here one space must be required after Name: and Java-Bean: & after writing True
carriage return(press enter))
This file indicates that there is one .class file in the JAR file and that it is a Java Bean.
Notice that the Colors.class file is in the package D:\kumar\week6
Generate a JAR File:
Beans are included in the ToolBox window of the BDK only if they are in JAR files in the
directory c:\beans\jars. These files are generated with the jar utility. Enter the following:
D:\kumar\week6>jar cfm Colors.jar colors.mft *.class
This command creates the file Colors.jar and places it in the directory D:\beans\jars.
(You may wish to put this in a batch file for future use.)
Start the BDK:
Change to the directory D:\beans\beanbox and type run. This causes the BDK to start.
You should see four windows, titled ToolBox, BeanBox, Properties and Method Tracer. The
ToolBox window should include an entry labeled Colors for your new Bean.
Create an Instance of the Colors Bean
After you complete the preceding steps, create an instance of the Colors Bean in the
BeanBox window by dropping the Color bean into BeanBox. Test your new component by
pressing the mouse anywhere within circle or square shape. Its color immediately changes.
Use the Properties window to change the square property from false to true. Its shape
immediately changes.
60
While installation assign port number 4040 to TOMCAT and 8080 to APACHE. Make
sure that these ports are available i.e., no other process is using this port.
2) Access the above developed static web pages for books web site, using these servers by
putting the web pages developed in week-1 and week-2 in the document root. Access the
pages by using the urls : http://localhost:4040/rama/books.html (for
tomcat)http://localhost:8080/books.html (for Apache)
1) Tomcat Server Installation Procedure:
Visit the Apache Website http://tomcat.apache.org to get the latest information. On
the home page, click the link Tomcat 5.x under the heading Download. Scroll down the page
until you find the heading 5.5.23, under which you will find sub heading Binary
Distributions.(for ex zip,exe,tar). But the choice of download may depend up on your
operating system.If you are using windows o.s download either the .zip file(apache-tomcat5.5.23.zip) or the .exe file(apache-tomcat-5.5.23.exe).
If you are using unix based o.s download the .tar.gz file(apache-tomcat5.5.23.tar.gz) Installing Under Windows O.S :If you have downloaded the .zip version of Tomcat, simply extract the content using a file
extractor tool (such as winzip or winrar) to the c:\drive.
(After the extraction process is completed, you will find a directory named apache-tomcat5.5.23 and a no.of subdirectories under it including a couple of files such as RUNNING.TXT,
NOTICE.FILE, RELEASE-NOTES.FILE and LICENSE.FILE .)
Note 1 : you may also use the Jar command that comes with JDK, to extract the content. The
command is Jar -xvf apache-tomcat-5.5.23.zip
Note 2 : if you wish , you can rename the directory apache-tomcat-5.5.23 with a convenient
and shorter name as tomcat 5.5
Note 3 : directory containing tomcat(c:\apache-tomcat-5.5.23) is called
CATALINA_HOME, and if you want tomcat to work correctly set this variable. if you have
download the .exe version, installation is very easy. Execute the apache-tomcat.5.5.23.exe
either by selecting open or double-click it.
61
During the installation you may have to make several choices such as Choosing the features
of tomcat :- you have the options to select Normal, full , minimum or custom, select one
among them.
62
choosing the port number, username , and password : Default port number is
8080, of course you may also choose the port number of your choice, provide user name and
password.
Choosing the JVM : Default JVM would be automatically selected, if you have multiple
JVMs installed on your system, provide a suitable path here.
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
63
63
Click on Install button, then you will see the following windows screen :-
64
Finally you will see the following window if the installation is successfully completed.
WEB-INF
classes
[. html] files
web.xml
[. Java] and
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
65
65
[.class] files
Servlets are to servers what applets are to browsers. Unlike applets, however, Servlets
have no graphical user interface. Servlets can be embedded in many different servers because
the servlet API, which you use to write Servlets, assumes nothing about the server's
environment or protocol. Servlets have become most widely used within HTTP servers; many
web servers support the Servlet API.
1.1.1.1 The ServletResponse Interface:
The ServletResponse interface gives the servlet methods for replying to the client. It
allows the servlet to set the content length and MIME type of the reply. Provides an output
stream, ServletOutputStream, and a Writer through which the servlet can send the reply data.
Interfaces that extend the ServletResponse interface give the servlet more protocolspecific capabilities. For example, the HttpServletResponse interface contains methods that
allow the servlet to manipulate HTTP-specific header information.
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
66
66
The classes and interfaces described above make up a basic Servlet. HTTP Servlets
have some additional objects that provide session-tracking capabilities. The servlet writer can
use these APIs to maintain state between the servlet and the client that persists across
multiple connections during some time period. HTTP Servlets also have objects that provide
cookies. The servlet writer uses the cookie API to save data with the client and to retrieve this
data.
The classes mentioned in the Architecture of the Servlet Package section are shown in
the example in bold:
SimpleServlet extends the HttpServlet class, which implements the Servlet interface.
SimpleServlet overrides the doGet method in the HttpServlet class. The doGet method
is called when a client makes a GET request (the default HTTP request method) and
results in the simple HTML page being returned to the client.
Within the doGet method an HttpServletRequest object represents the users request.
Because text data is returned to the client, the reply is sent using the Writer object
obtained from the HttpServletResponse object.
67
2) AIM: Access the above developed static web pages for books web site, using these
servers by putting the web pages developed in week-1 and week-2 in the document root.
Access the pages by using the urls : http://localhost:4040/rama/books.html (for
tomcat)http://localhost:8080/books.html (for Apache)
Procedure:
Step1: The web pages developed in week-1 and week-2 can be grouped together and give the
folder name as week7 and this folder pasted on the following link
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps
Step2: After successful installation of Tomcat in our system, go to START->Programs
->Apache Tomcat 6.0->Configure Tomcat as shown shown in below:
68
Step3: Open some web browser(internet explorer) and type the URL http://localhost:8080
in address bar (or) simply go to Start->Programs->Apache Tomcat 6.0-> Welcome option
then you will get the following window:
69
After clicking the ok button in the above window then you will get the following window
Here you can find the week7 folder i.e whatever you done in the step1.Then click the week7
in the above webpage you will get the following output, here you can see our week1 and
week2 web pages can be run under week7 folder in the Tomcat server i.e.
http://localhost:8080/week7 as shown in below figure.Here http is a Hyper Text Transfer
Protocol which is used to transfer the data from one web page into another web page and
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
70
70
Step4: For example in the Tomcat installation process if you will give the port number as
4040 then you must access the week7 application through the following link
http://localhost:4040/week7 .
Step5: After successful execution of our week7 application you should stop the Tomcat
Server by clicking the stop button , it is shown in the below windows.
71
OUTPUT:
Here in the below login page type user1 as username and pwd1 as password:
Click submit button, then another window will appear in which the CookieDemo servlet is
invoked. Hence you will get the following window
72
WEEK-8:
AIM: User Authentication :Assume four users user1,user2,user3 and user4 having the
passwords pwd1,pwd2,pwd3 and pwd4 respectively. Write a servelet for doing the
following.
1. Create a Cookie and add these four user ids and passwords to this Cookie.
2. 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.
Procedure:
This assignment can be performed in two ways- in the first approach we will make use of
cookies to store username and password. In the second way, we will make use of init
parameters to store the user names and password in webinf.xml file. let us see the first way of
authenticating user.
a)Use of cookies:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
73
73
OUTPUT:
Now in the address bar type getCookie then you will get the following window.
74
77
}
else
{
out.println("You are not authentic user!!");
}
}
}
catch(Exception e)
{
out.println("Invalid username/password");
}
}
out.close();
}
}
To get the class file for above program we use this command
javac getCookieServlet.java
This class file must be at the path
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\week8\WEBINF\classes
Step 4:
In the WEB-INF directory
(C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\week8\WEB-INF)
there is web.xml file. Open it using notepad and type as follows.
<web-app>
<servlet>
<servlet-name>CookieDemo1</servlet-name>
<servlet-class>CookieDemo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CookieDemo1</servlet-name>
<url-pattern>/cookie</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>getCookieServlet1</servlet-name>
<servlet-class>getCookieServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>getCookieServlet1</servlet-name>
<url-pattern>/getCookie</url-pattern>
</servlet-mapping>
</web-app>
Save this file and exit.
Step 5:
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
78
78
OUTPUT:
Here in the below login page type username as user1 and password as pwd1:
79
b)Use of init-parameters:
Now if we want to validate a user using the getInitParameters() method then follow the
following stepsstep 1: create a login form as follows(Login.html)
<html>
<head>
<title>Input Form</title>
</head>
<body>
<center>
<form name="form 1" method=get action="http://localhost:8080/week8b/gangaraju">
<h3>Login Page</h3>
<table>
<tr>
<td><b>UserName:</b></td>
<td><input type="text" name="User_name" size="25" value=""></td>
</tr>
<tr>
<td><b>Password:</b></td>
<td><input type="password" name="pwd" size="25" value=""></td>
</tr>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
80
80
OUTPUT:
Again go back to login page and give the user name as user1 and password as pwd3 you will
get the following output:
81
<servlet-name>getuserServlet1</servlet-name>
<url-pattern>/gangaraju</url-pattern>
</servlet-mapping>
</web-app>
Save this web.xml file and close it.
Step 3: Now write a java servlet program as follows:
getuserServlet.java
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
82
82
83
84
According to above model the presentation logic has to be implemented in JSP page
and the business logic has to be implemented as part of Java bean This model help us in
separating the presentation and business logic. For large-scale projects instead of using
model1 it is better to use model2 (MVC). Struts framework is based on model 2.
Java Server Pages (JSP) lets you separate the dynamic part of your pages from the
static HTML. You simply write the regular HTML in the normal manner, using whatever
Web-page-building tools you normally use. You then enclose the code for the dynamic parts
in special tags, most of which start with "<%" and end with "%>". For example, here is a
section of a JSP page that results in something like "Thanks for ordering Core Web
Programming
For URL of http://host/OrderConfirmation.jsp?title=Core+Web+Programming:
Thanks for ordering
<I><%= request.getParameter ("title") %></I>
You normally give your file a .jsp extension, and typically install it in any place you
could place a normal Web page. Although what you write often looks more like a regular
HTML file than a servlet, behind the scenes, the JSP page just gets converted to a normal
servlet, with the static HTML simply being printed to the output stream associated with the
servlet's service method. This is normally done the first time the page is requested, and
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
85
85
momentary delay when the JSP page is translated to a servlet and the servlet is compiled and
loaded. Note also that many Web servers let you define aliases that so that a URL that appears
to reference an HTML file really points to a servlet or JSP page.
Aside from the regular HTML, there are three main types of JSP constructs that you
embed in a page: scripting elements, directives, and actions. Scripting elements let you
specify Java code that will become part of the resultant servlet, directives let you control the
overall structure of the servlet, and actions let you specify existing components that should be
used, and otherwise control the behavior of the JSP engine. To simplify the scripting
elements, you have access to a number of predefined variables such as request in the snippet
above.
86
OUTPUT:
MySQL command prompt:
OUTPUT: (Registration_Form.jsp)
87
WEEK-9
AIM: Install a database(Mysql or Oracle).
Create a table which should contain at least the following fields: name, password, emailid,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.
Procedure:
Step 1: Start MYSQL server goto Start->Programs->MySQLServer5.0->MySQL Command
Line Client then you will get the MySQL command prompt as shown in the output.
Step 2: create a database named registration_DB using following command on the MYSQL
prompt
Then create a table under the database registration_DB as followsA.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
88
88
OUTPUT:
The extracted data from the table will be displayed as follow:
89
The submitted details can be stored in the MySQL server to check our student data is stored
or not .Here in the below figure it is successful and our data(JSP application data) is stored on
our database(MySQL) using JDBC connectivity.
ResultSet rs=null;
Statement stmt=null;
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
90
90
91
92
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
<%}%>
Step 3:Open some web browser and give the address of above JSP
page(http://localhost:8080/examples/jsp/Registration_Form.jsp) in the address bar then
the output can be obtained.
93
OUTPUT:
Here in the below registration page type student name as user2 and password as pwd2
94
WEEK-10:
AIM: Write a JSP which does the following job:
Insert the details of the 3 or 4 users who register with the web site (week9) by using
registration form. Authenticate the user when he submits the login form using the user
name and password from the database ( similar to week8 instead of cookies).
Procedure:
Here we have assumed that there are four valid users user1, user2, user3, and user4
having passwords pwd1, pwd2, pwd3, and pwd4 respectively.
On the login page we must provide proper username and password. For instance user1
the password must be pwd1 and so on.
Step 1: Start MYSQL server goto Start->Programs->MySQLServer5.0->MySQL Command
Line Client then you will get the MySQL command prompt as shown in the output.
Step 2: create a database named registration_DB using following command on the MYSQL
prompt
<%
Connection conn=null;
ResultSet rs=null;
Statement stmt=null;
OUTPUT:
Here in the below registration page type student name as user2 and password as
webtechnologies
Here user2 password should be pwd2, so it displays You have entered invalid
username/password, try again!!!
96
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/registration_DB","root","b
vcits");
stmt=conn.createStatement();
if(request.getParameter("action") !=null)
{
String Studname=request.getParameter("Studname");
String Studpass=request.getParameter("Studpass");
String Studemail=request.getParameter("Studemail");
String Studphone=request.getParameter("Studphone");
if(Studname.equals("user1") && Studpass.equals("pwd1"))
{
out.write("Welcome"+Studname);
stmt.executeUpdate("insert into registration_table1
(name,password,email,phone)values('"+Studname+"','"+Studpass+"','"
+Studemail+"', '"+Studphone+"')");
}
else if(Studname.equals("user2") && Studpass.equals("pwd2"))
{
out.write("Welcome"+Studname);
stmt.executeUpdate("insert into registration_table1(name,password,email,phone)
values('"+Studname+"','"+Studpass+"','"+Studemail+"','"+Studphone+"')");
}
else if(Studname.equals("user3") && Studpass.equals("pwd3"))
{
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
97
97
OUTPUT:
Here is the MySQL server command prompt, in this you check the your entered username
and password must be saved to check the user authentication and it is saved in our database.
98
<body>
<center>
<h2>Student List</h2>
<table border="1">
<tr>
<th>No</th>
<th>User Name</th>
A.P.V.D.L.KUMAR, (M.Tech) ASST. PROFESSOR,
BVCITS, AMALAPURAM
99
99
100
OUTPUT:
101
102
103
Here is the MySQL command prompt which shows about our books details are stored in the
database.
104
String Bookisbn=request.getParameter("Bookisbn");
String Bookedition=request.getParameter("Bookedition");
String Bookprice=request.getParameter("Bookprice");
String Bookquantity=request.getParameter("Bookquantity");
stmt.executeUpdate("insert into
Catalog_table(name,author,publication,isbn,edition,price,quantity)values('"+Bookname+"','"+
Bookauthor+"','"+Bookpublisher+"','"+Bookisbn+"','"+Bookedition+"','"+Bookprice+"','"+Bo
okquantity+"')");
rs=stmt.executeQuery("select * from Catalog_table");
%>
<html>
<body>
<center>
<h2>Catalog Page</h2>
<table border="1" cellspacing="0"cellpadding="0">
<tr>
<th>S.No</th>
<th>Book Name</th>
<th>Author</th>
<th>Publisher</th>
<th>ISBN</th>
<th>Edition</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<%
int num=1;
while(rs.next()){
%>
<tr>
<td><%=num%></td>
<td><%=rs.getString("name")%></td>
<td><%= rs.getString("author")%></td>
<td><%= rs.getString("publication")%></td>
<td><%= rs.getString("isbn")%></td>
<td><%= rs.getString("edition")%></td>
<td><%= rs.getString("price")%></td>
<td><%= rs.getString("quantity")%></td>
</tr>
<%
num++;
}
rs.close();
stmt.close();
A.P.V.D.L.KUMAR, (M.Tech) ASST. 105
PROFESSOR, BVCITS, AMALAPURAM
105
106
107