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 and other Java EE Technologies 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
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
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 ]
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Welcome to the Ranch Jurgen. A couple of pointers that will help you get responses to your problems:
1. When you post code, use the UBB Code tags to keep the formatting, otherwise it just looks like a big ugly blob of code on the screen, yuck.
2. Not many people will have the time or patience to read through a couple hundred lines of code looking for possible errors. You need to be more specific about what is not working. Are you getting an exception? If so post the stack trace. Are you having problems deploying the app? Is the web interface not working? What app server are you using? Is the data not being updated/inserted correctly? Too many questions at this point - narrow it down.


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Jurgen.
No one is going to just solve your problem for you. If we take your code and make it work, then what have you learned? You have to be logical and work through the problems. We can help you with specific, detailed problems, but we won't do your homework for you.
So take a step back and think. What is the first problem you have? You've just said "it doesn't work". WHY doesn't it work? Do you have a compilation error? Do you get a runtime exception? What does your program manage to do? For instance, I see from your program comments that you're using WebSphere Studio or Eclipse -- have you set any breakpoints in your program and seen how far it gets? How are you running your program? Are you just compiling it in Eclipse and then exporting files?
Calm down. You will get this done and you will graduate, IF you are logical and precise in going about this. Walk through the steps you've done, one at a time and if you really get to a particular point that you can't get past, then ask a SPECIFIC question for help.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

Also, please don't cross post the same question in multiple forums.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
where and what type of error are you getting? Try to debug you code and then send that piece of code that you think is generating errors. Otherwise it will be very difficult to read all of your code and find errors.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Originally posted by Jeanne Boyarsky:
Also, please don't cross post the same question in multiple forums.

You can continue this discussion at http://www.coderanch.com/t/284966/JSP/java/little-application-but-important-Please.
This thread is now closed. Thank you


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help me. This is for my graduation.