File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Please help me. This is for my graduation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Reply locked New topic
Author

Please help me. This is for my graduation

jurge hallez
Greenhorn

Joined: May 08, 2004
Posts: 3
Hello I am Jurgen Hallez. I am a student at the university of Antwerp, Belgium. I am trying to make an simple application using a jsp page, a session bean, an entity bean and a database. The application is a part of my graduation paper I have to make.
It is a very simple application. Trough a web client (jsp) one can input a name, a surname and a salary. These three fields are to be stored on a database. The application allso needs to give the possibility to calculate the average of all salaries. But the appliaction does not work.
I have downloaded and installed the J2EE SDK 1.4. I have read the tutorial, but I can not find the solution.
---------Please help, it is for my graduation---------
This is the code:
jsp file:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*, package1.Persneel, package1.PersoneelHome,
javax.ejb.*, java.math.*, javax.naming.*, javax.rmi.PortableRemoteObject, java.rmi.RemoteException" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<! private Personeel personeel = null;
public void jspInit () {
try {
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("ejb/SimplePersoneel");
PersoneelHome home = (PersoneelHome) PortableRemoteObject.narrow(objRef, PersoneelHome.class);
Personeel personeel = home.create();
}catch (RemoteException ex){
System.out.println("vormen van bean type personeel mislukt."+ ex.getMessage());
}catch (CreateException ex){
System.out.println("vormen van bean type personeel mislukt."+ ex.getMessage());
}catch (NamingException ex){
System.out.println("Unable to lookup home: "+ "a"+ ex.getMessage());
}
}
public void jspDestroy() {
personeel = null;
}
%>

<html>
<head>
<title>Personeelsadministratie</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<center><h1 align="center">Een kleine personeelsadministratie</h1>
<form name="personen ingeven" method="get">
<p></p>
<h3>Voer een nieuw personeelslid in:</h3>
<p></p>
voornaam: <input name="inputvoornaam" type="text">
naam:
<input name="inputnaam" type="text">
salaris:
<input name="salaris" type="text">
<p></p>
<input type="submit" value="sla op">
<input type="submit" value="herbegin">
</form>
<% String naam = request.getParameter("inputnaam");
String voornaam = request.getParameter("inputvoornaam");
double salaris = request.getParameter("salaris");

personeel.createMedewerker(naam, voornaam, salaris);
%>
<p></p>
<form method="get" name="vraag salaris">
<h3>Vraag de salaris van een personeelslid:</h3>
geef naam in:
<input name="vraagnaam" type="text"><p></p>
<input name="submit1" type="button" value="zoek salaris">
</form>
<% String naamsalaris = request.getParameter("vraagnaam"); %>
De heer/mevrouw <%=vraagnaam> verdient <%= personeel.getSalaris(naamsalaris) %> � per maand.
<form>
<h3>Bereken het gemiddelde van alle salarissen:</h3>
<input name="buttonbereken" type="button" value="bereken">
</form>
De gemiddelde salaris van alle werknemers is <%= personeel.bereken()%> �.
</center>
</body>
</html>
-----------------------
the session bean:
/*
* Created on 1-mei-2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package package1;
/**
* @author J�rgen
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
public class PersoneelBean implements SessionBean{
private LocalMedewerkerHome medewerkerHome = null;
/*
* ejbcreate methode van het type Personeel
* business methodes:
* - bereken gemiddlde
* - vragen van persoon en salaris
* - ingeven van salaris
*/
// Medewerker business methodes:
// get methodes
// create methode
// remove methode indien nodig
public double bereken (){

//hier krijg je een collectie van beans van type Medewerker binnen
// sum = 0;
// while i has next, sum = sum + medewerker.salaris, i++;
//gemiddelde = sum / collection.getNumberofitems
int j = 0;
double totaal = 0;
Collection medewerkers = null;

try {
medewerkers = medewerkerHome.findAll();
}catch (Exception ex){
throw new EJBException(ex.getMessage());
}

Iterator i = medewerkers.iterator();

while (i.hasNext()){
LocalMedewerker medewerker = (LocalMedewerker)i.next();
String naam = medewerker.getNaam();
totaal = totaal + (getSalaris(medewerker, naam));
j++;
}

totaal = totaal / j;

return (totaal);
}
public void createMedewerker(String naam, String voorNaam, double salaris){
}
public void removeMedewerker (String naam){
}
private double getSalaris(LocalMedewerker medewerker, String naam){

try{
return medewerker.getSalaris();
}catch (Exception ex){
throw new EJBException(ex.getMessage());
}

}

/*try{
LocalMedewerker medewerker = medewerkerHome.findByPrimaryKey(String naam);
double salaris = medewerker.getSalaris();
}catch (Exception ex){
throw nex EJBException(ex.getMessage())
}

return salaris;
}*/
// session bean methodes:
// ejbCreate, ejbActivate, ejbPassivate, constructor, ejbRemove, setSessionContext
public void ejbCreate() throws CreateException{
try {
medewerkerHome = lookupMedewerker();
}catch (NamingException ex) {
throw new CreateException(ex.getMessage());
}
}
public void ejbActivate(){
try {
medewerkerHome = lookupMedewerker();
}catch (NamingException ex){
throw new EJBException(ex.getMessage());
}
}
public void ejbPassivate() {
medewerkerHome = null;
}
public PersoneelBean(){
}
public void ejbRemove () {
}
public void setSessionContext(SessionContext sc) {
}
// private methodes:
// lookup methode naar Medewerker
private LocalMedewerkerHome lookupMedewerker() throws NamingException {

Context initial = new InitialContext();
Object objref = initial.lookup("java:comp/env/ejb/SimpleMedewerker");

return (LocalMedewerkerHome) objref;
}
}
----------------
home interface:
/*
* Created on 1-mei-2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package package1;
/**
* @author J�rgen
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
//import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface PersoneelHome extends EJBHome{
/*
* create nieuwe bean van type Personeel
*/
Personeel create() throws RemoteException, CreateException;
}
-------------
remote interface:
/*
* Created on 1-mei-2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package package1;
/**
* @author J�rgen
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
//import java.util.*;
public interface Personeel extends EJBObject{
/* business methodes:
* - vragen salaris
* - bereken gemiddelde
* - ingeven van salaris
*/
// Medewerker
public double getSalaris(String naam)
throws RemoteException;
public double bereken()
throws RemoteException;
}
-----------------
enity bean:
/*
* Created on 1-mei-2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package package1;
/**
* @author J�rgen
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
//import java.util.*;
import javax.ejb.*;
//import javax.naming.*;
public abstract class MedewerkerBean implements EntityBean{
/*
* get en set access methodes voor de vaste en realtie velden
* select methodes: selecteer salaris
* home methodes
* business methodes: bereken gemiddelde
* databaase connectie
*/

private EntityContext context;

// access methodes voor vaste velden

public abstract String getNaam();

public abstract void setNaam(String naam);

public abstract String getVoornaam();

public abstract void setVoornaam(String voornaam);

public abstract double getSalaris();

public abstract void setSalaris(double salaris);

// access methodes voor relationele velden

// select methodes

// business methodes

// entitybeans methodes
public String ejbCreate(String naam, String voornaam, double salaris) throws CreateException {

setNaam (naam);
setVoornaam (voornaam);
setSalaris (salaris);
return null;
}

public void ejbPostCreate(String naam, String voornaam, double salaris) throws CreateException {
}
public void setEntityContext (EntityContext ctx) {
context = ctx;
}
public void unsetEntityContext() {
context = null;
}
public void ejbRemove() {
}
public void ejbLoad() {
}
public void ejbStore() {
}
public void ejbPassivate() {
}
public void ejbActivate() {
}
}
-------------
localhome interface:
/*
* Created on 1-mei-2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package package1;
/**
* @author J�rgen
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.util.*;
import javax.ejb.*;
public interface LocalMedewerkerHome extends EJBLocalHome{
/*
* de create, finder en home methodes voor de session bean:
* - create bean van het type Medewerker
* - find by naam
*/
public LocalMedewerker findByPrimaryKey(String naam)
throws FinderException;
public LocalMedewerker create(String naam, String voornaam, double salaris)
throws CreateException;

public Collection findAll()
throws FinderException;
}
---------------
local interface:
/*
* Created on 1-mei-2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package package1;
/**
* @author J�rgen
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
//import java.util.*;
import javax.ejb.*;
public interface LocalMedewerker extends EJBLocalObject{
/*
* busines en access methodes voor de session bean Personeel
* - get salaris
* - get naam ???
* - bereken gemiddelde
*/
public double getSalaris();
public String getNaam();
}
[ May 08, 2004: Message edited by: jurge hallez ]
[ May 08, 2004: Message edited by: jurge hallez ]
Dale Seng
Ranch Hand

Joined: Mar 22, 2004
Posts: 275
There are not many folks that would dive-in to all of that code and do your work for you!! But if you were specific about what you observed when "it doesn't work", someone may help.
--Dale--
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Hi Jurge
Welcome to Javaranch, a friendly place for Java greenhorns
Please do not crosspost the same question in multiple forums. I'm going to close this thread. You can continue discussing this topic at http://www.coderanch.com/t/284966/JSP/java/little-application-but-important-Please . Thank you
Also, it would help if you could be more precise as to which problem you have. That way ranchers will be better able to help you find error and correct them.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Please help me. This is for my graduation