0% found this document useful (0 votes)
65 views47 pages

Practical No:-: Aim:-Write A Java Program Using Swing To Demonstrate Jpopupmenu

The document describes a Java program that demonstrates creation of a file, edit, and setting menu with submenus using JMenuBar. It creates a JFrame with a JMenuBar containing JMenu items for File, Edit, Setting and Games. The File menu contains New, Save, and Exit menu items. The Edit menu contains Copy and Paste. The Setting menu contains Change Password. The Games menu contains Game 1 and Game 2 menu items. It adds action listeners to the menu items and displays the selected menu item text on a JLabel.

Uploaded by

Geeky Spydy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views47 pages

Practical No:-: Aim:-Write A Java Program Using Swing To Demonstrate Jpopupmenu

The document describes a Java program that demonstrates creation of a file, edit, and setting menu with submenus using JMenuBar. It creates a JFrame with a JMenuBar containing JMenu items for File, Edit, Setting and Games. The File menu contains New, Save, and Exit menu items. The Edit menu contains Copy and Paste. The Setting menu contains Change Password. The Games menu contains Game 1 and Game 2 menu items. It adds action listeners to the menu items and displays the selected menu item text on a JLabel.

Uploaded by

Geeky Spydy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 47

Name : Sayali Pravin Patil

Roll no: 3828

PRACTICAL NO:-
Aim:- Write a java program using swing to demonstrate JPopupMenu.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Pop
{
JFrame f1;
JPopupMenu p1;
JMenuItem m1,m2,m3;
public Pop()
{
f1= new JFrame("Popup Example");
p1=new JPopupMenu();
m1=new JMenuItem("Copy");
m2=new JMenuItem("Cut");
m3=new JMenuItem("Paste");
p1.add(m1);
p1.addSeparator();
p1.add(m2);
p1.addSeparator();
p1.add(m3);
f1.setSize(400,400);
f1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if(e.getButton()==3)
{
p1.show(f1,e.getX(),e.getY());
}
}
});
f1.setVisible(true);
}
public static void main(String[]args)
{
new Pop();
}
}
Name : Sayali Pravin Patil
Roll no: 3828

OUTPUT:-
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-
Aim:- Write a java program using swing to demonstrate JTree.
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
public class Tre implements TreeSelectionListener
{
JFrame f1;
JLabel l1;
JTree t1;
DefaultMutableTreeNode p,b,c,f,s,t,fy,sy,ty;
public Tre()
{
f1= new JFrame("PILLAI COLLAGE");
l1=new JLabel();
p=new DefaultMutableTreeNode("PCASC");
b=new DefaultMutableTreeNode("Bsc.IT");
c=new DefaultMutableTreeNode("CS");
f=new DefaultMutableTreeNode("FY-IT");
s=new DefaultMutableTreeNode("SY-IT");
t=new DefaultMutableTreeNode("TY-IT");
fy=new DefaultMutableTreeNode("FY-CS");
sy=new DefaultMutableTreeNode("SY-CS");
ty=new DefaultMutableTreeNode("TY-CS");
p.add(b);
p.add(c);
b.add(f);
b.add(s);
b.add(t);
c.add(fy);
c.add(sy);
c.add(ty);
t1=new JTree(p);
f1.add(t1);
f1.add(l1);
f1.setSize(600,600);
f1.setVisible(true);
f1.setLayout(new FlowLayout());
t1.addTreeSelectionListener(this);
}
public void valueChanged(TreeSelectionEvent e)
Name : Sayali Pravin Patil
Roll no: 3828

{
l1.setText("Path"+t1.getSelectionPath());
}
public static void main(String[]args)
{
new Tre();
}

}
OUTPUT:-
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-
Aim:- Write a java program using swing to demonstrate JTable.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class emp_table
{
JFrame fr;
JScrollPane jsp;
JTable table;
Object[][] rows={{"1","abc","trainer","8000"},
{"2","riya","s/w developer","10000"},
{"3","xyz","Manager","40000"}
};
String[] cols={"empid","empname","designstion","salary"};

public emp_table()
{
fr=new JFrame("table example");
fr.setSize(1024,768);
table=new JTable(rows,cols);
jsp=new JScrollPane(table);
fr.add(jsp);
fr.setVisible(true);
}
public static void main(String[] args)
{
new emp_table();
}
}
Output:-
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-
Aim:- Write a java program using swing to demonstrate JColorChooser.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class democ implements ActionListener
{
JFrame f1;
JButton b;

public democ()
{
f1=new JFrame("JColorChooser");
b=new JButton ("Choose color");
f1.setSize(500,500);
f1.setVisible(true);
f1.add(b);
b.addActionListener(this);
f1.setLayout(new FlowLayout());
}

public void actionPerformed(ActionEvent e)


{
Color c=JColorChooser.showDialog(f1,"Please choose a color",Color.RED);
f1.getContentPane().setBackground(c);
}

public static void main(String[] args)


{
new democ();
}
}

Output:-
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-10
Aim:- Write a java program using swing to demonstrate JFileChooser.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class demof implements ActionListener
{
JFrame f1;
JButton b;
JLabel l1;
JFileChooser fc;

public demof()
{
f1=new JFrame("JFileChooser");
b=new JButton("Choose File");
l1=new JLabel();
fc=new JFileChooser();
f1.setSize(600,600);
f1.setVisible(true);
f1.setLayout(new FlowLayout());
f1.add(b);
f1.add(l1);
b.addActionListener(this);

}
public void actionPerformed(ActionEvent e)
{
int i=fc.showOpenDialog(f1);
if(i==0)
{
l1.setText(" "+fc.getSelectedFile());
}
}
public static void main(String[] args)
{
new demof();
}
}
Name : Sayali Pravin Patil
Roll no: 3828

Output:-
Name : Sayali Pravin Patil
Roll no: 3828

Servlet Calculator
calculator.html
<html>
<head>
<title>calculator </title>

</head>
<body>
<form name="f1" action="servlet1" method="POST">
<table>
<tr>
<td colspan="2"> enter first number </td>
<td colspan="2"><input type="text" name="t1"></td>
</tr>
<tr>
<td colspan="2">enter second number</td>
<td colspan="2"><input type="text" name="t2"></td>
</tr>

<tr>
<td><input type="submit" value="add" name="a"></td>
<td><input type="submit" value="sub" name="s"></td>
<td><input type="submit" value="mul" name="m"></td>
<td><input type="submit" value="div" name="d"></td>
</tr>
</table>
</form>
</body>
</html>

servlet1.java
import java.io.IOException;
import java.io.PrintWriter;
import static java.lang.System.out;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class servlet1 extends HttpServlet


Name : Sayali Pravin Patil
Roll no: 3828

{
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
int x,y,z=0;
try
{
x=Integer.parseInt(request.getParameter("t1"));
y=Integer.parseInt(request.getParameter("t2"));

if(request.getParameter("a")!=null)
{
z=x+y;
}
else if(request.getParameter("s")!=null)
{
z=x-y;
}
else if(request.getParameter("m")!=null)
{
z=x*y;
}
else if(request.getParameter("d")!=null)
{
z=x/y;
}

}
catch(Exception e)
{

}
try(PrintWriter out = response.getWriter())
{

out.println("<html><head><title> display result</title></head><body><h1>result=" +z+


"</h1></html>");

}
catch(Exception ae)
{
Name : Sayali Pravin Patil
Roll no: 3828

}
finally{
out.close();
}

OutPut:-

Addition:

Substraction:
Name : Sayali Pravin Patil
Roll no: 3828

Multiplication:

Division:
Name : Sayali Pravin Patil
Roll no: 3828

JMenuBar
Aim:- Write a java program using swing to demonstrate creation of a file, edit &
setting menu with appropriate submenu.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Menu implements ActionListener
{
JFrame f1;
JMenuBar mb;
JMenu f,ed,se,g;
JMenuItem n,s,ex,c,p,cp,g1,g2;
JLabel l1;
public Menu()
{

f1=new JFrame("Menubar example");


l1=new JLabel();
mb=new JMenuBar();
f=new JMenu("File");
ed=new JMenu("Edit");

se=new JMenu("Setting");
g=new JMenu("Games");

n=new JMenuItem("New");
s=new JMenuItem("Save");
ex=new JMenuItem("Exit");
c=new JMenuItem("Copy");
p=new JMenuItem("Paste");

cp=new JMenuItem("Change Password");


g1=new JMenuItem("Game 1");
Name : Sayali Pravin Patil
Roll no: 3828

g2=new JMenuItem("Game 2");

f1.setJMenuBar(mb);
mb.add(f);
mb.add(ed);

mb.add(se);

f.add(n);
f.addSeparator();
f.add(s);
f.addSeparator();
f.add(ex);

ed.add(c);
ed.addSeparator();
ed.add(p);

se.add(cp);
se.addSeparator();
se.add(g);

g.add(g1);
g.addSeparator();
g.add(g2);

f1.setSize(400,400);
f1.setVisible(true);
f1.add(l1);

n.addActionListener(this);
s.addActionListener(this);
ex.addActionListener(this);
c.addActionListener(this);
p.addActionListener(this);
cp.addActionListener(this);
g.addActionListener(this);
g1.addActionListener(this);
g2.addActionListener(this);
}

public void actionPerformed(ActionEvent e)


{
if(e.getSource()==n)
{
l1.setText("You are selected New");
}
Name : Sayali Pravin Patil
Roll no: 3828

else if(e.getSource()==s)
{
l1.setText("You are selected Save");
}

else if(e.getSource()==ex)
{
System.exit(0);
}

else if(e.getSource()==c)
{
l1.setText("You are selected Copy");
}

else if(e.getSource()==p)
{
l1.setText("You are selected Paste");
}

else if(e.getSource()==cp)
{
l1.setText("You are selected Change password");
}

else if(e.getSource()==g1)
{
l1.setText("You are selected Game 1");
}

else if(e.getSource()==g2)
{
l1.setText("You are selected Game 2");
}
}

public static void main(String[] args)


{
new Menu();
}
}
Name : Sayali Pravin Patil
Roll no: 3828

OUTPUT:-
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-
Aim:- Write a java program using swing to demonstrate JProgressBar.
import java.awt.*;
import javax.swing.*;

public class progress


{
JFrame f1;
JProgressBar pb;
int i=0,num=0;

public progress()
{
f1=new JFrame("JProgressBar");
pb=new JProgressBar(0,2000);

pb.setValue(0);

f1.setSize(600,600);
f1.setVisible(true);
f1.setLayout(new FlowLayout());
f1.add(pb);
}
public void iterate()
{
while(i<=2000)
{
pb.setValue(i);
i=i+20;
try
{
Thread.sleep(150);
}
catch(Exception e)
{

}
}
}

public static void main(String[] args)


{
progress m=new progress();

m.iterate();
Name : Sayali Pravin Patil
Roll no: 3828

}
}

Output:-
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-14
Aim:- Develop a simple Servlet Question Answer application to demonstrate use of
HttpServletRequest & HttpServletResponse interfaces.
Demo.html:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="Servlet2" method="POST">
Q.1 What is 2+2 ?<br/>
<input type="radio" name="q1" value="1"/>1<br/>
<input type="radio" name="q1" value="2"/>2<br/>
<input type="radio" name="q1" value="3"/>3<br/>
<input type="radio" name="q1" value="4"/>4<br/>
Q.2 Which of the following is not a vowel ?<br/>
<input type="radio" name="q2" value="a"/>a<br/>
<input type="radio" name="q2" value="i"/>i<br/>
<input type="radio" name="q2" value="e"/>e<br/>
<input type="radio" name="q2" value="c"/>c<br/>
Q.3 What of the following is a fruit ?<br/>
<input type="radio" name="q3" value="potato"/>Potato<br/>
<input type="radio" name="q3" value="onion"/>Onion<br/>
<input type="radio" name="q3" value="apple"/>Apple<br/>
<input type="radio" name="q3" value="pepper"/>Pepper<br/><br/>

<input type="Submit" value="Check">

</form>
</body>
</html>

Servlet2.java:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
Name : Sayali Pravin Patil
Roll no: 3828

import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = {"/Servlet2"})
public class Servlet2 extends HttpServlet
{
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
int correct=0,incorrect=0;
String a1=request.getParameter("q1");
String a2=request.getParameter("q2");
String a3=request.getParameter("q3");

PrintWriter pw = response.getWriter();

if(a1.equals("4"))
{
correct++;
}
else
{
incorrect++;
}
if(a2.equals("c"))
{
correct++;
}
else
{
incorrect++;
}

if(a3.equals("apple"))
{
correct++;
}
else
{
incorrect++;
}

pw.println("Correct: "+correct);
pw.println("Incorrect: "+incorrect);
pw.close();
}
}
Name : Sayali Pravin Patil
Roll no: 3828

Output:-
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-
Aim:- Write a java program using Split Pane to demonstrate a screen divided in
two parts, one part contains the names of Planets & another displays the image of
the planet. When the user selects the planet from left screen, appropriate image of
planet displayed in right screen.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Planet_splitpane implements ActionListener


{
JFrame f;
Name : Sayali Pravin Patil
Roll no: 3828

JSplitPane sp;
JPanel p;
JButton b1,b2,b3,b4,b5,b6;
JLabel l;
ImageIcon i1,i2,i3,i4,i5,i6;

public Planet_splitpane()
{
f=new JFrame();
sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
p=new JPanel();
l=new JLabel();

b1=new JButton("EARTH");
b2=new JButton("MERCURY");
b3=new JButton("VENUS");
b4=new JButton("MARS");
b5=new JButton("SATURN");
b6=new JButton("NEPTUNE");

i1=new ImageIcon("F:\\Advanced Java\\planets\\earth.jpg");


i2=new ImageIcon("F:\\Advanced Java\\planets\\mercury.jpg");
i3=new ImageIcon("F:\\Advanced Java\\planets\\venus.jpg");
i4=new ImageIcon("F:\\Advanced Java\\planets\\mars.jpg");
i5=new ImageIcon("F:\\Advanced Java\\planets\\saturn.jpg");
i6=new ImageIcon("F:\\Advanced Java\\planets\\neptune.jpg");

p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(b5);
p.add(b6);

sp.setLeftComponent(p);
sp.setRightComponent(l);
Name : Sayali Pravin Patil
Roll no: 3828

f.add(sp);
f.setSize(400,400);
f.setVisible(true);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);

} //constructor Planet_splitpane() closed

public void actionPerformed(ActionEvent e)


{
if(e.getSource()==b1)
{
l.setIcon(i1);
}

else if(e.getSource()==b2)
{
l.setIcon(i2);
}

else if(e.getSource()==b3)
{
l.setIcon(i3);
}

else if(e.getSource()==b4)
{
l.setIcon(i4);
}

else if(e.getSource()==b5)
{
Name : Sayali Pravin Patil
Roll no: 3828

l.setIcon(i5);
}

else if(e.getSource()==b6)
{
l.setIcon(i6);
}

} //function actionPerformed() closed

public static void main(String[] args)


{
new Planet_splitpane();
} //main() closed
} //class Planet_splitpane closed

Output:
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-11
Aim:- Write a java program using swing to demonstrate JTabbedPane.
import java.awt.*;
import javax.swing.*;
public class demo29
{
JFrame f;
JPanel p1,p2,p3;
JLabel l1,l2,l3;
JTabbedPane tb;

public demo29()
{
f=new JFrame();
tb=new JTabbedPane();

l1=new JLabel("WELCOME FYIT");


l2=new JLabel("WELCOME SYIT");
l3=new JLabel("WELCOME TYIT");
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
Name : Sayali Pravin Patil
Roll no: 3828

p1.add(l1);
p2.add(l2);
p3.add(l3);

tb.add("FYIT",p1);
tb.add("SYIT",p2);
tb.add("TYIT",p3);

f.add(tb);
f.setSize(400,400);
f.setVisible(true);
f.setLayout(null);
}

public static void main(String[] ar)


{
new demo29();
}
}

Output:-
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-
Aim:- Develop a JSP application to accept Registration Details from user and store
it into database table.

<html>
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="background:pink">

<form action="newjsp.jsp" method="POST">


<center>
<h1 style="font-family:Times new Roman,color:white,font-size:30px,text-align:center">
REGISTRATION FORM </h1></center>
<table align="center">
<tr>
<td> FIRST_NAME:</td>
<td> <input type="text" name="t1" size="35">
</td>
</tr>
<tr>
<td> LAST_NAME:</td>
<td> <input type="text" name="t2" size="35">
</td>
</tr>
<td> USER_NAME:</td>
<td> <input type="text" name="t3" size="35">
</td>
</tr>
<tr>
<td> PASSWORD:</td>
<td> <input type="text" name="t4" size="35">
</td>
</tr>
<tr>
<td> ZIP_CODE:</td>
<td> <input type="text" name="t5" size="35">
</td>
</tr>
<tr>
<td> CITY:</td>
<td> <input type="text" name="t6" size="35">
</td>
</tr>
Name : Sayali Pravin Patil
Roll no: 3828

<tr>
<td> COUNTRY:</td>
<td> <input type="text" name="t7" size="35">
</td>
</tr>
<tr>
<center>
<td> <input type="submit" value="SUBMIT" name="s">
</td>
</center>
</tr>
</table>

</form>
</body>
</html>

<%--
Document : newjsp.jsp
Created on : Sep 22, 2017, 8:35:04 AM
Author : student
--%>

<%@page import="java.sql.*;"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<%
String first_name = request.getParameter("t1");
String last_name = request.getParameter("t2");
String user_name = request.getParameter("t3");
String password = request.getParameter("t4");
String zip_code = request.getParameter("t5");
String city = request.getParameter("t6");
String country = request.getParameter("t7");

try
Name : Sayali Pravin Patil
Roll no: 3828

{
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/tyit","root","mes");
PreparedStatement ps = c.prepareStatement("insert into register values(?,?,?,?,?,?,?)");
ps.setString(1,first_name);
ps.setString(2,last_name);
ps.setString(3,user_name);
ps.setString(4,password);
ps.setString(5,zip_code);
ps.setString(6,city);
ps.setString(7,country);
ps.executeUpdate();
out.println("Records are inserted.");
}

catch(Exception e)
{
out.println(e.toString());
}
%>
}

</body>
</html>
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-15
Aim:- Develop a simple JSP application to check whether user is valid or invalid.

Login.html:
<html>
<head>
<title>Login Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="logincheck.jsp" method="POST">
Username:<input type="text" name="user">
Password:<input type="Password" name="pass">
<input type="Submit" value="Submit" name="s">
</form>
</body>
</html>

Logincheck.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String un=request.getParameter("user");
String ps=request.getParameter("pass");

if(un.equals("SHUBHAM")&& ps.equals("ROOT"))
{
session.setAttribute("Username",un);
response.sendRedirect("home.jsp");
}
else
{
response.sendRedirect("error.jsp");
}
%>
</body>
</html>
Name : Sayali Pravin Patil
Roll no: 3828

Home.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String s=session.getAttribute("Username").toString();
out.println("Login Successful "+ s);
%>
</body>
</html>

Error.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
out.println("Incorrect usernamr or passwor");
%>
</body>
</html>
Output:-
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828

PRACTICAL NO:-17
Aim:- Develop a JSP application to authenticate user login as per the registration
details. If login success the forward user to index page otherwise show login failure
message.
Index.html:
<html>
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form name="f1" action="login.jsp" method="POST">
<table border="2">
<tr>
<td colspan="1">Enter Username:</td>
<td><input type="text" name="t1"></td>
</tr>
<tr>
<td colspan="1">Enter Password:</td>
<td><input type="text" name="t2"></td>
</tr>
<tr>
<td><input type="Submit" value="login" name="I"></td>
<td><input type="Submit" value="Cancel" name="C"></td>
</tr>
</table>
</form>
</body>
</html>

Login.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
Name : Sayali Pravin Patil
Roll no: 3828

</head>
<body>
<%@page import="java.sql.*;"%>

<%
Statement stmt;ResultSet rs;
int x=0;

String u=request.getParameter("t1");
String p=request.getParameter("t2");

Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/DB1","root","mcst");
stmt=c.createStatement();

if(request.getParameter("I")!=null)
{
rs=stmt.executeQuery("select * from stud where username='"+u+"' and password='"+p+"'");

if(rs.next())
{
x=1;
}

if(x==1)
{
out.println("<html><body>Login Successfull</body></html>");
}
else
{
out.println("<html><body>Login Unsuccessfull</body></html>");
}
}
%>
</body>
</html>

Output:-
Name : Sayali Pravin Patil
Roll no: 3828
Name : Sayali Pravin Patil
Roll no: 3828

You might also like