Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What is wrong w/ this JSP?

Posted on 2004-10-22
2
Medium Priority
?
147 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
Comment
Question by:skip1000
2 Comments
 
LVL 8

Accepted Solution

by:
kiranhk earned 600 total points
ID: 12382257
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
petmagdy earned 150 total points
ID: 12382292
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

916 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