What is wrong w/ this JSP?

Hi,

Here is my code for a JSP accessing and entity EJB.  I just want a real simple mode to see some data displayed.  What is wrong w/ this code such that it won't compile:



<%@ page import="bean.Item, bean.ItemHome, javax.ejb.*, java.math.*, javax.naming.*, javax.rmi.PortableRemoteObject, java.rmi.RemoteException" %>
<%!
   private Item item = null;

      public void jspInit() {

            try {
                  InitialContext ic = new InitialContext();
                  Object objRef = ic.lookup("java:comp/env/ejb/TheItem");
                  ItemHome home = (ItemHome)PortableRemoteObject.narrow(objRef, ItemHome.class);
                  item = home.findByPrimaryKey("L872341D");
            } catch (Exception ex) {
                  System.out.println("Exception: "+ "TheItem "+ ex.getMessage());
            }
      }

      public void jspDestroy() {    
             item = null;
      }

      InitialContext ic = new InitialContext();
      Object objRef = ic.lookup("java:comp/env/ejb/TheItem");
      ItemHome home = (ItemHome)PortableRemoteObject.narrow(objRef, ItemHome.class);
      item = home.findByPrimaryKey("L872341D");

%>
<html>
<head>
    <title>Item</title>
</head>

<body bgcolor="white">
<h1><b><center>Item</center></b></h1>
<hr>
   <p>
   The title is  <%= item.getProductNum() %></p>
 </hr>

</body>
</html>
-------------------------------------------------------------------end of code

I get the following error message:

/C:/Sun/AppServer/domains/domain1/generated/jsp/j2ee-apps/NewStore2/NewStore_war//org/apache/jsp\index_jsp.java     [javac] Compiling 1 source file    [javac] C:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-apps\NewStore2\NewStore_war\org\apache\jsp\index_jsp.java:39: <identifier> expected    [javac]                   item = home.findByPrimaryKey("L872341D");    [javac]                              ^    [javac] 1 error

----------------------------------------------------------------------------------------

What does the error message mean and what needs to be changed for the jsp page to make it work?   Thanks.

skip1000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kiranhkCommented:
write this in a seperate scriptlet
InitialContext ic = new InitialContext();
     Object objRef = ic.lookup("java:comp/env/ejb/TheItem");
     ItemHome home = (ItemHome)PortableRemoteObject.narrow(objRef, ItemHome.class);
     item = home.findByPrimaryKey("L872341D");

also u need to take out the line in the jspInit which is doing the findByprimarykey

like
<%
InitialContext ic = new InitialContext();
     Object objRef = ic.lookup("java:comp/env/ejb/TheItem");
     ItemHome home = (ItemHome)PortableRemoteObject.narrow(objRef, ItemHome.class);
     item = home.findByPrimaryKey("L872341D");
%>


also check out this link

http://www.jguru.com/faq/view.jsp?EID=5314

http://www.jguru.com/faq/view.jsp?EID=42963
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petmagdyCommented:
yes the scope of the declaration of (private Item item = null;) when complied will be inside service method so it is not seen inside jspInit()

   private Item item = null;



move the code from jspInit to outside of it u need not to do it inside jspinit
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.