program that displays the data in the user table that exists in database, a servlet program that creates a new user entry in the user table in database, Java program to display the details of a particular department from Access database, GUI application using Swings that has a button that uses JColorChooser to change the background of the application to the color choosen in JColorChooser, applet program that implements AdjustmentListener, applet program that allows parameter passing, applet with ‘n’ labels with ‘n’ different colours occupy ‘n’ grids, applet program that implements ItemListener, Java Script program that uses onMouseOver and onMouseOut events, program in Java Script for displaying the current date in the following format. FRIDAY, 3-May-2013, web application using different types of CSS, database using XML and display the content using XSL by validating through XML schema,
4. AIM: To design a web application using different types of CSS.
PROGRAM:
<html>
<head>
<link rel="stylesheet" type="text/css" href="E.css"/>
<style type="text/css">
.medium {border-width:medium}
.thin {border-width:thin}
.solid {border-style:solid}
.outset {border-style:outset}
.red {border-color:red}
.blue {border-top-color:blue;border-left-color:red;border-right-color:red;
border-bottom-color:blue;margin-bottom:1em}
</style>
</head>
<body>
<p>This text doesnot have style applied</p>
<p style="font-size:20pt;color:SteelBlue">this text has inline style
<em>font-size</em><em> color</em> applied to it.</p>
<p>These have embedded styles applied</p>
<div class="thin red solid">thin red Solid Border</div>
<hr>
<div class="medium blue outset ">medium blue outset Border</div>
<p>These have external styles applied</p>
<div class="section">
<div class="floated"> External StyleSheets</div>
A style sheet is linked using link element that uses rel attribute="stylesheet"
means the linked document is a stylesheet for this document.
</div>
</body>
</html>
E.css:
div.floated { background-color:#eeeeee;
font-size:1.5em;
font-family:arial;
margin-bottom:.5em;
float:right;
text-align:center;
width:50%;
}
div.section {
border: 1px solid #bbddff
}
RESULT: Hence the design of web application using different types of CSS has been successfully
executed
6. AIM: To write a program in Java Script for displaying the current date in the following format. FRIDAY,
3-May-2013
PROGRAM:
<html>
<head>
<script type="text/javascript">
var current = new Date();
var d=["SUNDAY","MONDAY","TUESDAY","WEDNESDAY",
"THURSDAY","FRIDAY","SATURDAY"];
var m=["January","February","March","April","May","June","July","August",
"September","October","November","December"];
document.writeln("<h1>Today's date is</h1>");
document.writeln(d[current.getDay()]);
document.write(","+current.getDate());
document.write("-"+m[current.getMonth()]);
document.write("-"+current.getYear());
</script>
</head>
<body>
</body>
</html>
RESULT: Hence the program that displays the current date in the following format FRIDAY, 3-May-2013
has been successfully executed.
OUTPUT:
7. AIM: To write a Java Script program that uses onMouseOver and onMouseOut events
PROGRAM:
<html>
<head>
<script>
function bigImg(x)
{
x.style.height="256px";
x.style.width="256px";
}
function normalImg(x)
{
x.style.height="64px";
x.style.width="64px";
}
</script>
</head>
<body>
<img onMouseOver="bigImg(this)" onMouseOut="normalImg(this)" border="0"
src="p.jpg" alt="Flower" width="32" height="32">
</body>
</html>
RESULT: Hence the Java Script program that uses onMouseOver and onMouseOut events has been
successfully executed.
9. AIM: To write an applet program that implements ItemListener
PROGRAM:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<applet code=" ItemListenerDemo " width=200 height=200>
</applet>
*/
public class ItemListenerDemo extends Applet implements ItemListener
{
Choice c;
public void init()
{
c = new Choice(); //create choice or combobox
c.add("red"); //add items to the choice
c.add("green");
c.add("blue");
c.add("pink");
add(c); //add choice or combobox
c.addItemListener(this); //add item listener
}
public void paint(Graphics g)
{
// To get selected item, use String getSelectedItem() method of AWT Choice class.
g.drawString(c.getSelectedItem(),10, 70);
}
public void itemStateChanged(ItemEvent e)
{
repaint();
}
}
RESULT: Hence the applet program that implements ItemListener has been successfully executed.
17. AIM: To design an GUI application using Swings that has a button that uses JColorChooser
to change the background of the application to the color choosen in JColorChooser.
PROGRAM:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class J extends JFrame implements ActionListener
{
private Container p;
public J()
{
super("JC");
p = getContentPane();
p.setBackground(Color.WHITE);
p.setLayout(new FlowLayout(FlowLayout.CENTER));
JButton btn = new JButton("Select background color");
btn.addActionListener(this);
p.add(btn);
this.setSize(300,100);
}
public void actionPerformed(ActionEvent ac)
{
Color b= JColorChooser.showDialog(this,"Select Color",this.getBackground());
if(b != null)
p.setBackground(b);
}
}
public class Ex
{
public static void main(String a[])
{
J cc = new J();
cc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cc.setVisible(true);
}
}
RESULT: Hence the GUI application using Swings has been successfully executed.
19. AIM: Write a simple Java program to display the details of a particular department from Access database.
PROGRAM:
import java.sql.*;
public class AccessDatabase
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:db1");
Statement st=con.createStatement();
ResultSet rs = st.executeQuery("select * from department where deptno='1'");
while (rs.next())
{
System.out.println("Deptno= " + rs.getString(1) + " Deptname= " +
rs.getString(2)+ " Location = " + rs.getString(3));
}
}
catch(Exception e)
{
System.out.println("this is");
System.out.println(e);
}
}
}
RESULT: Hence a simple Java program to display the details of a particular department has been
successfully executed.
21. AIM: To write a servlet program that creates a new user entry in the user table in database.
User entry is done through html form and a new user is created on clicking login button on form.html.
PROGRAM:
Form.html
<html>
<body>
<form method="post" action="http://localhost/3">
Login :      
<input type=text name="login">
<br>
Password : <input type=password name="password">
<br>
<input type=submit value="login">
<input type=reset value="clear">
</form>
</body>
</html>
22. SERVLET PROGRAM:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DBServlet extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
{
String login=req.getParameter("login");
String pwd=req.getParameter("password");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:db1");
PreparedStatement st=con.prepareStatement("insert into user values (?,?)");
st.setString(1,login);
st.setString(2,pwd);
int n = st.executeUpdate();
con.close();
res.setContentType("text/html");
PrintWriter out =res.getWriter();
out.println("<html><body><h1>");
if(n >0)
{
out.println("new user created");
}
else
{
out.println("new user not created");
}
out.println("</h1></body></html>");
out.close();
}
catch(Exception e)
{
System.out.println("this is");
System.out.println(e);
}
}
}
RESULT: Hence the servlet program has been successfully executed.
25. AIM: To write a JSP program that displays the data in the user table that exists in database.
PROGRAM:
<html>
<body>
<table border="1">
<%@ page import="javax.sql.*;" %>
<%
java.sql.Connection con=null;
java.sql.Statement s=null;
java.sql.ResultSet rs=null;
java.sql.ResultSetMetaData rsmd;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = java.sql.DriverManager.getConnection("jdbc:odbc:db1");
s = con.createStatement();
rs = s.executeQuery("select * from user");
rsmd=rs.getMetaData();
int count = rsmd.getColumnCount();
out.print("<tr>");
for (int i=1; i<=count; i++)
{
out.print("<th>");
out.print(rsmd.getColumnName(i));
}
out.println("</tr>");
%>
<%
while( rs.next() )
{
%>
<tr>
<td><center><%= rs.getString("Login") %></center></td>
<td><center><%= rs.getString("Password") %></center></td>
</tr>
<%
}
%>
<%
}
catch(Exception e)
e.printStackTrace();
%>
</table>
</body>
</html>
RESULT: Hence the JSP program that displays the data in the user table has been successfully executed.