Solved

What is wrong w/ this JSP?

Posted on 2004-10-22
145 Views
Last Modified: 2010-04-01
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.

0
Question by:skip1000
    2 Comments
     
    LVL 8

    Accepted Solution

    by:
    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
     
    LVL 13

    Assisted Solution

    by:petmagdy
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT Security CISA, CISSP & CISM Certification

    Master the advanced techniques required to protect network resources from external threats with the IT Cyber Security bundle. Built around industry best-practice guidelines, the IT Cyber Security bundle consists of three in-depth courses.

    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    Ransomware continues to be a growing problem for both personal and business users alike and Antivirus companies are still struggling to find a reliable way to protect you from this dangerous threat.
    This video Micro Tutorial is the first in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles al…
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now