4th Sem JAVA Record 2009
4th Sem JAVA Record 2009
class Cons
{
int a,b;
Cons()
{
a=1;
b=1;
}
Cons(int i)
{
a=i;
b=i;
}
Cons(int x, int y)
{
a=x;
b=y;
}
void disp()
{
System.out.println("\n\n No arguments Passed ");
System.out.println("\n Value of a : " +a);
System.out.println("\n Value of b : " +b);
}
void disp(int m)
{
System.out.println("\n\n Arument Passed : " +m);
System.out.println("\n Value of a : " +a);
System.out.println("\n Value of b : " +b);
}
}
class P1a
{
public static void main(String args[])
{
Cons c1=new Cons();
Cons c2=new Cons(5);
Cons c3=new Cons(10,20);
c1.disp();
c2.disp(4);
c3.disp();
}
}
OUTPUT:
No arguments Passed
Value of a : 1
Value of b : 1
Arument Passed : 4
Value of a : 5
Value of b : 5
No arguments Passed
Value of a : 10
Value of b : 20
1b. JAVA Program to implement Inner class and demonstrate its Access Protections.
class Outer
{
int outer_x=100;
void test()
{
Inner i1=new Inner();
i1.display();
}
int y=10;
class Inner
{
// int y=5;
void display()
{
System.out.println("Display : outer_x = " +outer_x);
}
}
void showy()
{
System.out.println("Value of Y : " +y);
}
}
class P1b
{
public static void main(String args[])
{
Outer o=new Outer();
o.test();
}
}
OUTPUT:
class Sup
{
int i,j;
Sup(int a,int b)
{
i=a;
j=b;
}
void displayij()
{
System.out.println("\n Value of i : " +i);
System.out.println("\n Value of j : " +j);
}
}
class P2a
{
public static void main(String args[])
{
Sub sbob=new Sub(10,20,30);
Sup spob=new Sup(15,25);
System.out.println("\n Contents of Super Class Object : ");
spob.displayij();
System.out.println("\n Contents of Sub Class Object : ");
sbob.displayij();
sbob.displayk();
System.out.println("\n After adding Sub Class Object : " );
sbob.sum();
}
}
OUTPUT:
Value of i : 15
Value of j : 25
Value of i : 10
Value of j : 20
Value of k : 30
class P2b
{
public static void main(String args[])
{
try
{
int a=args.length;
int b=10/a;
System.out.println("Length : " +a);
try
{
if(a==1)
a=a/(a-a);
if(a==2)
{
int c[]={1};
c[2]=10;
}
try
{
int s;
if(a>2)
s=30/a;
}
finally
{
System.out.println("No Exception");
System.out.println(a+ " Command-line Arguments ");
}
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array Index Out-of-Bound : " +e);
}
}
catch(ArithmeticException e)
{
System.out.println("Divide by 0 : " +e);
}
}
}
OUTPUT:
C:\jdk1.3\>javac P2b.java
C:\jdk1.3\>java P2b
Divide by 0 : java.lang.ArithmeticException: / by zero
C:\jdk1.3\>java P2b a
Length : 1
Divide by 0 : java.lang.ArithmeticException: / by zero
C:\jdk1.3\>java P2b a b
Length : 2
Array Index Out-of-Bound : java.lang.ArrayIndexOutOfBoundsException
C:\jdk1.3\>java P2b a b c
Length : 3
No Exception
3 Command-line Arguments
C:\jdk1.3\>java P2b a b c d
Length : 4
No Exception
4 Command-line Arguments
interface Interf
{
void comput(int x, int y);
}
class P3a
{
public static void main(String args[])
{
Add a_obj=new Add();
Mul m_obj=new Mul();
Interf i;
i=a_obj;
i.comput(10,20);
i=m_obj;
i.comput(4,5);
}
}
OUTPUT:
Sum : 30
Product : 20
Press any key to continue . . .
3b. JAVA Program to create a class (extending Thread) and use methods Thread class to
change name, priority of the current Thread and display the same.
class P3b
{
public static void main(String args[])
{
Five f=new Five();
Seven s=new Seven();
Nine n=new Nine();
n.setName("My");
n.setPriority(10);
System.out.println("Thread " +n.getName()+ " has a priority of " +n.getPriority());
f.setPriority(1);
f.start();
s.start();
n.start();
}
}
OUTPUT:
import java.awt.*;
import java.applet.*;
/*
<applet code="P4a" width=400 height=200>
<param name=message value="BMS COLLEGE OF ENGINEERING">
</applet>
*/
catch(InterruptedException e) { }
}
}
OUTPUT:
4b. JAVA Program to pass parameters to Applets and display the same.
import java.awt.*;
import java.applet.*;
/*
<applet code="P4b" width=400 height=200>
<param name=fontName value=Courier>
<param name=fontSize value=14>
<param name=leading value=2>
<param name=accountEnabled value=true>
</applet>
*/
param=getParameter("accountEnabled");
if(param!=null)
active=Boolean.valueOf(param).booleanValue();
}
public void paint(Graphics g)
{
g.drawString("Font Name : " +fontName,100,40);
g.drawString("Font Size : " +fontSize,100,80);
g.drawString("Leading : " +leading,100,120);
g.drawString("Account Active : " +active,100,160);
}
}
OUTPUT:
5. Write a JAVA Program to insert data into Student DATA BASE and retrieve info base
on particular queries (Using JDBC Design Front end using Swings).
lab5.java
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
Inpscr()
{
setTitle("Data Base Connectivity");
setSize(300, 300);
toolkit = getToolkit();
Dimension size = toolkit.getScreenSize();
getContentPane().add(panel);
panel.setLayout(null);
else
{
JOptionPane.showMessageDialog(null,"Record Not Found");
return false;
}
}
catch(Exception ee)
{
System.out.println("Error" +ee);}
return true;
}
}
public void Display()
{
try {
String creat="select * from emp1";
smnt=con.createStatement();
rs = smnt.executeQuery(creat);
rs.next();
}
catch(Exception ee)
{System.out.println("Error" +ee);}
showRecord(rs) ;
}
public void showRecord(ResultSet rs)
{
String str;
try {
//text1.setText(Integer.toString(rs.getInt(1)));
text1.setText(rs.getString(1));
text2.setText(rs.getString(2));
text3.setText(rs.getString(3));
str=rs.getString(4);
text4.setText(str.substring(0,10));
text5.setText(rs.getString(5));
text6.setText(rs.getString(6));
text1.setEditable(false);
text2.setEditable(false);
text3.setEditable(false);
text4.setEditable(false);
text5.setEditable(false);
text6.setEditable(false);
}
catch(Exception ee) {}
}
public void setcomp()
{
next.setBounds(60, 240, 80, 20);
close.setBounds(150, 240, 80, 20);
panel.add(next);
next.addActionListener(this);
}
if(ee.getSource() == close) {
try {
setVisible(false);
smnt.close();
con.close();
}
catch(Exception e) {}
}
if(ee.getSource() == save) {
getval();
Setquery();
}
if(ee.getSource() == reset) {
Reset();
}
if(ee.getSource() == del) {
del_rec();
}
if(ee.getSource() == updat) {
getval();
Setupdat();
}
if(ee.getSource() == click) {
updat_rec();
}
}
public void updat_rec()
{
//String sid;
sid=text1.getText();
if(showspec())
{
text1.setEditable(true);
text2.setEditable(true);
text3.setEditable(true);
text4.setEditable(true);
text5.setEditable(true);
text6.setEditable(true);
setcomp4();
getval();
}
/*try {
del = "delete from emp1 where s_id="+id;
smnt1=con.createStatement();
rs1= smnt1.executeQuery(del);
}
catch(Exception ex)
{}*/
}
}
public void del_rec()
{
String del,ser;
id=text1.getText();
try {
del = "delete from emp1 where s_id="+id;
ser = "select * from emp1 where s_id="+id;
smnt1=con.createStatement();
rs1= smnt1.executeQuery(ser);
if((rs1.next()))
{
JOptionPane.showMessageDialog(null,"Record deleted");
smnt=con.createStatement();
rs = smnt.executeQuery(del);
}
else
{
JOptionPane.showMessageDialog(null,"Record Not Found");
}
}
catch(Exception ex) {}
}
public void Reset()
{
text1.setText("");
text2.setText("");
text3.setText("");
text4.setText("");
text5.setText("");
text6.setText("");
}
public void getval()
{
id=text1.getText();
nam=text2.getText();
ad=text3.getText();
db=text4.getText();
se=text5.getText();
ph=text6.getText();
System.out.println(nam);
System.out.println(se);
}
public void Setquery()
{
String creat;
try {
creat = "insert into emp1(s_id,name,adr,dob,sex,phone)" + "values(?,?,?,?,?,?)";
PreparedStatement ps = con.prepareStatement(creat);
ps.setString(1, id);
ps.setString(2, nam);
ps.setString(3, ad);
ps.setString(4, db);
ps.setString(5, se);
ps.setString(6, ph);
ps.executeUpdate();
}
catch(Exception ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
public void connect()
{
Connection con = getOracleJDBCConnection();
if(con!= null)
{
System.out.println("Got Connection.");
}
else
{
System.out.println("Could not Get Connection");
}
}
public static Connection getOracleJDBCConnection()
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e) { }
try {
con = DriverManager.getConnection(url);
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}
return con;
}
if(e.getSource() == insertrec) {
Inpscr i = new Inpscr();
i.setfields();
i.setcomp1();
i.connect();
i.setVisible(true);
}
if(e.getSource() == viewallinfo) {
Inpscr i1 = new Inpscr();
i1.setfields();
i1.setcomp();
i1.connect();
i1.setVisible(true);
i1.Display();
}
if(e.getSource() == viewinfo) {
Inpscr i2 = new Inpscr();
i2.setcomp2();
i2.connect();
i2.setVisible(true);
}
if(e.getSource() == delete ) {
Inpscr i3 = new Inpscr();
i3.setcomp3();
i3.connect();
i3.setVisible(true);
}
if(e.getSource() == modify) {
Inpscr i4 = new Inpscr();
i4.setcomp5();
i4.connect();
i4.setVisible(true);
}
}
}
public class lab5
{
OUTPUT:
Client.java
import java.io.*;
import java.net.*;
OutputStream out=cs.getOutputStream();
out.write(buf);
String str;
while((str=in.readLine())!=null)
{
System.out.println(str);
}
cs.close();
}
}
Server.java
import java.io.*;
import java.net.*;
InputStream in=cs.getInputStream();
in.read(buf);
while((line=fr.readLine())!=null)
{
out.println(line);
}
fr.close();
}
ss.close(); cs.close();
}
}
OUTPUT:
C:\>javac Server.java
C:\>javac Client.java
C:\>java Server
Server is running........
C:\>java Client
Enter the file name : color.html
<html>
<body>
<center>
<form name="form1" action="http://localhost:8090/servlet/Color">
<B>color:</B>
<input type=text name="color" />
<br><br>
<input type=submit value="submit">
</form>
</body>
</html>
7. Write a JAVA Program to implement a simple Client Server Application using RMI.
AddServerIntf.java
import java.rmi.*;
public interface AddServerIntf extends Remote
{
double add(double d1 , double d2) throws RemoteException ;
}
AddServerImpl.java
import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf
{
public AddServerImpl() throws RemoteException { }
public double add(double d1, double d2) throws RemoteException
{
return d1 + d2;
}
}
AddClient.java
import java.rmi.*;
public class AddClient
{
public static void main(String args[] )
{
try {
String serverURL = "rmi://" + args[0] + "/AddServer";
AddServerIntf addServerIntf=(AddServerIntf)Naming.lookup(serverURL);
AddServer.java
import java.net.*;
import java.rmi.*;
OUTPUT:
C:\>javac AddServerIntf.java
C:\>javac AddServerImpl.java
C:\>javac AddServer.java
C:\>javac AddClient.java
C:\>rmic AddServerImpl
C:\>start rmiregistry
C:\>java AddServer
First no. x : 5
Second no. y : 6
Result of d1 + d2 : 11.0
8. Write a JAVA Servlet Program to implement a dynamic HTML using Servlet (user
name and password should be accepted using HTML and displayed using a Servlet).
Lab8.html
<html>
<head>
<title>Lab8</title>
</head>
<body>
<h2> User details</h2>
<form method="post" action="http://localhost:8090/servlet/lab8" >
<hr />
<h3> Enter user name::</h3>
<input type="text" name="uname" /><br /><br />
<h3>Enter Password::</h3>
<input type="password" name="uadd" /><br /><br />
<input type="submit" value="Display" />
<input type="reset" value="Clear" />
</form>
</body>
</html>
lab8.java
import java.lang.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
OUTPUT:
Procedure to Excecute:
1. Compile lab8.java
2. Copy lab8.class file to C:\JSDK2.0\examples\
3. Run servletrunner with –p option and 8090 port number
4. Open lab8.html file
5. Enter user name and password and click Display
C:\>javac lab8.java
C:\>servletrunner -p 8090
servletrunner starting with settings:
port = 8090
backlog = 50
max handlers = 100
timeout = 5000
servlet dir = .\examples
document dir = .\examples
servlet propfile = .\examples\servlet.properties
C:\>servletrunner -p 8090
servletrunner starting with settings:
port = 8090
backlog = 50
max handlers = 100
timeout = 5000
servlet dir = .\examples
document dir = .\examples
servlet propfile = .\examples\servlet.properties
lab8: init
9. Write a JAVA Servlet Program to Download a file and display it on the screen (A link
has to be provided in HTML, when the link is clicked corresponding file has to be
displayed on Screen).
Download.html
<html>
<body bgcolor="ff99ff">
<center><br />
<form action="down">
<h2>FILE DOWNING </h2>
<h6>( Image and C source code )</h6>
<hr><br />
Image
<input type=hidden value="Ganesha.jpg" name="id">
<input type="submit" value="Download" /><br /><br />
</form>
<form action="down">
C Code for BFS search
<input type=hidden value="bfs.txt" name="id">
<input type="submit" value="Download" />
</form>
</center>
</body>
</html>
web.xml
<web-app>
<servlet>
<servlet-name>down</servlet-name>
<servlet-class>DownloadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>down</servlet-name>
<url-pattern>/down</url-pattern>
</servlet-mapping>
</web-app>
DownloadServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
OUTPUT:
10a. Write a JAVA Servlet Program to implement RequestDispatcher object (use include()
and forward() methods).
web.xml
<web-app>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>
login.jsp
<html>
<head><title>Login Page</title></head>
<body bgcolor="#aabbcc">
<center>
<h1>Login Page</h1>
<h2>Welcome to Java</h2>
<br><br><br><br>
<marquee><u>Enter Valid User ID and Password for login</u></marquee>
<h2>
<%
Object o=session.getAttribute("MSG");
if(o!=null)
{
String msg=o.toString();
out.println(msg);
}
%>
</h2>
<form action="login" method="post">
<table border="2">
<tr><td>User ID</td>
<td><input type="text" name="uname"/>
</td>
</tr>
<tr><td>Password</td>
<td><input type="password" name="pword"/>
</td>
</tr>
<tr><td colspan="2" align="center" >
<input type="submit" value="Login"/>
</td>
</tr></table></form></center>
</body>
</html>
LoginServlet.jsp
<html><head></head><body>
<%
<%@import java.io.*;%>
<%@import javax.servlet.*;%>
<%@import javax.servlet.http.*;%>
public class LoginServlet extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws
IOException,ServletException
{
String un = req.getParameter("uname");
String pw = req.getParameter("pword");
System.out.println("User id =" +un);
System.out.println("Password =" +pw);
RequestDispatcher rd = null;
HttpSession ses= req.getSession();
if(un.equals("java") && pw.equals("lab10a"))
{
ses.setAttribute("UN",un);
rd = req.getRequestDispatcher("/lab10a/register.jsp");
rd.forward(req,res);
}
else
{
String msg ="in valid user id and password";
ses.setAttribute("MSG",msg);
rd = req.getRequestDispatcher("/lab10a/login.jsp");
rd.include(req,res);
}
}
}
%>
</body>
</html>
register.jsp
<html>
<head><title>Login Page</title></head>
<body bgcolor="#aabbcc">
<center>
<h1>Login Page</h1>
<h2>Welcome to Java</h2>
<br><br><br><br>
<marquee><u>THIS IS doPost() METHOD EXAMPLE</u></marquee>
<br><br>
<h2>
<font color="red">
<%
Object o=session.getAttribute("UN");
if(o!=null)
{
String un=o.toString();
//out.println(un);
}
%>
<h1>WELCOME TO MY PROJECT--------</h1>
<br><br><br>
</font>
</h2>
</center>
</body>
</html>
LoginServlet.java
//package com;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res) throws
IOException,ServletException
{
String un = req.getParameter("uname");
String pw = req.getParameter("pword");
System.out.println("user id is=" +un);
System.out.println("user password is =" +pw);
RequestDispatcher rd = null;
HttpSession ses= req.getSession();
if(un.equals("java")&& pw.equals("lab10a"))
{
ses.setAttribute("UN",un);
rd = req.getRequestDispatcher("/register.jsp");
rd.forward(req,res);
}
else
{
String msg ="Invalid user id and password";
ses.setAttribute("MSG",msg);
rd = req.getRequestDispatcher("/login.jsp");
rd.include(req,res);
}
}
}
OUTPUT:
10b. Write a JAVA Servlet Program to implement and demonstrate Get() and Post()
methods(Using HTTP Servlet Class).
web.xml
<web-app>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>
login.jsp
<html>
<head>
</head>
<body bgcolor="#aabbcc">
<center>
<H1>Login Page</H1>
<H2><u>Welcome to Java</u></H2>
<br><br><br><br>
<marquee>This site is hundred persent safe</marquee>
<h2>
<font color="red">
<%
Object o = session.getAttribute("MSG");
if(o!=null)
{
String msg= o.toString();
out.println(msg);
}
%>
</font>
</h2>
<form action ="login" method="get">
<table border="2" >
<tr><td>User name</td>
<td><input type="text" name="uname"/>
</tr>
<tr><td>Password</td>
<td><input type="password" name="pword"/>
</tr>
<tr><td colspan="2" align="center">
<input type="submit" value="Login"/>
</td></tr></table>
</form></center>
</body></html>
register.jsp
<html>
<head>
</head>
<body bgcolor="#aabbcc">
<center>
<H1>Login Page</H1>
<hr><br><br><br><br>
<h2><marquee><u>WELCOME</u></marquee></h2>
<br><br><br>
<h2>
<font color="red">
<%
Object o = session.getAttribute("UN");
if(o!=null)
{
String un= o.toString();
//out.println(un);
}
%>
Your are an Authorized User.............
<br>
<br>
<br>
<br>
</font>
</h2>
</form>
<br>
<br>
<br>
<br>
<marquee behaviour ="slide" direction="right" width="1000" bgcolor="pink">
<h4>YOU ARE WELCOME TO THIS PAGE</h4>
</marquee>
</center>
</body>
</html>
LoginServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
System.out.println("User id is====="+un);
System.out.println("Password is====="+pw);
RequestDispatcher rd = null;
HttpSession ses = req.getSession();
if(un.equals("java")&&pw.equals("lab10b"))
{
ses.setAttribute("UN",un);
rd = req.getRequestDispatcher("/register.jsp");
rd.forward(req,res);
}
else
{
String msg="Invalied user id and password";
ses.setAttribute("MSG",msg);
rd=req.getRequestDispatcher("/login.jsp");
rd.forward(req,res);
}
}
}
OUTPUT:
lab11.html
<html>
<head>
<title>New Page 1</title>
</head>
<body bacgroundColor="cyay">
<center>
<h1>USER NAME AND PASSWORD </h1>
<h6>( Accept and Display the Name and Password )</h6><hr><br />
<form method="POST" action="http://localhost:8090/servlet/SendRedirectServlet">
<p>User Name:<input type="text" name="username" size="20"></p>
<p>Password: <input type="password" name="pasword" size="20"></p>
<input type="submit" value="Submit" name="B1"></p>
</form>
</body>
</html>
SendRedirectServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
ValidUserServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
OUTPUT:
12. Write a JAVA Servlet Program to implement sessions (Using HTTP Session Interface).
ShowSession.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
import java.util.*;
out.println("<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=\"CENTER\">" + heading + "</H1><HR>\n" +
"<H2>Information on Your Session:</H2>\n" +
"<TABLE BORDER=1 ALIGN=CENTER>\n" +
"<TR BGCOLOR=\"#FFAD00\">\n" +
" <TH>Info Type<TH>Value\n" +
"<TR>\n" +
" <TD>ID\n" +
" <TD>" + session.getId() + "\n" +
"<TR>\n" +
" <TD>Creation Time\n" +
" <TD>" + new Date(session.getCreationTime()) + "\n" +
"<TR>\n" +
" <TD>Time of Last Access\n" +
" <TD>" + new Date(session.getLastAccessedTime()) + "\n" +
"<TR>\n" +
OUTPUT:
13a. Write a JAVA JSP Program to print 10 even and 10 odd number.
OddEven.jsp
<html>
<head>
<title>Odd Even</title>
</head>
<body bgcolor="#DDAAEE">
<center>
<h2><b><u>Ten Odd and Ten Even numbers</u></b></h2>
<table border="1" aling="center" bgcolor="#FFEEAA" cellpadding=6 cellspacing=6>
<th>Odd No.</th><th>Even No.</th>
<%
for(i=1;i<=100;i++)
{
d = i%2;
if(d!=0)
{
%>
<tr align="center">
<td><%= i%></td>
<%
}
else
{
%>
<td><%= i%></td>
</tr>
<%
}
} // End of loop %>
</table>
</center>
</body>
</html>
OUTPUT:
13b. Write a JAVA JSP Program to implement verification of a particular user login and
display a welcome page.
login.jsp
<html>
<head>
<title>Login Page </title>
</head>
<body bgcolor="#aabbcc">
<center>
<H1>Login Page</H1>
<marquee>This page is to check the user Authentication</marquee>
<tr><td>Password</td>
<td><input type="password" name="pword"/>
</tr>
registration.jsp
<html>
<head>
<title>Register</title>
</head>
<body>
<center><br>
<h1>Registration success page</h1>
<%
String un = request.getParameter("uname");
String pw=request.getParameter("pword");
if(un.equals("Java")&& pw.equals("lab13b"))
{
out.println("<hr>");
out.println("<h3>"+un+" : Welcome to JSP</h3>");
}
else
{
out.println("<hr>");
out.println("You are not Valid user");
}
%>
</center>
</body>
</html>
register.jsp
<html>
<head>
<title>Register</title>
</head>
<body bgcolor="FFEEAA">
<center>
<h1>Registration success page</h1>
<%
String un = request.getParameter("uname");
String pw=request.getParameter("pword");
System.out.println(un);
System.out.println(pw);
%>
</center>
</body>
</html>
OUTPUT:
14. Write a JAVA JSP Program to get student information through a HTML and create a
JAVA Bean Class, populate Bean and display the same information through another
JSP.
StudInfo.html
<html>
<head><title> Student Information </title></head>
<body>
first.jsp
<html>
<body>
<jsp:useBean id="stud" scope="request" class="beans.Student"/>
<jsp:setProperty name="stud" property="*"/>
<jsp:forward page="display.jsp"/>
</body>
</html>
display.jsp
<html>
<body>
<center>
<h1>STUDENT INFORMATION </h1>
<h6>( Accepted Information ) </h6><hr><br>
<jsp:useBean id="stud" scope="request" class="beans.Student"/>
Name : <jsp:getProperty name="stud" property="sname"/><br>
USN : <jsp:getProperty name="stud" property="usn"/><br>
Marks : <%out.print(stud.getmarks());%>
</center>
</body>
</html>
Student.java
package beans;
public class Student
{
public String sname;
public int usn;
public double marks;
OUTPUT: