Develop static pages (using only HTML) of an online Book store. The
pages should resemble: www.amazon.com
The website should consist the following pages.
Home page, Registration and user Login, User profile page, Books
catalog, Shopping cart, Payment By credit card, order confirmation.
Validate the registration, user login, user profile and payment by credit
card pages using JavaScript.
2
3
4
5
6
7
Create and save an XML document at the server, which contains 10
users information. Write a program which takes User Id as input and
returns the user details by taking the user information from the XML
document.
Bean Assignments
a. Create a JavaBeans which gives the exchange value of INR
(Indian Rupees) into equivalent American/Canadian/Australian
Dollar value.
b. Create a simple Bean with a label which is the count of number
of clicks. Then create a Bean info class such that only the count
properly is visible in the property Window.
c. Create two Beans – a) Keypad b) Display pad. After that
integrate the two Beans to make it work as a calculator.
d. Create two Beans Traffic Light(implemented as a label with only
three background colors-red, green, yellow) and
Automobile(Implemented as a Text Box which states its
state/movement). The state of the Automobile should depend on
the following Light Transition table.
Install TOMCAT web server. Convert the static web pages of
assignments 2 into dynamic web pages using servlets and cookies. Hint:
User’s information (user id, password, credit card number) would be
stored in web. Xml. Each user should have a separate shopping cart.
Redo the previous task using JSP by converting the static web pages of
assignment 2 into dynamic web pages. Create a database with user
information and books information. The books catalogue should be
dynamically loaded from the database. Follow the MVC architecture
while doing the website.
Implement the “Hello World” program using JSP Struts Framework.
1
JNTUH
WEB TECHNOLOGIES
1.Develop static pages (using only HTML) of an online Book store. The pages should
resemble: www.amazon.com
The website consists the following pages.
Home page, Registration and user Login, User profile page, Books catalog, Shopping
cart, Payment By credit card, order confirmation.
HOME PAGE
<!DOCTYPE html>
<html>
<body>
<table width=100%>
<tr>
<td><img src="amazonlogo.jpg"> </td>
<td style="background-color:#E55151">
<h1> WELCOME TO AMAZON.COM <h1> </td>
</tr>
<tr>
<td colspan="2" style="background-color:#AFB3F2"> HOMEPAGE
</td>
</tr>
<tr>
<td colspan="2" style="background-color:#E8F2AF; text-align:center">
<a href="regamazon.html" style="text-decoration:none"> registration
link </a>
<hr>
<a href="logamazon.html" style="text-decoration:none"> user login link </a>
<hr>
<a href="profamazon.html" style="text-decoration:none" > user profile page </a>
<hr>
<a href="bookamazon.html" style="text-decoration:none" > books catalog </a>
<hr>
<a href="shopcart.html" style="text-decoration:none"> shopping cart</a>
<hr>
<a href="payamazon.html" style="text-decoration:none"> payment by
credit card
</a>
<hr>
<a href="orderamazon.html" style="text-decoration:none"> order confirmation </a>
</td>
</tr>
<tr>
<td colspan="2" style="background-color:#FFA500;text-align:center;">
www.amazon.com </td>
</tr>
</body>
</html>
<p class="reg"> Sign In <br> What is your e-mail address?</p>
<table align="center">
<tr >
<form action="">
<td style="text-align:right">My e-mail address is:</td> <td> <input
type="text"
name="emailid1"></td>
</form>
</tr>
</table>
<p class="reg"> Do you have an Amazon.com password?</p>
<table align="center">
<tr >
<form action="">
<input type="radio" name="ans" value="no">No, I am a new
customer<br>
<input type="radio" name="ans" value="yes">Yes,I have a password:<input
type="text" name="password"><br>
</form>
</tr>
<tr> <a href="">Forgot password</a></tr>
<tr>
<td>
<button type="button">Sign in using our secure server</button>
</td>
</table></b>
</div>
<div id="help">
<p>Sign In Help</p>
<p>Forgot your password? <a href=""> Get password help.</a></p>
<p> Has your e-mail address changed? <a href="">Update it
here.</a></p>
<hr>
</div>
<div id="footer" style="text-align:center"><a href="">Conditions of Use</a>
<a href="">Privacy Notice</a>@ 1996-2013,Amazon.com,Inc. or its affliates</div>
</DIV>
</body>
</html>
<script>
function myFunc()
{
if(document.getElementById("myName").elements[0].value=="")
{
alert("First name must be filled out");
return false;
}
if(document.getElementById("myMail").elements[0].value=="")
{
alert("Please provide the e-mail id!");
return false;
}
if(document.getElementById("Mail").elements[0].value=="")
{
19
JNTUH
WEB TECHNOLOGIES
alert("Type in the e-mail id again !");
return false;
}
if(document.getElementById("myMail").elements[0].value.length!
=document.getElementById("Mail").elements[0].value.length)
{
alert("E-mail id do not match");
document.getElementById("myMail").elements[0].value="";
document.getElementById("Mail").elements[0].value="";
return false;
}
if(document.getElementById("myMail").elements[0].value.length==document.getElementBy
Id("Mail").elements[0].value.length)
{
if(document.getElementById("myMail").elements[0].value!
=document.getElementById("Mail").elements[0].value)
{
alert("E-mail id do not match");
document.getElementById("myMail").elements[0].value="";
document.getElementById("Mail").elements[0].value="";
return false;
}
}
if(document.getElementById("myPhone").elements[0].value="")
{
alert("Please enter a valid phone number");
return false;
}
if(document.getElementById("myPass").elements[0].value=="")
{
alert("Please enter a password");
return false;
20
JNTUH
WEB TECHNOLOGIES
}
if(document.getElementById("myPass").elements[0].value!="")
{
if(document.getElementById("myPass").elements[0].value.length<8)
{
alert("password should be atleast of length 8");
return false;
}
}
if(document.getElementById("Pass").elements[0].value=="")
{
alert("Type in the password again !");
return false;
}
if(document.getElementById("myPass").elements[0].value.length!
=document.getElementById("Pass").elements[0].value.length)
{
alert("passwords do not match");
document.getElementById("myPass").elements[0].value="";
document.getElementById("Pass").elements[0].value="";
return false;
}
if(document.getElementById("myPass").elements[0].value.length==document.getElementBy
Id("Pass").elements[0].value.length)
{
if(document.getElementById("myPass").elements[0].value!
=document.getElementById("Pass").elements[0].value)
{
alert("passwords do not match");
document.getElementById("myPass").elements[0].value="";
document.getElementById("Pass").elements[0].value="";
return false;
21
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
p.reg {color:#990000}
</style>
24
JNTUH
WEB TECHNOLOGIES
</head>
<body><font size="4">
<script>
function myFunc()
{
if(document.getElementById("mail").elements[0].value=="")
{
alert("Please enter the e-mail id");
return false;
}
if(document.getElementById("options").elements[1].checked)
{
if(document.getElementById("options").elements[2].value=="")
{
alert("please write password");
return false;
} }}
</script>
<p class="reg"> Sign In <br> What is your e-mail address?</p>
<table align="center">
<tr >
<form id="mail" action="">
<td style="text-align:right">My e-mail address is:</td> <td> <input
name="emailid1"></td>
type="text"
</form>
</tr>
</table>
<p class="reg"> Do you have an Amazon.com password?</p>
<table align="center">
<tr >
<form id="options" action="">
<input type="radio" name="ans" value="no">No, I am a new
customer<br>
<input type="radio" name="ans" value="yes">Yes,I have a password:<input
type="text" name="password"><br>
</form>
</tr>
<tr> <a href="">Forgot password</a></tr>
<tr>
<td>
<button onclick="myFunc()">Sign in using our secure server
</td>
</table></b>
</div>
<div id="help">
<p>Sign In Help</p>
<p>Forgot your password? <a href=""> Get password help.</a></p>
<p> Has your e-mail address changed? <a href="">Update it
<hr>
</div>
26
here.</a></p>
JNTUH
WEB TECHNOLOGIES
<div id="footer" style="text-align:center"><a href="">Conditions of Use</a>
<a href="">Privacy Notice</a>@ 1996-2013,Amazon.com,Inc. or its affliates</div>
</DIV>
</body>
</html>
PAYMENT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<script>
function myFunc()
{
if(document.getElementById("ship").elements[0].value=="")
{
alert("Please enter the name");
return false;
27
JNTUH
WEB TECHNOLOGIES
}
if(document.getElementById("ship").elements[1].value=="")
{
alert("Please enter the address");
return false;
}
if(document.getElementById("ship").elements[2].value=="")
{
alert("Please enter the address");
return false;
}
if(document.getElementById("ship").elements[3].value=="")
{
alert("Please enter the city");
return false;
}
if(document.getElementById("ship").elements[4].value=="")
{
alert("Please enter the state");
return false;
}
if(document.getElementById("ship").elements[5].value=="")
{
alert("Please enter the ZIP");
return false;
}
if(document.getElementById("ship").elements[7].value=="")
{
alert("Please enter the phone no.");
return false;
28
<p><font size="6"> Optional Delivery Preferences</font></p>
<form id="ship1" action=""><b>
Address Type:<br><select name="addresstype" placeholder="Select an Address Type">
<option value="res">Residential</option>
<option value="com">Commercial</option>
</select><br>
Security Access Code:<br><input type="text" placeholder="For buildings or gated
communities"><br>
Is this address also your billing address(the address that appears on your credit card or bank
statement)?<br>
<input type="radio" name="ans" value="yes">Yes<br>
<input type="radio" name="ans" value="no">No (If not, we'll ask you for it in a moment )
<br>
<hr>
</form>
3. XSL FILE TO RETREIVE THE DATA
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4. Create and save an XML document which contains 10 users information. Write a
program which takes User Id as input and returns the user details by taking the user
information from the XML document.
demo.html
<html>
<body>
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","details.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("user");
function myfun()
{
var a = document.forms["form1"]["userid"].value;
for (i=0;i<x.length;i++)
{
if (a==x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue)
{ document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue );
document.write(" ");
document.write(x[i].getElementsByTagName("age")[0].childNodes[0].nodeValue);
40
5. JavaBeans which gives the exchange value of INR (Indian Rupees) into equivalent
American Dollar value.
Indian.java
import java.beans.*;
import java.awt.*;
import java.awt.event.*;
public class Indian extends Canvas
{
private double rupees;
private String other;
public Indian()
{
setSize( 200 ,25 );
other= "America" ;
}
public void setRupees( double amount)
{ rupees=amount; repaint();
}
public double getRupees()
{ return rupees;
}
public void setOther( String other)
{ this .other=other;
repaint();
}
44
JNTUH
WEB TECHNOLOGIES
public String getOther()
{ return other;
}
public void paint( Graphics g)
{
if (other.equals( "America" ))
g.drawString( String .valueOf(rupees/ 42 ), 20 ,20 );
else
if (other.equals( "Australia" ))
g.drawString( String .valueOf(rupees/ 27 ), 20 ,20 );
else if (other.equals( "Canada" ))
g.drawString( String .valueOf(rupees/ 35 ), 20 ,20 );
else g.drawString( "I Can't convert for such country" ,20 ,20 );
}
}
1.
Compile the source code for the Bean and generate the
Currency_converter1.class in the command prompt :
javac Indian.java
2.
Create a manifest file in a text editor.
The manifest file specifies the name of the class file and indicates that it is a
JavaBean. The manifest file becomes part of the JAR file. You can name the
manifest file manifest.man. It contains the following two lines:
Name: Indian.class
JavaBean: True
(On Windows, be sure to include a carriage return at the end of the text in the
manifest file.)
3..
Create the executable JAR file.
Use the form of the jar command to include the manifest file along with the
Indian.class file (Type the command on one line):
45
JNTUH
WEB TECHNOLOGIES
jar cfm indian.jar manifest.man Indian.class
NetBean 6.1 IDE For Indian JavaBean
ï‚·
ï‚·
ï‚·
ï‚·
Click File | New Project to create a new project, a grouping of related files. Follow
the wizard steps below.
1. Choose Project - General | Java Application
2. Name and Location - Uncheck Create Main Class, check Set as Main Project
Click File | New File to create a new file. Follow the wizard steps below.
1. Choose File Type - Java GUI Forms | JApplet Form
2. Class Name - Use Default
Installing Counter JavaBeans - JavaBeans that have been jarr'ed can be downloaded
and added to the Palette .
o Tools | Pallette Manager
1. Click Add from JAR
2. Select JAR file - Locate and select indian.jar
3. Select Components - Highlight indian
4. Select Palette Category - Highlight Beans
o Beans should now contain Indian class
Visual programming - Since applets are visual it is possible to program by dragging
and dropping components from the toolbar.
o Click Design tab.
o To see the layout manager:
 Right click in gray design area | Set Layout | Flow Layout
o To add a visual object, right click the gray area:
 Add From Palette | Swing | JButton
 Add From Palette | Beans | Indian
Then the net beans IDE look like this:
46
JNTUH
WEB TECHNOLOGIES
47
JNTUH
WEB TECHNOLOGIES
48
JNTUH
WEB TECHNOLOGIES
Create a simple Bean with a label which is the count of number of clicks.
Counter.java
import java.awt.*;
public class Counter extends Panel {
private long count=0;
private Label label;
private long maxValue=20;
public void setMaxValue(long max) {
maxValue = max;
}
public long getMaxValue() { return maxValue; }
public Counter() {
setBackground(Color.blue);
setForeground(Color.white);
label = new Label(""+count);
add(label);
}
public void increment () {
if (count < maxValue) {
count++;
label.setText(count+" ");
}
else label.setText("!!");
}
}
1.
Compile the source code for the Bean and generate the Counter.class in
the command prompt :
49
JNTUH
WEB TECHNOLOGIES
javac Counter.java
2.
Create a manifest file in a text editor.
The manifest file specifies the name of the class file and indicates that it is a
JavaBean. The manifest file becomes part of the JAR file. You can name the
manifest file manifest.man. It contains the following two lines:
Name: Counter.class
JavaBean: True
(On Windows, be sure to include a carriage return at the end of the text in the
manifest file.)
3..
Create the executable JAR file.
Use the form of the jar command to include the manifest file along with the
Counter.class file (Type the command on one line):
jar cfm counterEvent.jar manifest.man Counter.class
NetBean 6.1 IDE For Counter JavaBean
ï‚·
ï‚·
ï‚·
ï‚·
Click File | New Project to create a new project, a grouping of related files. Follow
the wizard steps below.
1. Choose Project - General | Java Application
2. Name and Location - Uncheck Create Main Class, check Set as Main Project
Click File | New File to create a new file. Follow the wizard steps below.
1. Choose File Type - Java GUI Forms | JApplet Form
2. Class Name - Use Default
Installing Counter JavaBeans - JavaBeans that have been jarr'ed can be downloaded
and added to the Palette .
o Tools | Pallette Manager
1. Click Add from JAR
2. Select JAR file - Locate and select counterEvent.jar
3. Select Components - Highlight Counter
4. Select Palette Category - Highlight Beans
o Beans should now contain Counter class
Visual programming - Since applets are visual it is possible to program by dragging
and dropping components from the toolbar.
o Click Design tab.
o To see the layout manager:
 Right click in gray design area | Set Layout | Flow Layout
o To add a visual object, right click the gray area:
 Add From Palette | Swing | JButton
 Add From Palette | Beans | Counter
50
JNTUH
WEB TECHNOLOGIES
Then the net beans IDE look like this:
Connecting the Button to the Counter Bean
CounterFrame.java
public class CounterFrame extends javax.swing.JFrame {
public CounterFrame() {
initComponents();
}
private void initComponents() {
counter1 = new Counter();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
51
Create two Beans Traffic Light(implemented as a label with only three background
colors-red, green, yellow) and Automobile(Implemented as a Text Box which states its
state/movement). The state of the Automobile should depend on the following Light
Transition table.
Traffic.java
import java.awt.Panel;
import java.awt.event.*;
import java.io.PrintStream;
import java.io.Serializable;
import javax.swing.JTextField;
import java.beans.*;
public class Traffic extends Panel
implements Serializable, PropertyChangeListener
{
public Traffic()
{
tx = new JTextField(12);
state="Ready";
tx.setHorizontalAlignment(JTextField.LEFT);
tx.setText("Ready");
tx.setEnabled(false);
add(tx);
}
public void change()
{ if(state.equals("Ready"))
{ state="Move";
tx.setText(state);
}
else if(state.equals("Move"))
{ state="Stopped";
55
import java.awt.*;
import java.beans.*;
import java.io.*;
import java.util.Date;
public class TrafficLight extends Panel
implements Runnable, Serializable, PropertyChangeListener
{private Color color;
private Label label;
private PropertyChangeSupport changes;
private int interval;
transient Thread runner;
public TrafficLight()
{
56
JNTUH
WEB TECHNOLOGIES
setSize(50, 50);
color = Color.red;
label = new Label();
label.setSize(100,100);
label.setBackground(Color.red);
add(label);
changes = new PropertyChangeSupport(this);
changes.addPropertyChangeListener(this);
interval = 5;
runner = new Thread(this);
runner.start();
}
public void addPropertyChangeListener(PropertyChangeListener propertychangelistener)
{
changes.addPropertyChangeListener(propertychangelistener);
}
public void removePropertyChangeListener(PropertyChangeListener propertychangelistener)
{
changes.removePropertyChangeListener(propertychangelistener);
}
public int getInterval()
{
return interval;
}
public void setInterval(int i)
{
interval = i;
if(runner != null)
runner.interrupt();
}
public int getSeconds()
57
JNTUH
WEB TECHNOLOGIES
{
return (int)((new Date()).getTime() / 1000L);
}
public void run()
{
int i = getSeconds();
do
{
try
{
Thread.sleep(interval * 1000);
}
catch(InterruptedException interruptedexception) { }
int j = getSeconds();
changes.firePropertyChange("seconds", new Integer(i), new Integer(j));
i = j;
} while(true);
}
public void propertyChange(PropertyChangeEvent propertychangeevent)
{
if(color == Color.red)
{
label.setBackground(Color.orange);
color = Color.orange;
} else
if(color == Color.orange)
{
label.setBackground(Color.green);
color = Color.green;
} else
58
JNTUH
WEB TECHNOLOGIES
if(color == Color.green)
{
label.setBackground(Color.red);
color = Color.red;
}
}
}
1. Compile the source code for the Bean and generate the Traffic.class and
TrafficLight.class in the command prompt :
javac Traffic.java
javac TrafficLight.java
2.
Create a manifest file in a text editor.
The manifest file specifies the name of the class file and indicates that it is a
JavaBean. The manifest file becomes part of the JAR file. You can name the
manifest file manifest1.man and manifest2.man . It contains the
following two lines:
manifest1.man
Name: Traffic.class
JavaBean: True
manifest2.man
Name: TrafficLight.class
JavaBean: True
3.
Create the executable JAR file.
Use the form of the jar command to include the manifest file along with the
Traffic.class and TrafficLight.class file (Type the command on one line):
jar cf Traffic.jar manifest.man Traffic.class
jar cf TrafficLight.jar manifest.man TrafficLight.class
NetBean 6.1 IDE For Light JavaBean
59
JNTUH
ï‚·
ï‚·
ï‚·
ï‚·
WEB TECHNOLOGIES
Click File | New Project to create a new project, a grouping of related files. Follow
the wizard steps below.
1. Choose Project - General | Java Application
2. Name and Location - Uncheck Create Main Class, check Set as Main Project
Click File | New File to create a new file. Follow the wizard steps below.
1. Choose File Type - Java GUI Forms | JApplet Form
2. Class Name - Use Default
Installing Counter JavaBeans - JavaBeans that have been jarr'ed can be downloaded
and added to the Palette .
o Tools | Pallette Manager
1. Click Add from JAR
2. Select JAR file - Locate and select counterEvent.jar
3. Select Components - Highlight TrafficLight
4. Select Palette Category - Highlight Beans
o Beans should now contain TrafficLight class
Visual programming - Since applets are visual it is possible to program by dragging
and dropping components from the toolbar.
o Click Design tab.
o To see the layout manager:
 Right click in gray design area | Set Layout | Flow Layout
o To add a visual object, right click the gray area:
 Add From Palette | Swing | JButton
 Add From Palette | Beans | TrafficLight
public class WelcomeServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);
}
}
web.xml
<web-app>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>Simple</servlet-name>
<servlet-class>Simple</servlet-class>
</servlet>
73
JNTUH
WEB TECHNOLOGIES
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Simple</servlet-name>
<url-pattern>/go</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
</web-app>
main.jsp
<html>
<head>
<title>Using GET Method to Read Form Data</title>
</head>
<body>
<center>
<h1>Using GET Method to Read Form Data</h1>
<ul>
<li><p><b>First Name:</b>
<%= request.getParameter("first_name")%>
</p></li>
<li><p><b>Last Name:</b>
<%= request.getParameter("last_name")%>
</p></li>
</ul>
</body>
81
JNTUH
WEB TECHNOLOGIES
</html>
82
JNTUH
WEB TECHNOLOGIES
JSP(USING COOKIES)
Login.html
<body>
<form action=First.jsp method=post>
Enter Name : <input type="text" name="ename"><br>
Enter city : <input type="text" name="city"><br>
Enter age : <input type="text" name="age"><br>
<input type="submit" value="send">
</form>
</body>
StudBean.java
package sp;
public class StudBean
{
int sno;
String sname;
float marks;
public StudBean()
{
}
public void setSno(int sno)
{
this.sno=sno;
}
public int getSno()
{
87
JNTUH
WEB TECHNOLOGIES
return sno;
}
public void setSname(String sname)
{
this.sname=sname;
}
public String getSname()
{
return sname;
}
public void setMarks(float marks)
{
this.marks=marks;
}
public float getMarks()
{
return marks;
}
}
88
JNTUH
WEB TECHNOLOGIES
89
JNTUH
WEB TECHNOLOGIES
STUDENT DETAILS BY USING SET PROPERTY
student.jsp
<jsp:useBean id="sb1" class="sp.StudBean"/>
<html>
<body>
<h2 style=color:blue>Student Details By using set property<br>
<jsp:setProperty name="sb1" property="sno" value="100"/>
<jsp:setProperty name="sb1" property="sname" value="balu"/>
<jsp:setProperty name="sb1" property="marks" value="75.5"/>
TechBean.java
package tb;
public class TechBean
{
String name;
String lang;
public TechBean()
{
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public void setLang(String lang)
{
this.lang=lang;
}
public String getLang()
{
return lang;
}
public String getLangComments()
{
94
JNTUH
WEB TECHNOLOGIES
if(lang.equals("java"))
{
return "king of oops";
}
if(lang.equals(".net"))
{
return "king of mstech";
}
if(lang.equals("c++"))
{
return "partialoops";
}
else
return "no idea";
}
}
95
JNTUH
WEB TECHNOLOGIES
96
JNTUH
WEB TECHNOLOGIES
CREATE TABLE USING JDBC
import java.sql.*;
public class create
{
public static void main(String args[])throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3307/sushma","root","root");
String qry="create table student11(sno int(5),sname varchar(20),saddr varchar(30))";
Statement st=con.createStatement();
int k=st.executeUpdate(qry);
st.close();
con.close();
}
}
INSERTING VALUES INTO TABLE USING JDBC
import java.sql.*;
97
JNTUH
WEB TECHNOLOGIES
public class insert
{
public static void main(String args[])throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3307/sushma","root","root");
String qry="insert into student1 values(11,'abc','def')";
Statement st=con.createStatement();
int k=st.executeUpdate(qry);
st.close();
con.close();
}
}
98
JNTUH
WEB TECHNOLOGIES
EXECUTION OF QUERY USING SERVLETS-JDBC
db.html
<html>
<body text=red>