Tybca Slips-25marks
Tybca Slips-25marks
Tybca Slips-25marks
Slip 1 : Write a JSP script to accept username, store it into the session, compare it with
password in another jsp file, if username matches with password then display appropriate
message in html file.
Slip1_checklogin.jsp
<%
%>
Slip1.jsp
<BODY>
<H1>LOGIN FORM</H1>
<%
if(myname!=null)
{
%>
</BODY>
</HTML>
Slip1_logout.jsp
<%
String username=(String)session.getAttribute("username");
if(username!=null)
{
out.println(username+" loged out, <a href=\"Slip1.jsp\">Back</a>");
session.removeAttribute("username");
}
else
{
out.println("You are already not login <a href=\"Slip1.jsp\">Back</a>");
}
%>
SLIP 2 :
Write a servlet which counts how many times a user has visited a web page. If the user is
visiting the page for the first time, display a welcome message. If the user is revisiting the
page, display the number of times visited. (Use cookies)
Slip3_2.java
import java.applet.*;
import java.awt.*;
Slip 4 : Write a JSP program to create a shopping mall. User must be allowed to do
purchase from two pages. Each page should have a page total. The third page should
display a bill, which consists of a page total of whatever the purchase has been done and
print the total.
Slip4_first.jsp
Rice :
<select name="rice">
<option value="2">2 Kg</option>
<option value="5">5 Kg</option>
<option value="10">10 Kg</option>
<option value="15">15 Kg</option>
</select>
Wheat :
<select name="wheat">
<option value="2">2 Kg</option>
<option value="5">5 Kg</option>
<option value="10">10 Kg</option>
<option value="15">15 Kg</option>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>
Slip4_Second.jsp
<%
String rice = request.getParameter("rice");
int r = Integer.parseInt(rice);
session.setAttribute("first_Total", pt);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Shopping Mall</h1>
<form action="Slip4_Third.jsp" method="post">
Maggi :
<select name="maggi">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
Good Day :
<select name="good">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
Slip4_Third.jsp
<%
String m = request.getParameter("maggi");
String g = request.getParameter("good");
int mp = Integer.parseInt(m);
int gp = Integer.parseInt(g);
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Shopping Mall</h1>
</body>
</html>
Slip 5 : Write a MultiThreading program in java using Runnable interface to draw temple flag
on an applet container.
Slip5_2.java
import java.awt.*;
import java.applet.*;
}
run();
}
public void paint(Graphics g)
{
if(ln==1&&x1>100)
{
g.drawLine(100,200,100,x1-=5);
}
if(ln==2&&x2<150)
{
g.drawLine(100,200,100,100);
g.drawLine(100,100,x2+=5,100);
}
if(ln==3&&x3>125&&y3<125)
{
g.drawLine(100,200,100,100);
g.drawLine(100,100,150,100);
g.drawLine(150,100,x3-=5,y3+=5);
}
if(ln==4&&x4<150&&y4<150)
{
g.drawLine(100,200,100,100);
g.drawLine(100,100,150,100);
Slip 6 : Write a socket program in java to check whether given file is present on server or
not, If it present then display its content on the server’s machine.
S_Slip6_2.java
import java.io.*;
import java.net.*;
class S_Slip6_2
{
public static void main(String a[]) throws Exception
{
ServerSocket ss = new ServerSocket(1000);
System.out.println("Server is waiting for client : ");
Socket s =ss.accept();
System.out.println("Client is connected");
DataInputStream dis=new DataInputStream(s.getInputStream());
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
C_Slip6_2.java
class C_Slip6_2
{
public static void main(String a[]) throws Exception
{
Socket s = new Socket("localhost",1000);
System.out.println("client is connected : ");
DataInputStream dis=new DataInputStream(s.getInputStream());
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
Slip7_2.java
import java.awt.*;
import java.util.*;
import java.applet.*;
//The basic applet class.The applet shows 4 cars crossing each other at a square.
class Slip7_2 extends Applet implements Runnable
{
Thread t;
//4 variables used to vary the car's positions.
int x1=0,x2=380,y1=50,y2=250;
public void start()
{
if(t==null)
{
t =new Thread(this,"New Thread");//New side Thread created on start
of applet.
t.start();
}
}
SLIP 8:
Write a SERVLET application to accept username and password, search them into
database,if found then display appropriate message on the browser otherwise display error
message.
HTML FILE:
<HTML>
<BODY>
<input type=SUBMIT>
</BODY>
</HTML>
JAVA FILE :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
response.setContentType(“text/html”);
String password=req.getParmeter(“password”);
Connection con=null;
Statement st=null;
ResultSet rs=null;
out.println(“<HTML>”);
out.println(“<BODY>”);
try
Class.forName(“org.postgresql.Driver”);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:dsn");
if(con==null)
else
st=con.createStatement();
if(rs==null)
else
out.println(“Welcome: ‘”+name+”’”);
catch(Exception e) { }
out.println(“</BODY>”);
out.println(“</HTML>”);
Slip 9_2.java
import java.awt.*;
import java.awt.event.*;
}
}
}
catch(Exception e)
{
System.out.println(e);
}
run();
}
public static void main(String args[])
{
new Slip9_2();
}
}
Slip 10_2.java
import java.awt.*;
Slip 12 :Write a JSP program to accept the details of Account (ANo, Type, Bal) and store it
into database and display it in tabular form. (Use PreparedStatement interface)
Slip12.html
<!-- To change this template, choose Tools | Templates and open the template in the editor.
-->
<!DOCTYPE html>
<html><body>
<form method=get action="Slip12.jsp">
Enter Account No. : <input type=text name=ano><br><br>
Enter Account Type:<input type=text name=type><br><br>
Enter Balance : <input type=text name=bal><br><br>
<input type=submit value="Save">
</form>
</body></html>
Slip12.jsp
<html><body>
<%@ page import="java.sql.*;" %>
<%! int ano,bal;
String type; %>
<%
ano=Integer.parseInt(request.getParameter("ano"));
type=request.getParameter("type");
bal=Integer.parseInt(request.getParameter("bal"));
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:acnt","","");
PreparedStatement s=cn.prepareStatement("insert into Account values(?,?,?)");
s.setInt(1,ano);
s.setString(2,type);
s.setInt(3,bal);
s.executeUpdate();
out.println("Record is saved");
Statement st=cn.createStatement();
ResultSet rs=st.executeQuery("select * from Account");
%>
<table border="1" width="40%">
<% while(rs.next())
{
%>
<tr><td><%= rs.getInt("ano") %></td>
Slip 13 : Write a socket program in java for simple stand alone chatting application */
S_Slip13_2.java
import java.io.*;
import java.net.*;
class S_Slip13_2
{
public static void main(String a[]) throws Exception
{
ServerSocket ss = new ServerSocket(1000);
System.out.println("Server is waiting for client : ");
Socket s =ss.accept();
System.out.println("Client is connected");
DataInputStream ios=new DataInputStream(s.getInputStream());
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
C_Slip13_2.java
import java.io.*;
import java.net.*;
class C_Slip13_2
{
public static void main(String a[]) throws Exception
{
Socket s = new Socket("localhost",1000);
System.out.println("client is connected : ");
DataInputStream ios=new DataInputStream(s.getInputStream());
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
Slip 14_2 : Write a JDBC program in java to display details of Book_Sales(SalesID, Date,
Amount)
*of selected month in JTable. Book_sales table is already created. (Use JCombo
component for Month selection)
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
String head[]={"SalesID","Date","Amount"};
Slip14_2()
{
setLayout(null);
cb=new JComboBox();
cb.setBounds(350,20,100,20);
cb.addItem("JAN");
cb.addItem("FEB");
cb.addItem("MARCH");
cb.addItem("APRIL");
cb.addItem("MAY");
cb.addItem("JUN");
cb.addItem("JULY");
cb.addItem("AUG");
cb.addItem("SEP");
cb.addItem("OCT");
cb.addItem("NOV");
cb.addItem("DEC");
add(cb);
cb.addItemListener(this);
setSize(500,400);
setVisible(true);
}
public void itemStateChanged(ItemEvent ie)
{
String str=cb.getSelectedItem().toString();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:dsn");
Statement st=cn.createStatement();
ResultSet rs=st.executeQuery("select * from BookSales where Date like '"+str+"%'");
int i=0;
while(rs.next())
{
as[i][0]=rs.getString("SalesID");
as[i][1]=rs.getString("Date");
as[i][2]=rs.getString("Amount");
i++;
}
cn.close();
JTable jt=new JTable(as,head);
JScrollPane pane=new JScrollPane(jt);
pane.setBounds(0,0,300,400);
add(pane);
}catch(Exception e)
{
System.out.println(e);
}
Slip17.java
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
class Slip17 extends JFrame implements ActionListener
{
JLabel l1;
JButton b1,b2,b3;
JTextArea t1;
Connection con;
Statement stmt;
String str;
Slip17()
{
l1=new JLabel("Type DDL Query");
b1=new JButton("create table");
b2=new JButton("Alter table");
b3=new JButton("Drop table");
t1=new JTextArea(20,20);
add(l1);
add(b1);
add(b2);
add(b3);
add(t1);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
setVisible(true);
}
catch(Exception ex)
{
System.out.println(ex);
}
}
else if(b2==e.getSource())
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:dsn");
stmt=con.createStatement();
str=t1.getText();
int ans= stmt.executeUpdate(str);
if(ans==0)
JOptionPane.showMessageDialog(null,"Table Alter");
else
JOptionPane.showMessageDialog(null,"Table NOT
Alter");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
else if(b3==e.getSource())
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:dsn");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
Slip 18:
Design a servlet that provides information about a http request from client, such as IP
address and browser type. The servlet also provides information about the server on which
the servlet is running, such as the operating system type, and the names of currently loaded
servlet.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
response.setContentType(“text/html”);
out.println(“<HTML>”);
out.println(“<BODY>”);
out.println(“</BODY>”);
out.println(“</HTML>”);
Slip 19 : Write a multithreading program in java to convert smile face into the crying face
after 5 seconds.
Slip19_2.java
import java.awt.*;
import java.applet.*;
SLIP 20:
Chatting Application using AWT
Awtschat.java
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
String reply=(String)dis.readUTF();
l2.setText(reply);
msg=t1.getText();
dos.writeUTF(msg);
t1.setText("");
}
catch(Exception e){}
}
}
Awtcchat.java
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
String reply=(String)dis.readUTF();
l2.setText(reply);
}
catch(Exception e){}
}
}
SLIP 21:
/* Slip21_2 :*/
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<%
Cookie c1 = new Cookie("p", "Paintaing");
response.addCookie(c1);
/* Slip21 :*/
<%
%>
Slip 22 : Write a java program to create a student table with field’s rno, name and per.
Insert values in the table. Display all the details of the student on screen. (Use
PreparedStatement Interface)
Slip22_2.java
import java.sql.*;
import java.io.*;
ps.setInt(1,rno);
ps.setString(2,name);
ps.setInt(3,per);
int no=ps.executeUpdate();
if(no!=0)
System.out.println("Data inserted succesfully.....");
else
System.out.println("Data not inserted");
//display details
System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3));
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Slip 23_2 :
Write a Java Program to Read, Update and Delete any record from “Elements†table.
The table has following fields (Atomic_weight , Name (primary key), Chemical_symbol). The
input should be provided through Command Line Arguments along with the appropriate data.
The operations are: R : Read, U: Update, D: Delete.
The syntax for Read: R
The syntax for Delete: D name
import java.sql.*;
import java.io.*;
class Slip23_2
{
static BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
Connection con;
PreparedStatement ps;
Statement st;
ResultSet rs;
ps.setFloat(1,per);
ps.setInt(2,rno);
int n=ps.executeUpdate();
if(n>0)
System.out.println("Record Updated...");
}
}
}
Slip 24 : Write a java program to accept the details of college (CID, CName, Address, year)
and store it into database (Use Swing and PreparedStatement interface)
Slip24_2.java
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
JTable t;
JScrollPane js;
Statement stmt ;
ResultSet rs ;
ResultSetMetaData rsmd ;
int columns;
Slip24_2()
{
t1 = new JTextField(20);
t2 = new JTextField(20);
t3 = new JTextField(20);
t4 = new JTextField(20);
b1 = new JButton("Save");
b2 = new JButton("Clear");
b1.addActionListener(this);
b2.addActionListener(this);
p=new JPanel();
p1=new JPanel();
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(t3);
p.add(l4);
p.add(t4);
p.add(b1);
p.add(b2);
add(p);
setLayout(new GridLayout(2,1));
setSize(600,800);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
else
JOptionPane.showMessageDialog(null,"Record NOT
inserted ");
}//end of try
catch(Exception ex)
{
System.out.println(ex);
//ex.printStackTrace();
}
}//end of if
else
{
t1.setText(" ");
t2.setText(" ");
t3.setText(" ");
t4.setText(" ");
}
}//end of method
Slip 25 : Write a java program for implementation scrollable ResultSet. Consider Emp table
(eno, ename, sal)
- moveFirst
- moveNext
- movePrevious
Slip 25_2
import java.io.*;
import java.sql.*;
import java.util.*;
class Slip25_2
{
public static void main(String args[])
{
Connection conn= null;
Statement stmt = null;
ResultSet rs = null;
int ch;
Scanner s=new Scanner(System.in);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:dsn");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("select * from employee");
int count=0;
while(rs.next())
count++;
do
{ System.out.println("1 First \n2 last \n3 next \n4 prev \n0 Exit");
ch=s.nextInt();
switch(ch)
{
case 1: rs.first();
System.out.println("Roll :"+rs.getInt(1)+" Name
:"+rs.getString(2)); break;
case 2: rs.last();
System.out.println("Roll :"+rs.getInt(1)+" Name
:"+rs.getString(2)); break;
case 3 : rs.next();
if(rs.isAfterLast())
System.out.println("can't move
forword");
else
System.out.println("Roll :"+rs.getInt(1)+"
Name :"+rs.getString(2));
break;
case 4 : rs.previous();
}//switch
}while(ch!=0);
}//end of try
catch(Exception e)
{
System.out.println(e);
}
}//main
}//class
Slip 27 : Write program to create a window that has a textbox/label to show current time. The
time should be displayed in hh:mm:ss format. The thread should start displaying the time
when the user clicks the Start button and stop when the user clicks the Stop button.
Slip27_2.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
btnStart.addActionListener(this);
btnStop.addActionListener(this);
t = new MyThread(txtTime);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btnStart)
{
if(!t.isAlive()) t.start();
else t.resume();
}
if(ae.getSource()==btnStop)
{
t.suspend();
}
}
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.Vector;
JFrame f;
JComboBox cb;
JPanel p;
JLabel l,l1,l2,l3;
Slip28_2()
{
f = new JFrame("Employee Information");
p = new JPanel();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:dsn11");
stmt = conn.createStatement();
Vector v = new Vector();
cb = new JComboBox(v);
cb.addItemListener(this);
}
catch(Exception e)
{
p.add(l);
p.add(cb);
p.add(l1);
p.add(l2);
p.add(l3);
f.add(p);
f.setSize(400, 400);
f.setVisible(true);
}
try
{
rs1 = stmt.executeQuery("select * from employee where eno ="+emp_no);
if(rs1.next())
{
l1.setText("\nEmp No : "+rs1.getInt(1));
l2.setText("\nName : "+rs1.getString(2));
l3.setText("\nSalary : "+rs1.getInt(3));
}
}
catch(Exception ex)
{
System.out.println(ex);
}
}
Slip 29_2 : Write a menu driven java program for the following:
Insert
Update
Delete
Search
Display
Exit
Slip29_2.java
import java.sql.*;
import java.io.*;
class Slip29_2
{
static BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
Connection con;
PreparedStatement ps;
Statement st;
ResultSet rs;
Slip29_2() throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:dsn");
if(con==null)
{
System.out.println("Connection Failed....");
System.exit(1);
}
}
ps.setInt(1,rno);
ps.setString(2,name);
ps.setFloat(3,per);
int n=ps.executeUpdate();
if(n>0)
System.out.println("Record Inserted...");
}
ps.setFloat(1,per);
ps.setInt(2,rno);
int n=ps.executeUpdate();
if(n>0)
System.out.println("Record Updated...");
}
rs=ps.executeQuery();
if(rs.next())
{
System.out.println("Roll No :"+rs.getInt(1)
+"\nName :"+rs.getString(2)
+"\nPercentage :"+rs.getFloat(3));
}
else
System.out.println("Roll no not found...");
}
switch(ch)
{
case 1 :ob.insert();
break;
case 2 : ob.modify();
break;
case 3 : ob.delete();
break;
case 4 : ob.search();
break;
case 5 : ob.viewAll();
break;
case 0 : break;
}
}while(ch!=0);
}
}
Slip 30:
Write a servlet program to display the details of Product (ProdCode, PName, Price) on the
browser in tabular format. (Use database)
JAVA FILE:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Slip4 extends HttpServlet
{
}
}
catch(Exception e) { }
out.println(“</BODY>”);
out.println(“</HTML>”);
}
}