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 EJB 3.0 and jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3.0 and jsp" Watch "EJB 3.0 and jsp" New topic
Author

EJB 3.0 and jsp

Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
I have created an EJB 3.0 stateless bean and a WebContent project in Eclipse Ganymede and deployed them successfully to a Glassfish server. When I try to go to the url for which it was deployed my jsp is unable to compile because it states that my ejb package doesn't exist. Where am I missing my reference to my package for my stateless bean??? should my ejb.xml so a reference to my package ejb.mybean???

thanks for any help.
ajl
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52

Well if you are using annotations, you don't need to use any XML files here. And please provide the client code you used so we can figure out your problem more accurately. For best practice, it is recommended to use an intermediate servlet between the JSP and EJB, instead of directly accessing the business tier EJB from a JSP.
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
...
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
<%@ page import="javax.ejb.*, javax.naming.*"%>
<%@ page import="ejb.*"%>
<%@ page import="java.util.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Deal</title>

</head>
<body bgcolor="blue">

<p><font size="10" color="Yellow">
Changes
</font></p>


<%!
private CardDeckRemote cd;

public void jspInit() {
try {

InitialContext ic = new InitialContext();
cd = (CardDeckRemote) ic.lookup("CardDeck/remote");
} catch (Exception ex) {
System.out.println("Error:"+
ex.getMessage());
}
}

public void jspDestroy() {
cd = null;
}
%>

<p><font size="10" color="red">
<%
String result;
Card c = new Card();
Vector <Card> v = cd.getHand();
for (int x=0;x<5;x++)
c = (Card)v.elementAt(x);
result = c.printCard();
%>
<%=result%>

</font></p>

</body>

</html>
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52

What is "CardDeck/remote"? Have you tested this with the @EJB annotation? Since these annotations are new to EJB 3.0, it is better to use them, if you are working with a EJB 3.0 container.
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
I thought the JNDI version would be simpler to begin. I had planned to move to the annotation after I got the JNDI working. I will try the annotation. have you gotten a jsp connecting to an ejb 3 object using glassfish? what about archiving? is it necessary?
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
I can't find an example of annotation inside of a jsp? can you post the code for this?

thanks
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52

You don't need to archive explicitly here. The problem may be with the JNDI name that you used for the lookup. Please check it in your ejb-jar descriptor. I did never attempt to access an EJB object directly from a JSP, since it is not a good practice. As I said before, you should use an intermediate servlet to implement your connection logic.
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
can you point me to some code for making the code in the jsp? <%@EJB%> then just reference my remote session bean object.method??? I think I am missing something?
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52


is sufficient.
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
I got the exact same error















<%@ page import="javax.ejb.*, javax.naming.*"%>
<%@ page import="ejb.*"%>
<%@ page import="java.util.*"%>

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

</head>
<body bgcolor="blue">

<p><font size="10" color="Yellow">
Changes
</font></p>


<%!
@EJB
private CardDeckRemote cd;

public void jspInit() {
try {

//InitialContext ic = new InitialContext();
// cd = (CardDeckRemote) ic.lookup("CardDeck/remote");
} catch (Exception ex) {
System.out.println("Error:"+
ex.getMessage());
}
}

public void jspDestroy() {
cd = null;
}
%>

<p><font size="10" color="red">
<%
String result;
Card c = new Card();
Vector <Card> v = cd.getHand();
for (int x=0;x<5;x++)
c = (Card)v.elementAt(x);
result = c.printCard();
%>
<%=result%>

</font></p>

</body>

</html>
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52

You said that it is a compile time error, so which statement gives that error?
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
run time error



org.apache.jasper.JasperException: PWC6033: Unable to compile class for JSP

PWC6199: Generated servlet error:
string:///index_jsp.java:8: package ejb does not exist

PWC6197: An error occurred at line: 22 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
string:///index_jsp.java:16: cannot find symbol
symbol : class CardDeckRemote
location: class org.apache.jsp.index_jsp

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
string:///index_jsp.java:96: cannot find symbol
symbol : class Card
location: class org.apache.jsp.index_jsp

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
string:///index_jsp.java:96: cannot find symbol
symbol : class Card
location: class org.apache.jsp.index_jsp

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
string:///index_jsp.java:97: cannot find symbol
symbol : class Card
location: class org.apache.jsp.index_jsp
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52

It is a compile time error, JasperException is thrown when the container attempt to 'compile' your JSP file. It says that the package ejb is not exist. Are you sure that you appropriately packaged your EJB components to the 'ejb' package?
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
you are correct. I wasn't thinking jsp compile. my classes are in the ejb package which I declared when creating the classes. is there a project file I should be looking at in order to see if I have mapped something incorrectly?




Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
[quote=Adam LaFaye]you are correct. I wasn't thinking jsp compile. my classes are in the ejb package which I declared when creating the classes. is there a project file I should be looking at in order to see if I have mapped something incorrectly?


i have two projects created in eclipse. one is the dynamic web page the other an ejb project.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52

Adam LaFaye wrote:is there a project file I should be looking at in order to see if I have mapped something incorrectly?

Duhhh! The question now turns into an eclipse related question. Please feel kind to post a new topic on our IDE Forum, by explicitly specifying your eclipse problem.
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
I mentioned in my first posting that I was using eclipse with a dynamic web content project. I am guessing you haven't worked with eclipse???
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52

Yes I don't. And this forum is for EJB and Java EE related questions only. Since we recognized that this problem is about Eclipse, and it is NOT about general EJB, it is good to post a more specific topic on the IDE forum.
Marcos Serrano
Ranch Hand

Joined: Jul 13, 2006
Posts: 46
Hey Adam,

check your gmail account, I sent an example.



toutes les jours
Adam LaFaye
Greenhorn

Joined: Apr 14, 2009
Posts: 21
I finally got my ejb 3 / struts / jsp test application to work using glassfish. If you call working by putting my ejb.jar file into the jre/lib directory and deploying my web client as a war!!!

so how will I get my ejb code to work on a remote server under this deployment plan??? can someone tell me if they have deployed an ejb module on a separate server from their web client???

also as a side note Java Server Faces are for Secretary applications not for real code work right???


cheers

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3.0 and jsp