LAB MANUAL
Subject: Advanced Java Programming
Class: TE E&TC Semester – 2
(Academic Year: 2021-22)
Prepared By:
Mr. Shrikrishna U. Kolhar
Assistant Professor
Department of Electronics and Telecommunication Engineering.
Vidya Pratishthan’s
Kamalnayan Bajaj Institute of Engineering and Technology,
Baramati
List of Experiments
1 Write a program to demonstrate status of key on an Applet window such as
KeyPressed, KeyReleased, KeyUp, KeyDown.
2 Write a program to create a frame using AWT. Implement mouseClicked,
mouseEntered() and mouseExited() events. Frame should become visible when
the mouse enters it.
3 Develop a GUI which accepts the information regarding the marks for all the
subjects of a student in the examination. Display the result for a student in a
separate window.
4 Write a program to insert and retrieve the data from the database using JDBC.
5 Develop an RMI application which accepts a string or a number and checks that
string or number is palindrome or not.
6 Write a program to demonstrate the use of InetAddress class and its factory
methods.
7 Write program with suitable example to develop your remote interface, implement
your RMI server, implement application that create your server, also develop
security policy file.
8 Write a database application that uses any JDBC driver.
9 Create a simple calculator application using servlet.
10 Create a registration servlet in Java using JDBC. Accept the details such as
Username, Password, Email, and Country from the user using HTML Form and
store the registration details in the database
Program No: 1
Program Statement: Write a program to demonstrate status of key on an Applet window such
as KeyPressed, KeyReleased, KeyUp, KeyDown.
Theory: Write in 4-5 lines
What is Applet in Java?
What is event handling? Write an example
Program:
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code="SimpleKey" width=300 height=100>
</applet>
*/
public class SimpleKey extends Applet implements KeyListener
{
String msg = "";
int X = 10, Y = 20; // output coordinates
public void init()
{
addKeyListener(this);
}
public void keyPressed(KeyEvent k)
{
showStatus("Key Down");
int key = [Link]();
switch(key)
{
case KeyEvent.VK_F1:
msg = msg + "F1";
break;
case KeyEvent.VK_F2:
msg = msg + "F2";
break;
case KeyEvent.VK_F3:
msg = msg + "F3";
break;
case KeyEvent.VK_F4:
msg = msg + "F4 ";
break;
case KeyEvent.VK_RIGHT:
msg = msg + "RIGHT ";
break;
case KeyEvent.VK_LEFT:
msg = msg + "LEFT ";
break;
case KeyEvent.VK_UP:
msg = msg + "UP ";
break;
case KeyEvent.VK_DOWN:
msg = msg + "DOWN ";
break;
}
repaint();
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up");
}
public void keyTyped(KeyEvent ke)
{
msg += [Link]();
repaint();
}
// Display keystrokes.
public void paint(Graphics g)
{
[Link](msg, X, Y);
}
}
Post-lab questions:
1. Identify the name of listener interface used in above program
2. Which command is used for registering listener in the above program?
3. Identify the name of event class
4. Name the methods used for handling event in above program
Program No: 2
Program Statement: Write a program to create a frame using AWT. Implement
mouseClicked, mouseEntered() and mouseExited() events. Frame should become visible
when the mouse enters it.
Theory: Write in 4-5 lines
What is GUI in Java?
Explain use of Frame class with its constructors.
Program:
/**** Mouse_Exp2.java ****/
// Program we want to check events like Mouse click, mouse entered and
mouse exited
import [Link].*;
import [Link].*;
public class Mouse_Exp2 extends Frame implements MouseListener {
Label l;
Mouse_Exp2() {
super("AWT Frame");
l = new Label();
[Link](25, 60, 250, 30);
[Link]([Link]);
[Link](l);
[Link](300, 300);
[Link](null);
[Link](true);
[Link](this);
[Link](new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
public static void main(String[] args) {
new Mouse_Exp2();
}
@Override
public void mouseClicked(MouseEvent e) {
[Link]("Mouse Clicked");
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
[Link]("Mouse Entered");
}
@Override
public void mouseExited(MouseEvent e) {
[Link]("Mouse Exited");
}
}
Post-lab questions:
1. How to identify that above program is a GUI program?
2. Identify the name of listener interface used in above program
3. Which command is used for registering listener in the above program?
4. Identify the name of event class
5. Name the methods used for handling event in above program
Program No: 3
Program Statement: Develop a GUI which accepts the information regarding the marks for
all the subjects of a student in the examination. Display the result for a student in a separate
window.
Theory:
If you want to accept marks for 3 subjects of a student and after clicking on submit a
new window will pop-up to display overall result
Which component classes are required for creating above GUI?
Draw GUI here.
Program:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class ReportCard extends JFrame{
JPanel jp = new JPanel();
JLabel lname = new JLabel();
JButton bsubmit = new JButton("Submit");
JTextField tname = new JTextField(20);
JLabel lMath = new JLabel();
JTextField tMath = new JTextField(20);
JLabel lScience = new JLabel();
JTextField tScience = new JTextField(20);
JLabel lEnglish = new JLabel();
JTextField tEnglish = new JTextField(20);
public ReportCard()
{
[Link]("Enter Name");
[Link](lname);
[Link](tname);
[Link]("Enter Math Marks");
[Link](lMath);
[Link](tMath);
[Link]("Enter Science Marks");
[Link](lScience);
[Link](tScience);
[Link]("Enter English Marks");
[Link](lEnglish);
[Link](tEnglish);
[Link](bsubmit);
add(jp);
[Link](new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
String val = [Link]();
JLabel l1 = new JLabel("Welcome "+val);
int sub1 = [Link]([Link]());
int sub2 = [Link]([Link]());
int sub3 = [Link]([Link]());
int sum = sub1+sub2+sub3;
float average = sum/3;
JLabel l2 = new JLabel("Average "+ average);
JPanel jip = new JPanel();
[Link](l1);
[Link](l2);
JFrame inf = new JFrame();
[Link](true);
[Link](jip);
[Link](300, 100);
}
});
public static void main(String[] args) {
ReportCard rc = new ReportCard();
[Link](300, 200);
[Link](true);
}
}
Post-lab Questions:
1. Identify component classes used in above program.
2. Which event and listener used in the program?
3. What is the use of [Link]() method?
Program No: 4
Program Statement: Write a program to insert and retrieve the data from the database using
JDBC.
Theory:
What is JDBC and what is the use of it? ([Link]
Write 5 steps for JDBC connectivity ([Link]
database-in-java)
VLAB Link: [Link]
dev/vlab_bootcamp/bootcamp/bots_with_dots/labs/exp1/[Link]
Program:
1. Program to display the contents of the table
import [Link].*;
// User class
public class SQLStatementSelect{
public static void main(String args[]){
try{
[Link]("[Link]"); // register the driver class
Connection con=[Link](
"jdbc:mysql://localhost:3306/xyz?characterEncoding=latin1","root","root");
Statement stmt=[Link]();
ResultSet rs=[Link]("select * from pqr");
while([Link]())
//[Link]("Success");
[Link]([Link](1)+" "+[Link](2)+"
"+[Link](3));
[Link]();
}catch(Exception e){
[Link](e);}
}
}
2. Program to insert new record into the table
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class SQLPreparedStatementInsert{
public static void main(String[] args) {
try{
[Link]("[Link]");
Connection con=[Link](
"jdbc:mysql://localhost:3306/xyz?characterEncoding=latin1","root","root");
PreparedStatement stmt = [Link]("insert into pqr
values (?,?,?)");
[Link](1,"user3");
[Link](2,"pqr@[Link]");
[Link](3,"Baramati");
//[Link](4, "India");
//[Link](4,"India");
int i = [Link]();
[Link](i + "Records inserted..");
[Link]();
}
catch(Exception e){
[Link](e);
}
3. Program to delete record from the table
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class SQLPreparedStatementDelete{
public static void main(String[] args) {
try{
[Link]("[Link]");
Connection con=[Link](
"jdbc:mysql://localhost:3306/xyz?characterEncoding=latin1","root","root");
PreparedStatement stmt = [Link]("delete from pqr
where city=?");
[Link](1,"Baramati");
int i = [Link]();
[Link](i + "Records deleted");
[Link]();
}
catch(Exception e){
[Link](e);
}
4. Program to update any field of the record
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class SQLPreparedStatementUpdate{
public static void main(String[] args) {
try{
[Link]("[Link]");
Connection con=[Link](
"jdbc:mysql://localhost:3306/xyz?characterEncoding=latin1","root","root");
PreparedStatement stmt = [Link]("update pqr set
email=? where name=?");
[Link](1,"user1@[Link]");
[Link](2,"Ganesh");
int i = [Link]();
[Link](i + "Records updated");
[Link]();
}
catch(Exception e){
[Link](e);
}
}
Post-lab Questions:
1. List the SQL queries for 1) displaying all the data from the table 2) inserting new record
3) deleting particular record 4) updating any field of the record
2. List and explain the commands for JDBC connectivity steps
Program No: 5
Program Statement: Develop an RMI application which accepts a string or a number and
checks that string or number is palindrome or not.
Theory:
What is RMI? Architecture of RMI application, Working of RMI application, RMI registry,
[Link]
list steps for RMI application development
Program:
1. Following is an example of a remote interface. Here we have defined an interface
with the name Hello and it has a method called printMsg().
import [Link];
import [Link];
// Creating Remote interface for our application
public interface Hello extends Remote {
void printMsg() throws RemoteException;
}
2. Following is an implementation class. Here, we have created a class named
ImplExample and implemented the interface Hello created in the previous step
and provided body for this method which prints a message.
// Implementing the remote interface
public class ImplExample implements Hello {
// Implementing the interface method
public void printMsg() {
[Link]("This is an example RMI program");
}
}
3. Following is an example of an RMI server program.
import [Link];
import [Link];
import [Link];
import [Link];
public class Server extends ImplExample {
public Server() {}
public static void main(String args[]) {
try {
// Instantiating the implementation class
ImplExample obj = new ImplExample();
// Exporting the object of implementation class
// (here we are exporting the remote object to the stub)
Hello stub = (Hello) [Link](obj, 0);
// Binding the remote object (stub) in the registry
Registry registry = [Link]();
[Link]("Hello", stub);
[Link]("Server ready");
} catch (Exception e) {
[Link]("Server exception: " + [Link]());
[Link]();
}
}
}
4. Following is an example of an RMI client program.
import [Link];
import [Link];
public class Client {
private Client() {}
public static void main(String[] args) {
try {
// Getting the registry
Registry registry = [Link](null);
// Looking up the registry for the remote object
Hello stub = (Hello) [Link]("Hello");
// Calling the remote method using the obtained object
[Link]();
// [Link]("Remote method invoked");
} catch (Exception e) {
[Link]("Client exception: " + [Link]());
[Link]();
}
}
}
Post-lab Questions:
1. List steps to write RMI program
([Link]
2. Write example code for creating remote interface
Program No: 6
Program Statement: Write a program to demonstrate the use of InetAddress class and its
factory methods.
Theory:
Write use of InetAddress class, two versions of IP address and TCP/IP communication
protocol.
[Link]
Program:
import [Link].*;
import [Link].*;
public class InetDemo{
public static void main(String[] args){
try{
InetAddress ip=[Link]("[Link]");
[Link]("Host Name: "+[Link]());
[Link]("IP Address: "+[Link]());
}catch(Exception e){[Link](e);}
}
}
import [Link].Inet4Address;
import [Link];
import [Link];
public class InetDemo2
{
public static void main(String[] arg) throws Exception
{
InetAddress ip = [Link]("[Link]");
InetAddress ip1[] = [Link]("[Link]");
byte addr[]={72, 3, 2, 12};
[Link]("ip : "+ip);
[Link]("\nip1 : "+ip1);
InetAddress ip2 = [Link](addr);
[Link]("\nip2 : "+ip2);
[Link]("\nAddress : " +[Link]([Link]()));
[Link]("\nHost Address : " +[Link]());
[Link]("\nisAnyLocalAddress : " +[Link]());
[Link]("\nisLinkLocalAddress : " +[Link]());
[Link]("\nisLoopbackAddress : " +[Link]());
[Link]("\nisMCGlobal : " +[Link]());
[Link]("\nisMCLinkLocal : " +[Link]());
[Link]("\nisMCNodeLocal : " +[Link]());
[Link]("\nisMCOrgLocal : " +[Link]());
[Link]("\nisMCSiteLocal : " +[Link]());
[Link]("\nisMulticastAddress : " +[Link]());
[Link]("\nisSiteLocalAddress : " +[Link]());
[Link]("\nhashCode : " +[Link]());
[Link]("\n Is ip1 == ip2 : " +[Link](ip2));
}
}
Post-lab Questions:
List factory methods and instance methods of InetAddress class. Write use of each one.
Program No: 7
Program Statement: Write program with suitable example to develop your remote interface,
implement your RMI server, implement application that create your server, also develop
security policy file.
Theory and Program:
1. In the previous chapter, we created a sample RMI application. In this chapter, we will
explain how to create an RMI application where a client invokes a method which
displays a GUI window (JavaFX).
2. Defining the Remote Interface
3. Here, we are defining a remote interface named Hello with a method named
animation() in it.
import [Link];
import [Link];
// Creating Remote interface for our application
public interface Hello extends Remote {
void animation() throws RemoteException;
}
4. Developing the Implementation Class
5. In the Implementation class (Remote Object) of this application, we are trying to
create a window which displays GUI content, using JavaFX.
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
// Implementing the remote interface
public class FxSample extends Application implements Hello {
@Override
public void start(Stage stage) {
// Drawing a Box
Box box = new Box();
// Setting the properties of the Box
[Link](150.0);
[Link](150.0);
[Link](100.0);
// Setting the position of the box
[Link](350);
[Link](150);
[Link](50);
// Setting the text
Text text = new Text(
"Type any letter to rotate the box, and click on the box to stop the rotation");
// Setting the font of the text
[Link]([Link](null, [Link], 15));
// Setting the color of the text
[Link]([Link]);
// Setting the position of the text
[Link](20);
[Link](50);
// Setting the material of the box
PhongMaterial material = new PhongMaterial();
[Link]([Link]);
// Setting the diffuse color material to box
[Link](material);
// Setting the rotation animation to the box
RotateTransition rotateTransition = new RotateTransition();
// Setting the duration for the transition
[Link]([Link](1000));
// Setting the node for the transition
[Link](box);
// Setting the axis of the rotation
[Link](Rotate.Y_AXIS);
// Setting the angle of the rotation
[Link](360);
// Setting the cycle count for the transition
[Link](50);
// Setting auto reverse value to false
[Link](false);
// Creating a text filed
TextField textField = new TextField();
// Setting the position of the text field
[Link](50);
[Link](100);
// Handling the key typed event
EventHandler<KeyEvent> eventHandlerTextField = new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
// Playing the animation
[Link]();
}
};
// Adding an event handler to the text feld
[Link](KeyEvent.KEY_TYPED, eventHandlerTextField);
// Handling the mouse clicked event(on box)
EventHandler<[Link]> eventHandlerBox =
new EventHandler<[Link]>() {
@Override
public void handle([Link] e) {
[Link]();
}
};
// Adding the event handler to the box
[Link]([Link].MOUSE_CLICKED,
eventHandlerBox);
// Creating a Group object
Group root = new Group(box, textField, text);
// Creating a scene object
Scene scene = new Scene(root, 600, 300);
// Setting camera
PerspectiveCamera camera = new PerspectiveCamera(false);
[Link](0);
[Link](0);
[Link](0);
[Link](camera);
// Setting title to the Stage
[Link]("Event Handlers Example");
// Adding scene to the stage
[Link](scene);
// Displaying the contents of the stage
[Link]();
}
// Implementing the interface method
public void animation() {
launch();
}
}
6. Server Program: An RMI server program should implement the remote interface or
extend the implementation class. Here, we should create a remote object and bind it
to the RMIregistry.
7. Following is the server program of this application. Here, we will extend the above
created class, create a remote object, and registered it to the RMI registry with the
bind name hello.
import [Link];
import [Link];
import [Link];
import [Link];
public class Server extends FxSample {
public Server() {}
public static void main(String args[]) {
try {
// Instantiating the implementation class
FxSample obj = new FxSample();
// Exporting the object of implementation class
// (here we are exporting the remote object to the stub)
Hello stub = (Hello) [Link](obj, 0);
// Binding the remote object (stub) in the registry
Registry registry = [Link]();
[Link]("Hello", stub);
[Link]("Server ready");
} catch (Exception e) {
[Link]("Server exception: " + [Link]());
[Link]();
}
}
}
8. Client Program: Following is the client program of this application. Here, we are
fetching the remote object and invoking its method named animation().
import [Link];
import [Link];
public class Client {
private Client() {}
public static void main(String[] args) {
try {
// Getting the registry
Registry registry = [Link](null);
// Looking up the registry for the remote object
Hello stub = (Hello) [Link]("Hello");
// Calling the remote method using the obtained object
[Link]();
[Link]("Remote method invoked");
} catch (Exception e) {
[Link]("Client exception: " + [Link]());
[Link]();
}
}
}
Post-lab questions:
1. List steps to run the program
Program No: 8
Program Statement: Write a database application that uses any JDBC driver.
Theory and Program:
1. We will take an example to see how a client program can retrieve the records of
a table in MySQL database residing on the server.
2. Assume we have a table named student_data in the database details as shown
below.
+----+--------+--------+------------+---------------------+
| ID | NAME | BRANCH | PERCENTAGE | EMAIL |
+----+--------+--------+------------+---------------------+
| 1 | Ram | IT | 85 | ram123@[Link] |
| 2 | Rahim | EEE | 95 | rahim123@[Link] |
| 3 | Robert | ECE | 90 | robert123@[Link] |
+----+--------+--------+------------+---------------------+
3. Assume the name of the user is myuser and its password is password.
4. Creating a Student Class: Create a Student class with setter and getter methods as shown
below.
public class Student implements [Link] {
private int id, percent;
private String name, branch, email;
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getBranch() {
return branch;
}
public int getPercent() {
return percent;
}
public String getEmail() {
return email;
}
public void setID(int id) {
[Link] = id;
}
public void setName(String name) {
[Link] = name;
}
public void setBranch(String branch) {
[Link] = branch;
}
public void setPercent(int percent) {
[Link] = percent;
}
public void setEmail(String email) {
[Link] = email;
}
}
5. Defining the Remote Interface: Define the remote interface. Here, we are defining a
remote interface named Hello with a method named getStudents () in it. This method
returns a list which contains the object of the class Student.
import [Link];
import [Link];
import [Link].*;
// Creating Remote interface for our application
public interface Hello extends Remote {
public List<Student> getStudents() throws Exception;
}
6. Developing the Implementation Class: Create a class and implement the above created
interface.
7. Here we are implementing the getStudents() method of the Remote interface. When you
invoke this method, it retrieves the records of a table named student_data. Sets these
values to the Student class using its setter methods, adds it to a list object and returns
that list.
import [Link].*;
import [Link].*;
// Implementing the remote interface
public class ImplExample implements Hello {
// Implementing the interface method
public List<Student> getStudents() throws Exception {
List<Student> list = new ArrayList<Student>();
// JDBC driver name and database URL
String JDBC_DRIVER = "[Link]";
String DB_URL = "jdbc:mysql://localhost:3306/details";
// Database credentials
String USER = "myuser";
String PASS = "password";
Connection conn = null;
Statement stmt = null;
//Register JDBC driver
[Link]("[Link]");
//Open a connection
[Link]("Connecting to a selected database...");
conn = [Link](DB_URL, USER, PASS);
[Link]("Connected database successfully...");
//Execute a query
[Link]("Creating statement...");
stmt = [Link]();
String sql = "SELECT * FROM student_data";
ResultSet rs = [Link](sql);
//Extract data from result set
while([Link]()) {
// Retrieve by column name
int id = [Link]("id");
String name = [Link]("name");
String branch = [Link]("branch");
int percent = [Link]("percentage");
String email = [Link]("email");
// Setting the values
Student student = new Student();
[Link](id);
[Link](name);
[Link](branch);
[Link](percent);
[Link](email);
[Link](student);
}
[Link]();
return list;
}
}
8. Server Program: An RMI server program should implement the remote interface or extend
the implementation class. Here, we should create a remote object and bind it to the RMI
registry.
9. Following is the server program of this application. Here, we will extend the above created
class, create a remote object and register it to the RMI registry with the bind name hello.
import [Link];
import [Link];
import [Link];
import [Link];
public class Server extends ImplExample {
public Server() {}
public static void main(String args[]) {
try {
// Instantiating the implementation class
ImplExample obj = new ImplExample();
// Exporting the object of implementation class (
here we are exporting the remote object to the stub)
Hello stub = (Hello) [Link](obj, 0);
// Binding the remote object (stub) in the registry
Registry registry = [Link]();
[Link]("Hello", stub);
[Link]("Server ready");
} catch (Exception e) {
[Link]("Server exception: " + [Link]());
[Link]();
}
}
}
10. Client Program: Following is the client program of this application. Here, we are fetching
the remote object and invoking the method named getStudents(). It retrieves the records
of the table from the list object and displays them.
import [Link];
import [Link];
import [Link].*;
public class Client {
private Client() {}
public static void main(String[] args)throws Exception {
try {
// Getting the registry
Registry registry = [Link](null);
// Looking up the registry for the remote object
Hello stub = (Hello) [Link]("Hello");
// Calling the remote method using the obtained object
List<Student> list = (List)[Link]();
for (Student s:list)v {
// [Link]("bc "+[Link]());
[Link]("ID: " + [Link]());
[Link]("name: " + [Link]());
[Link]("branch: " + [Link]());
[Link]("percent: " + [Link]());
[Link]("email: " + [Link]());
}
// [Link](list);
} catch (Exception e) {
[Link]("Client exception: " + [Link]());
[Link]();
}
}
}
Program No: 9
Program Statement: Create a simple calculator application using servlet.
Program:
[Link]
<html><head>
<title>Calculator App</title></head><body>
<form action="CalculatorServlet" >
Enter First Number <input type="text" name="txtN1"><br>
Enter Second Number <input type="text" name="txtN2" ><br>
Select an Operation<input type="radio" name="opr" value="+">
ADDTION <input type="radio" name="opr" value="-">
SUBSTRACTION <input type="radio" name="opr" value="*">
MULTIPLY <input type="radio" name="opr" value="/">
DIVIDE <br><input type="reset">
<input type="submit" value="Calculate" >
</form></body></html>
[Link]
packagemypack;
import [Link].*;
[Link].*;
[Link].*;
public class CalculatorServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throwsServletException, IOException {
[Link]("text/html;charset=UTF-8");
PrintWriter out = [Link]();
[Link]("<html><head><title>Servlet
CalculatorServlet</title></head><body>");
double n1 = [Link]([Link]("txtN1"));
double n2 = [Link]([Link]("txtN2"));
double result =0;
String opr=[Link]("opr");
if([Link]("+"))
result=n1+n2;
if([Link]("*"))
result=n1*n2;
[Link]("<h1> Result = "+result);
if([Link]("-"))
result=n1-n2;
if([Link]("/"))
result=n1/n2;
[Link]("</body></html>");
}}
Experiment No: 10
Program Statement: Create a registration servlet in Java using JDBC. Accept the details
such as Username, Password, Email, and Country from the user using HTML Form and store
the registration details in the database
Program:
[Link]
<html><head><title>Login Form</title></head>
<form action="LoginServlet" >
Enter User ID<input type="text" name="txtId"><br>
Enter Password<input type="password" name="txtPass"><br>
<input type="reset">
<input type="submit" value=" Click to Login "></form></html>
[Link]
packagemypack;
import [Link].*;
[Link];
[Link].*;
public class LoginServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throwsServletException, IOException
{
[Link]("text/html;charset=UTF-8");
PrintWriter out = [Link]();
[Link]("<html><head><title>Servlet LoginServlet</title></head>");
String uname = [Link]("txtId");
String upass = [Link]("txtPass");
if([Link]("admin") &&[Link]("12345"))
{
[Link]("<body bgcolor=blue >");
[Link]("<h1> Welcome !!! "+uname+"</h1>");
}
else
{
[Link]("<body bgcolor=red >");
[Link]("<h1> Login Fail !!! </h1>");