aspose file tools*
The moose likes JSP and the fly likes little application, but important, Please help, it is for my graduation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

little application, but important, Please help, it 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 ]
Gert Cuppens
Ranch Hand

Joined: Jul 13, 2003
Posts: 87
Hello Jurgen. It's always nice to meet someone who is from Antwerp too.
I could continue in Dutch, but then, the rest of the visitors couldn't follow our discussion. So I'll stick to English.
You seem to have coded already quite a lot, but could you define more precisely which problem you have ?
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
and also use the code formatting tags to make your code easier to read here.
It's far too much for us to go guessing what's going on let alone what's going different from what it should do unless you're a lot more precise.


42
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Continue any discussion here.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: little application, but important, Please help, it is for my graduation