Sei sulla pagina 1di 53

Practical No:01

AIM: Develop Simple Servlet Question Answer Application To Demonstrate Use Of


HttpServletRequest And HttpServletResponse Interfaces.

index.html:-

<html>

<head>

<title>Question Answer</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head> <body>

<form method="get" action="Aques">

1.What is full form of JSP? <br>

<input type="radio" name="f1" value="1"> J pages <br>

<input type="radio" name="f1" value="2"> Java Server Page <br>

<input type="radio" name="f1" value="3"> J S Pages <br>

<input type="radio" name="f1" value="4"> J Server page <br>

2.What is full form of JVM? <br>

<input type="radio" name="f2" value="1"> Java Virtual Machine <br>

<input type="radio" name="f2" value="2"> J Machine <br>

<input type="radio" name="f2" value="3"> JV Machine <br>

<input type="radio" name="f2" value="4">JV <br>

<input type="submit" value="Done">

</form>

</body> </html>

Aques.java:-
package Aques;

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;
import javax.servlet.http.HttpServletResponse;
public class Aques extends HttpServlet
{
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
{
PrintWriter out=resp.getWriter();
int r=0;
int a=Integer.parseInt(req.getParameter("f1"));
int b=Integer.parseInt(req.getParameter("f2"));
if(a==2) r++;
if(b==1) r++;
out.println("total score is:"+r);
}
}
Html form:

1.What is full form of JSP?

J pages

Java Server Page

J S Pages

J Server page
2.What is full form of JVM?

Java Virtual Machine

J Machine

JV Machine

JV
Done

Output:
Practical No:02

AIM:-Develop Servlet Application of Basic Calculator(+,-,*,/,%) using


ServletInputStream and ServeltOutputStream.

Source Code:-
<html>

<head>

<title> Calculator </title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>

<body>

<form method="post" action="Calculator">

Enter no 1:<input type="text" name="n1"> <br>

Enter no 2:<input type="text" name="n2"> <br>

<input type="Submit" name="btn" value="+">

<input type="Submit" name="btn" value="-">

<input type="Submit" name="btn" value="*">

<input type="Submit" name="btn" value="/">

<input type="Submit" name="btn" value="%">

</form>

</body>

</html>

Calulator1.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;

import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = {"/Calculator"})

public class Calculator1 extends HttpServlet

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse respone) throws


ServletException, IOException

PrintWriter out=respone.getWriter();

try

int n1=Integer.parseInt(request.getParameter("n1"));

int n2=Integer.parseInt(request.getParameter("n2"));

int c=0;

String opt=request.getParameter("btn");

if(opt.equals("+"))

c=n1+n2;

if(opt.equals("-"))

c=n1-n2;

if(opt.equals("*"))
c=n1*n2;

if(opt.equals("/"))

c=n1/n2;

if(opt.equals("%"))

c=n1%n2;

out.println("result"+c);

catch(Exception e)

out.println("error"+e.getMessage());

Output:-

Enter no 1:
Enter no 2:
+ - * / %
Practical No:03
AIM:Develop a JSP Application to accept RegistrationDetails form user and store it into the database
table.

html.jsp file:

<html>

<head>

<title>TODO supply a title</title>


</head>

<body>

<form action="reg.jsp" >

enter the registration number<input type="text" name="t1"> <br>

enter the email id<input type="text" name="t3"> <br>

enter the name<input type="text" name="t2"> <br>

<input type="submit" value="register">

</form>

</body>

</html>

reg.jsp file:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@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>

<%

try

Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/user","root","tiger");

PreparedStatement ps=con.prepareStatement("insert into reg values(?,?,?)");

int regnumber =Integer.parseInt(request.getParameter("t1"));

String emailid =request.getParameter("t3");

String name = request.getParameter("t2");

ps.setInt(1,regnumber);

ps.setString(2,emailid);

ps.setString(3,name);

ps.executeUpdate();

out.println("data added");

ps.close();

con.close();

catch(Exception e)

%>

</body>

</html>

Output:
Practical no:04
AIM: Develop 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.

CODE:index.jsp
<!DOCTYPE html>

<html>

<head>

<title>User Login Authentication</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>

<body>

<form action="login9.jsp" method="post">

Username:<input type="Text" name="uname">

Password:<input type="Text" name="pass">

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

</form>

</body>

</html>

Login.jsp
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>

<!DOCTYPE html>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<%

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db","root","tiger");

String uname1=request.getParameter("uname");

String pass1=request.getParameter("pass");

PreparedStatement ps=con.prepareStatement("select * from logintable where uname=? and pass=?");

ps.setString(1, uname1);

ps.setString(2, pass1);

ResultSet rs=ps.executeQuery();

if(!rs.next())

%>

invalid Username or Password entry!!!<br>

<jsp:include page="index.html;"/>

<%}

else

%>

<jsp:forward page="AuthenticatedUser.jsp"/>

<%
}

%>

</body>

</html>

AuthenticatedUser.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>

WELCOME USER <br>

<%=request.getParameter("uname")%>

</body>

</html>

HTML Output:

LOGIN
Username: Password:

BROWSER OUTPUT:
Practical No:05(A)

AIM:Write a java program to present a set of choices for a user to select Stationary
products and display the price of Product after Selection from the list.

CODE:
package product9;

import java.awt.Container;

import javax.swing.*;

import javax.swing.event.ListSelectionEvent;

import javax.swing.event.ListSelectionListener;

public class Product9 extends JFrame implements ListSelectionListener

JList list;

String prod[]={"pen","notebook","pencil","Graph","colorbox","files"};

int price[]={5,40,20,10,140,50};

JScrollPane jsp;

JLabel lbl1;

Container c;

Product9()

super("Product Details:");

c=getContentPane();

list=new JList(prod);

list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

list.addListSelectionListener(this);
jsp=new JScrollPane(list);

jsp.setBounds(50, 50, 100, 100);

c.add(jsp);

lbl1=new JLabel("");

lbl1.setBounds(200, 200, 100, 35);

c.add(lbl1);

setSize(400,400);

setDefaultCloseOperation(3);

setVisible(true);

@Override

public void valueChanged(ListSelectionEvent lse)

int val=list.getSelectedIndex();

lbl1.setText("Price="+ price[val]);

public static void main(String args[])

new Product9();

}
OUTPUT:
Practical No:05(B)

AIM:Write a java program to demonstrate typical Editable Table,Describing employee


details for a software company.

CODE:
package emptable;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.*;

import javax.swing.*;

import javax.swing.table.*;

public class EmpTable extends JFrame implements ActionListener

JTable jt;

DefaultTableModel dtm;

JScrollPane jsp;

JLabel l1,l2,l3;

JTextField t1,t2,t3;

JButton b1;

EmpTable()

super("Employee Table:");

Object[][] data=null;

String[] head={"Empolyee no","Name","Age"};

dtm=new DefaultTableModel(0,3);
dtm.setDataVector(data,head);

jt=new JTable(dtm);

jt.setGridColor(Color.RED);

jt.setRowSelectionAllowed(true);

jsp=new JScrollPane(jt);

JPanel p1=new JPanel();

p1.add(jsp);

l1=new JLabel("Empolyee no");

l2=new JLabel("Name");

l3=new JLabel("Age");

t1=new JTextField(5);

t2=new JTextField(15);

t3=new JTextField(3);

JButton b1=new JButton("ADD");

b1.addActionListener(this);

JPanel p2=new JPanel();

p2.add(l1);

p2.add(t1);

p2.add(l2);

p2.add(t2);

p2.add(l3);

p2.add(t3);

p2.add(b1);

Container c=getContentPane();
c.add(p1,BorderLayout.NORTH);

c.add(p2,BorderLayout.CENTER);

setSize(500,500);

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);

@Override

public void actionPerformed(ActionEvent ae)

String no=t1.getText();

String name=t2.getText();

String age=t3.getText();

Object[] data={no,name,age};

dtm.addRow(data);

t1.setText("");

t2.setText("");

t3.setText("");

public static void main(String[] args)

new EmpTable();

}
OUTPUT:
Practical No:06(A)

AIM:Write a java program using split pane to demonstrate a screen divided in two
parts,one part contains the names of planets and another Displays the image of
planets.When user selects the planets name from Left Screen,appropriate image of
planets displayed in right screen.

CODE:
package split;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import javax.swing.event.ListSelectionEvent;

import javax.swing.event.ListSelectionListener;

public class Split extends JFrame implements ListSelectionListener

JList list1;

JScrollPane jsp1;

JLabel lbl;

JSplitPane pane;

ImageIcon img1,img2,img3,img4,img5,img6,img7,img8,img9;

Container c;

Split()

super("Planet display");

c=getContentPane();
String[] st={"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto"};

list1=new JList(st);

list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

list1.addListSelectionListener(this);

jsp1=new JScrollPane(list1);

img1=new ImageIcon("C:\\Users\\exam.VSIT-X119-11\\Desktop\\mercury.jpg");

img2=new ImageIcon("C:\\Users\\exam.VSIT-X119-11\\Desktop\\venus.jpg");

img3=new ImageIcon("C:\\Users\\exam.VSIT-X119-11\\Desktop\\earth.jpg");

img4=new ImageIcon("C:\\Users\\exam.VSIT-X119-11\\Desktop\\mars.jpg");

img5=new ImageIcon("C:\\Users\\exam.VSIT-X119-11\\Desktop\\jupiter.jpg");

img6=new ImageIcon("C:\\Users\\exam.VSIT-X119-11\\Desktop\\saturn.jpg");

img7=new ImageIcon("C:\\Users\\exam.VSIT-X119-11\\Desktop\\uranus.jpg");

img8=new ImageIcon("C:\\Users\\exam.VSIT-X119-11\\Desktop\\neptune.jpg");

img9=new ImageIcon("C:\\Users\\exam.VSIT-X119-11\\Desktop\\pluto.jpg");

lbl = new JLabel("",JLabel.CENTER);

pane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,jsp1,lbl);

pane.setDividerLocation(80);

c.add(pane);

setSize(400,400);

setDefaultCloseOperation(3);

setVisible(true);

public void valueChanged(ListSelectionEvent lse)

{
int ch=list1.getSelectedIndex() +1;

switch(ch)

case 1 : lbl.setIcon(img1); break;

case 2 : lbl.setIcon(img2); break;

case 3 : lbl.setIcon(img3); break;

case 4 : lbl.setIcon(img4); break;

case 5 : lbl.setIcon(img5); break;

case 6 : lbl.setIcon(img6); break;

case 7 :lbl.setIcon(img7); break;

case 8 : lbl.setIcon(img8); break;

case 9 : lbl.setIcon(img9); break;

default : lbl.setText("image not found !");

public static void main(String[] args)

new Split();

}
OUTPUT:
Practical No:06(B)

AIM:Write a java program for Jfilechooserdemo.

CODE:
package jfilechooserdemo;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

public class Jfilechooserdemo extends JFrame implements ActionListener

private static int APPROVE_OPTION;

JMenuBar mb;

JMenu f;

JMenuItem o,x;

JFileChooser fc;

JTextArea ta;

JDialog d;

Jfilechooserdemo(String s)

super(s);

mb=new JMenuBar();

setJMenuBar(mb);

f=new JMenu("File");

mb.add(f);
o=new JMenuItem("Open...");

x=new JMenuItem("Exit");

f.add(o);

f.add(x);

f.setMnemonic(KeyEvent.VK_F);

o.setMnemonic(KeyEvent.VK_O);

x.setMnemonic(KeyEvent.VK_X);

fc=new JFileChooser("C:\\Users\\dell\\Desktop");

o.addActionListener(this);

x.addActionListener(this);

ta=new JTextArea();

ta.setEditable(false);

Container c=getContentPane();

c.add(new JScrollPane(ta));

setSize(500,400);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);

public void actionPerformed(ActionEvent ae)

if(ae.getSource()==o) loadFl();

else if(ae.getSource()==x)

dispose();
System.exit(0);

void loadFl()

int result=fc.showOpenDialog(this);

File f=fc.getSelectedFile();

if(f!=null && result==Jfilechooserdemo.APPROVE_OPTION)

try

FileInputStream fr=new FileInputStream(f);

ta.setText("");

byte[] buffer=new byte[4096];

int count=fr.read(buffer,0,buffer.length);

ta.append(new String(buffer,0,count));

catch(IOException ie)

System.out.println(ie);

public static void main(String[] args)

new Jfilechooserdemo("File Chooser Demo");


}

OUTPUT:

Practical no:06(C)
AIM:Write a java program for JColorChooserDemo.(split pane)

CODE:
package jcolorfiledemo;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

public class JColorFileDemo extends JFrame implements ActionListener

JMenuBar mb;

JMenu e;

JMenuItem c;

JColorChooser cc;

JTextArea ta;

JDialog d;

JColorFileDemo(String s)

super(s);

mb=new JMenuBar();

setJMenuBar(mb);

e=new JMenu("Edit");

e.setMnemonic('E');

mb.add(e);

c=new JMenuItem("Change color...");


e.add(c);

c.setMnemonic(KeyEvent.VK_C);

cc=new JColorChooser();

c.addActionListener(this);

ta=new JTextArea();

Container c=getContentPane();

c.add(new JScrollPane(ta));

setSize(500,400);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);

public void actionPerformed(ActionEvent ae)

if(ae.getSource()==c)

d=JColorChooser.createDialog(this,"select text color",true,cc,new ColorOKListener()

@Override

public void actionPerformed(ActionEvent e)

throw new UnsupportedOperationException("Not supported yet."); //To change body of generated


methods, choose Tools | Templates.

},null);

cc.setColor(ta.getForeground());
d.setVisible(true);

abstract class ColorOKListener implements ActionListener

public void ActionPerfomed(ActionEvent ae)

Color c=cc.getColor();

ta.setForeground(c);

ta.repaint();

public static void main(String args[])

new JColorFileDemo("Color Choosers");

OUTPUT:
Practical No:-08
AIM:Develop a web application to add items in the inventory using JSF.

CODE:

index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:h="http://xmlns.jcp.org/jsf/html">

<h:head>

<title>Product table</title>

</h:head>

<h:body>

<h:form>

Product Details form...

<h:panelGrid columns="2">

Product code:<h:inputText id="textcode" value="#{b1.pcode}"/>

Product name:<h:inputText id="textname" value="#{b1.pname}"/>

<h:commandButton id="cmdadd" value="ADD" action="#{b1.add}"/>

</h:panelGrid>

</h:form>

</h:body>

</html>

Success.xhtml

<?xml version='1.0' encoding='UTF-8' ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:h="http://xmlns.jcp.org/jsf/html">

<h:head>

<title>Facelet Title</title>

</h:head>

<h:body>

Product added succesfully......

</h:body>

</html>

Error.xhtml

<?xml version='1.0' encoding='UTF-8' ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:h="http://xmlns.jcp.org/jsf/html">

<h:head>

<title>Facelet Title</title>

</h:head>

<h:body>

product not added.....

</h:body>

</html>

Faces-config-xml

<?xml version='1.0' encoding='UTF-8'?>

<faces-config version="2.2"

xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-
facesconfig_2_2.xsd">

<navigation-rule>

<from-view-id>/index.xhtml</from-view-id>

<navigation-case>

<from-outcome>yes</from-outcome>

<to-view-id>/Succes.xhtml</to-view-id>

</navigation-case>

<navigation-case>

<from-outcome>no</from-outcome>

<to-view-id>/error.xhtml</to-view-id>

</navigation-case>

</navigation-rule>

<managed-bean>

<managed-bean-name>b1</managed-bean-name>

<managed-bean-class>been.Productdet</managed-bean-class>

<managed-bean-scope>request</managed-bean-scope>

</managed-bean>

</faces-config>

Productdet.java

package been;

import java.sql.*;

public class Productdet {

private int pcode;

private String pname;


public Productdet() {

public int getPcode() {

return pcode;

public void setPcode(int pcode) {

this.pcode = pcode;

public String getPname() {

return pname;

public void setPname(String pname) {

this.pname = pname;

public String add()

{ try

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/producdb","root","tiger");

PreparedStatement ps=con.prepareStatement("insert into producttable values(?,?)");

ps.setInt(1,pcode);

ps.setString(2,pname);

ps.executeUpdate();

return "yes";

}
catch(Exception e)

return "no";

Output:

Practical No:09
AIM:Develop a Room Reservation System Application Using Enterprise Java Beans.
index.html

<html>

<head>

<title>Room Reservation System</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>

<body>

<form method="post" action="Roomclient">

Number of Rooms:<input type="text" name="tl">

<input type="submit" name="btn" value="checkin">

<input type="submit" name="btn" value="checkout">

</form>

</body>

</html>

Interface-RoomLocal.java

package ejb;

import javax.ejb.Local;

@Local

public interface RoomLocal

public int checkin(int no);

public int checkout(int no);

}
Room.java

package ejb;

import javax.ejb.Stateless;

import java.sql.*;

@Stateless

public class Room implements RoomLocal

@Override

public int checkin(int no)

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ejbdb","root","tiger");

String sql1="select total,occ from room";

Statement st=con.createStatement();

ResultSet rs=st.executeQuery(sql1);

rs.next();

int total=rs.getInt(1);

int occ=rs.getInt(2);

int free=total-occ;

if (free>=no)

String sql2="update room set occ=?";


PreparedStatement ps=con.prepareStatement(sql2);

ps.setInt(1,occ+no);

int res=ps.executeUpdate();

return 1;

else

return 0;

catch (Exception e)

return 0;

@Override

public int checkout(int no)

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ejbdb","root","tiger");

String sql1="select total,occ from Room";

Statement st=con.createStatement();

ResultSet rs=st.executeQuery(sql1);

rs.next();

int total=rs.getInt(1);
int occ=rs.getInt(2);

if (occ>=no)

String sql2="update room set occ=?";

PreparedStatement ps=con.prepareStatement(sql2);

ps.setInt(1,occ-no);

int res=ps.executeUpdate();

return 1;

else

return 0;

catch (Exception e)

return 0;

Servlet-Roomclient

package servlet;

import ejb.RoomLocal;

import java.io.IOException;

import java.io.PrintWriter;

import javax.ejb.EJB;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "Roomclient", urlPatterns = {"/Roomclient"})

public class Roomclient extends HttpServlet

@EJB RoomLocal obj;

@Override

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException

PrintWriter out=resp.getWriter();

try

int no=Integer.parseInt(req.getParameter("tl"));

String b =req.getParameter("btn");

int res=0;

if(b.equals("checkin"))

res=obj.checkin(no);

if(res==1)

out.println(no+"room checkin");

else if(b.equals("checkout"))

{
res=obj.checkout(no);

if(res==1)

out.println(no+"room checkout");

if(res==0)

out.println("Not possible to do checkin and checkout");

finally

out.close();

OUTPUT:
practical 10

Aim:hibernate program

Guestbook.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<%@page import="org.hibernate.SessionFactory"%>

<%@page import="org.hibernate.Session"%>

<%@page import ="org.hibernate.cfg.Configuration"%>

<%@page import="org.hibernate.Transaction"%>

<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>

<%@page import="hibernate.Guestbook"%>

<%!

SessionFactory sf;

org.hibernate.Session ss;

List<hibernate.Guestbook> gbook;

%>

<%

sf=new Configuration().configure().buildSessionFactory();

ss=sf.openSession();

Transaction tx=null;

Guestbook gb= new Guestbook();

try

tx=ss.beginTransaction();

String name=request.getParameter("name");

String msg=request.getParameter("msg");

String dt=new java.util.Date().toString();

gb.setName(name);

gb.setMsg(msg);

gb.setDt(dt);

ss.save(gb);

tx.commit();

}
catch(Exception e)

{out.println("Error"+e.getMessage());

try

ss.beginTransaction();

gbook=ss.createQuery("from Guestbook").list();

catch(Exception e)

{}

%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Guest view</title>

</head>

<body>

Guest View

click here to go <a href="index.jsp"> BACK</a>

<br><br>

<%

Iterator it=gbook.iterator();

while(it.hasNext())

Guestbook each=(Guestbook)it.next();
out.print(each.getDt()+" ");

out.print(each.getName()+"<br>");

out.print(each.getMsg()+"<br><hr>");

%>

</body>

</html>

Index.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>

guest book <hr> <br><br>

<form action="guestbookview.jsp" method="post">

Name<input type="text" name="name" maxlength="20"><br>

Message<textarea rows ="5" cols="40" maxlength="1000" name="msg"></textarea>

<br> <input type="submit" value="submit"></form>

</body>
</html>

Guestbook.java

package hibernate;

public class Guestbook implements java.io.Serializable {

private Integer no;

private String name;

private String msg;

private String dt;

public Guestbook() {

public Guestbook(String name, String msg, String dt) {

this.name = name;

this.msg = msg;

this.dt = dt;

public Integer getNo() {

return this.no;

}
public void setNo(Integer no) {

this.no = no;

public String getName() {

return this.name;

public void setName(String name) {

this.name = name;

public String getMsg() {

return this.msg;

public void setMsg(String msg) {

this.msg = msg;

public String getDt() {

return this.dt;

public void setDt(String dt) {

this.dt = dt;

}}
}
Steps for EJB Application

1) File -> New project -> java web -> web application -> get New web
Application Window -> provide the information in that window as: project
name -> EJBRoomReservetionApp -> browse the path for saving EJB -> next ->
select server - glassfish server -> next -> finish.
2) Click on services -> database -> create database ->db -> right click on db
-> create table -> room -> columns-> total - int primary key -> add
column->occ - int - deselect NULL -> ok.
3) Click on project -> right click on library -> add mysql connector jar
file.
4) Right click on EJBRoomReservetionApp -> new -> other -> Enterprise java
bean -> session bean -> next ->you will get new session bean window.
Provide the information to that window: EJBName -> RoomBean -> package ->
ejb, session type -> stateless, Create interface -> Local -> Finish. You
will get two files i.e. RoomBeanLocal.java and RoomBean.java.
5) Right click on EJBRoomReservetionApp -> new -> servlet. You will get
new servlet window. Give class name -> roomclient, package -> servlet-
> next-> finish.

Steps for JSF Application


1) File -> new project -> Java web -> web application -> write project name as JSFProductApp -> browse the
folder -> Next -> select server ->apache tomcat / glassfish server -> next -> frameworks -> Java Server
Faces -> click on configuration tab -> preferred page language ->facelets -> finish.
2) Click on services -> database -> create database ->db -> right click on db -> create table -> product
->pcode int primary key -> add ->pname varchar 15 -> ok.
3) Click on project -> right click on library -> add mysql connector jar file.
4) Select index.xhtml file and make required changes for inserting product code and product name and also
to add button.
5) Right click the project -> new -> other -> Java Server Faces -> JSF Page -> next -> write filename as
success -> select options ->facelets -> finish -> make necessary changes in success.xhtml.
6) Right click the project -> new -> other -> Java Server Faces -> JSF Page -> next -> write filename as error
-> select options ->facelets -> finish -> make necessary changes in error.xhtml.
7) Right click the project -> new -> other -> Java Server Faces -> JSF faces configuration -> next ->keep
default file name as it is, that is faces-config ->finish.
8) Right click the project -> new -> other -> Java Server Faces -> JSF Managed Bean ->class name
->ProductBean -> package -> bean -> select the checkbox add data to configuration file -> scope->
request ->finish ->make necessary changes in ProductBean.java
9) make necessary changes in faces-config.xml file.
10) Run the project.

Potrebbero piacerti anche