Magazine
 
Working with Entity bean using JPA

defined properties..
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}

IV. Creating a Web Client

The web client is divided into two pages. First is “form.jsp” where a request form is sent to the client; second is “WebClient.jsp” which is called from the “form.jsp” page. The source code for the “form.jsp” is given below.

<html>
<head>
<title>Library</title>
</head>
<body bgcolor=”pink”>
<h1>Library</h1>
<hr>
<form action=”WebClient.jsp”
method=”POST”>
<p>Enter the Title:
<input type=”text” name=”t1"
size=”25"></p>
<br>
<p>Enter Author name:

 

<input type=”text” name=”aut” size=”25">
</p>
<br>
<p>Enter Price:
<input type=”text” name=”price” size=”25">
</p>
<br>
<p>
<input type=”submit” value=”Submit”>
<input type=”reset” value=”Reset”>
</p>
</form>
</body>
</html>

The following statements given below in “WebClient.jsp” are used for locating the business interface, creating an enterprise bean instance, and invoking a business method.

InitialContext ic = new InitialContext();
BookCatalogInterface bci = (BookCatalogInterface) ic.lookup(“book/ BookCatalogBean/remote”);

The full source code for the WebClient.jsp is given below.

<%@ page contentType=”text/html;
charset=UTF-8" %>
<%@ page import=”entity.library.*,
javax.naming.*, java.util.*”%>
<%!
private BookCatalogInterface bci = null;
String s1,s2,s3;
Collection list;
public void jspInit() {
try {
InitialContext ic = new
InitialContext();
bci = (BookCatalogInterface)
ic.lookup(“book/BookCatalogBean/remote”);
System.out.println(“Loaded Bank Bean”);
} catch (Exception ex) {
System.out.println(“Error:”+
ex.getMessage());
}
}
public void jspDestroy() {
bci = null;
}
%>

Feb 2008 | Java Jazz Up | 11
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 ,

Download PDF