Help - import own classes in jsp

Hey guys..
I'm working on a Shopping cat project which is in the directory -
C:\Tomcat 6\webapps\ROOT\cart
I've written one code in shop-product.jsp as below -
<%@ page language = "java" contentType = "text/html"
         import = "ShoppingBasket, Product, java.sql.*"
         errorPage = "errorpage.jsp" %>
<html>
<head> <title>Welcome to Shop</title></head>
<body>
<table width = "385" border="0" cellspacing="0">
<tr>
<td colspan="4">More Books from me</td>
</tr><tr>
<td colspan="4" align ="right">
<a href = "<%=response.encodeURL("shop-basket.jsp") %>"> View Basket </a></td>
</tr><tr>
<td><b>Ref</b></td><b>Title</b></td>
<td><b>Price</b></td></td></tr>
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection connection = null;
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "rahul");
Statement stmt = null;
ResultSet RS = null;
stmt = connection.createStatement();
RS = stmt.executeQuery("select * from items");
int rowCounter = 0;
    while(RS.next())
      String item_id = RS.getString("id");
      String title = RS.getString("title");
      String desc = RS.getString("desc");
      String price = RS.getString("price");
      rowCounter=rowCounter+1;
      String bg=  (rowCounter % 2 !=0) ?"#C0C0C0":"#ffffff";
%>
<tr bgcolor = <%=bg%>">
<td><%=item_id%></td>
<td><b><%=title %></b><br/><%=desc%></td>
<td><b><%=price %></b></td>
<td>
<a href =" <% response.encodeURL("shop-products.jsp?title="+title+"&item_id="+item_id+"&price="+price); %> "> Add to Cart </a></td>
</tr>
<% } RS.close(); connection.close(); %>
</table>
<jsp:useBean id = "basket" class = "ShoppingBasket" scope = "session"/>
<% String title = request.getParameter("title");
   if(title!=null)
     String item_id = request.getParameter("item_id");
     double price = Double.parseDouble(request.getParameter("price"));
     Product item = new Product (item_id, title, price);
     basket.addProduct(item);
%>
</body></html>{code}
in which ShoppingBasket and Product are the classes which I want to import. Where should I put those class files if my project path is 
+C:\Tomcat 6\webapps\ROOT\cart+
I've put class files into Tomcat_home/lib but it is giving me error
{code}type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 6 in the generated java file
The import ShoppingBasket cannot be resolved
An error occurred at line: 7 in the generated java file
The import Product cannot be resolved
An error occurred at line: 62 in the jsp file: /cart/shop-products.jsp
The method addProduct(Product) in the type ShoppingBasket is not applicable for the arguments (Product)
59:      String item_id = request.getParameter("item_id");
60:      double price = Double.parseDouble(request.getParameter("price"));
61:      Product item = new Product (item_id, title, price);
62:      basket.addProduct(item);
63:    }
64: %>
65: </body></html>
Stacktrace:
     org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
     org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
     org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
     org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
     org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
     org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
     org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.{code}
Please assist me on, how to import my custom made class files..
Thanks,
Rahul...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

What You need to do is to place ShoppingBasket class in a package and import to fully qualified class name (which is class name with package name). I also discourage You to use scriptlets - it's an obsolete, old technology.

Similar Messages

  • How to import  my own class in jsp file

    I have a jsp file in jsp\ directory and a class in web-inf\classes\ directory. How do I import the class in jsp so i can use it in my jsp file. Thanks,

    This is your lucky day, wennie.
    The correct forum to post this is:
    [http://forums.sun.com/forum.jspa?forumID=45]

  • HELP: Import my own class in JSP ???

    Hi, all!
    I read many previous topics in this forum but no one works for me!
    Please someone help me!
    I'm using Tomcat 4.1.12 and my JSP scripts work just fine, but I need to import my own .class file. I just don't know where to put it so Tomcat can find it!?
    I have this environment variable:
    JAVA_HOME=.;c:\jdk1.3.1
    And in my code I'want to place something like this:
    <%@ page import="myClass" %>
    But I get a "can not resolve symbol" exception.
    Thanks for readind this, and please help if you can!
    Bye.
    adriano

    Within the Tomcat directory, under your application directory place the class file/s into the WEB-INF/classes directory. If your classes are part of a package place the entire directory structure of the package under the WEB-INF/classes directory.
    The import in the JSP is the same as for any Java class.
    Hope this solves your problem.

  • NullPointerException - importing my own class to JSP

    Hi.
    I'm writing a JSP page. I also made a class in WEB-INF/classes/org/MyXml.class. When I try to run this class from console, there is no problems at all. But if i try to use function from that class in JSP, i get this (the same error i get whichever function i try to use (btw, all functions are static, as they should be, right?)):
    java.lang.NullPointerException
         org.MyXml.CountProducts(MyXml.java:46)
         org.apache.jsp.index_jsp._jspService(index_jsp.java:75)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    I used this class like this:
    <%@ page import="org.MyXml" %>
    <%
    MyXml.CountProducts();
    %>
    I'm also a bit confused, it says that error is on line 46. Well, there's just a comment!
    Please help. Thanks.

    pqeuens,
    MyXml is his class. his methods are static, so, import="org.MyXml.*" won't work. It would either be import="org.*" or import="org.MyXml" (which he has)
    paull1911
    "What file are you looking at to find line 46? It is the java file (a servlet) corresponding to the jsp file."
    It should actually be in the org.MyXml.java file. The stack trace line is:
    java.lang.NullPointerException
    org.MyXml.CountProducts(MyXml.java:46)
    someone_
    You know from the above error line that the error is in MyXml.CountProducts method. After making sure you are working with the most up-to-date version of the class, (if that doesn't help you get a more accurate line number) walk through the CountProducts method and see where you might be trying to access an object that has not yet been instantiated (either using someObject.someMethodOrMember, or someArray[index])

  • Importing java classes into jsp page

    I'm trying to import java classes inside my jsp page, while doing that i am getting compilation error "package uma.natarajan.javaclasses" not found. I don't know where to copy the java files. i'm keeping my jsp files under public_html folder
              

    Hi uma,
              create uma\natarajan\javaclasses under weblogic_home\myserver and copy java
              classes(u want to import) to uma\natarajan\javaclasses and then u try.
              Concept is the java classes u import should be present in a classpath. Hope
              this may help u,
              Arun,
              [email protected]
              "uma natarajan" <[email protected]> wrote in message
              news:3a490bcb$[email protected]..
              > I'm trying to import java classes inside my jsp page, while doing that i
              am getting compilation error "package uma.natarajan.javaclasses" not found.
              I don't know where to copy the java files. i'm keeping my jsp files under
              public_html folder
              

  • How can i import my classes in jsp?

    Dear All,
    i want to access my classes in jsp. i am using apache tomcat
    server. let me know where i have to put my own packages and
    how can i use them in jsp.
    thanks

    Put them in directory /WEB-INF/classes under you webcontext. You can use them in your jsp by importing them or using the useBean directive.

  • Not able to import a class in jsp

    Hello.
    I want to import a custom java class (non-packaged) that resides in the same directory as the
    jsp file.
    I tried the page directive as:
    <%@ page import="MyClass.class" %>
    But Tomcat complains and doesn't compile.
    Shows the following error message:
    No identifier.
    What's wrong here? Is there another way to import a custom class?
    Please help. Thank you.

    You need to place your custom class in a package. Has to do with tomcat not giving you access to the default package.

  • How to import API classes in JSP?

    hi,
    What is the syntax for importing Java API classes in JSP (like in .java files)?
    I've tried,
    <% import java.util.*; %>
    <%! import java.util.*; %>
    <%@ import java.util.*; %>
    <%@ page import java.util.*; %>
    ...all don't compile!
    Please help. Thanks very much!
    Gerald.

    <%@ page import="java.util.*" %>
    Look at these resources:
    http://java.sun.com/products/jsp/pdf/card11.pdf
    http://java.sun.com/products/jsp/pdf/syntaxref.pdf

  • Importing Bean Class to JSP

    Hi here's my bean
    import java.util.*;
    public class leaveChange extends Object implements java.io.Serializable
         String Name;
         String Grade;
         String Pattern;
         int numDays;
         Date startDate;
         Date endDate;
    Now to use this bean in my JSP page what do I do ?
    I tried
    <%@ page import="leaveChange"%>
    but got following error
    [javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Devannualleave\newDev\advancedOptions_jsp.java:8: '.' expected
    [javac] import leaveChange;
    [javac] ^
    [javac] 1 error
    Thanks in advance

    Update
    changed Bean class to
    package test;
    import java.util.*;
    public class leaveChange extends Object implements java.io.Serializable
         String Name;
         String Grade;
         String Pattern;
         int numDays;
         Date startDate;
         Date endDate;
    JSP File
    <%@ page import="test.leaveChange" %>
    and have in my WEB-INF/classes/test
    my Bean Class
    but get the following error
    [javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\Devannualleave\newDev\advancedOptions_jsp.java:8: package test does not exist
    [javac] import test.leaveChange;
    [javac] ^
    [javac] 1 error
    Any help ?

  • Import java-classes in JSP-page

    Hi,
    I'm starting with JSP and with trying one of the first examples in the book "beginning J2EE 1.4" from wrox, i got following problem.
    i'm trying to import a java-class in the package CH03 with
    <%@ page import="Ch03.FaqCategories" %>but he didn't find the package Ch03.
    I try already many things and i have no idea of the cause of the problem. So it's difficult to give information that leads to the solution.
    Maybe helpfull is the direcory-structure:
    jsp-page: /Ch03/welcome.jsp
    java-classe: /Ch03/WEB-INF/classes/Ch03/FaqCategories.class
    If you need source-codes or other information, just ask.
    Thanks,
    Dennis

    Thank you,
    Your help was one step into the good direction and that problem is solved.
    The application work now with studio one, but if i try it to work it with a stand-alone tomcat server it doesn't work anymore. I go first try to solve this problem by my self or at least try to describe the problem more exactly, before i ask for new help.
    but if you have any idea, that's always welcome...
    with regards,
    Dennis

  • Can't import own classes...

    I'm very new to java. I rented a book called Java 2 Grand Cru to learn it on my own. It is based on Java 1.3 but I have 1.4 installed. Now I wanted to write a simple program with a class in an other directory. I added that directory to CLASSPATH so my compiler could find it. These are the 2 programs
    import printer;
    public class test
         public static void main(String[] args)
              (new printer()).print();
    }and
    public class printer
         public void print()
              System.out.println("test");
    }So I want the first class to use the second to print "test"!
    Now I can compile public class printer without any problems but when I compile the first one, I get this:
    test.java:1: '.' expected
    import Printer;
                   ^
    1 error
    Process Exit Code: 1
    Time Taken: 00:00
    i don't get it. Is there anything changed with the import instruction in the new version of Java2?
    regards

    It is the error of my code but probably I did something bad with the copy paste thing :-)... The 'P' should be a 'p'
    Anyhow, I don't understand your first comment. 'printer.class' isn't a default package. I made it myself...
    regards

  • Help importing a class and initializing it

    Hi guys...
    I have a (what I think is) a little problem but after being the whole night awake I can´t think anymore...
    I have a button which sends you to frame 10 and in frame 10 I suppose to intialize the class I imported:
    import Payment;
    getpremium.addEventListener(MouseEvent.CLICK, PI);
    function PI(e:MouseEvent):void {
         gotoAndStop(10);
    Now in frame 10 the only thing I have is:
    Payment();
    and the class (how it starts) is:
    package
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.IOErrorEvent;
        import flash.events.MouseEvent;
        import flash.net.URLLoader;
        import flash.net.URLRequest;
        import flash.text.TextField;
        import flash.text.TextFormat;  //etc
    public class Payment extends Sprite
            private var paymentSystem:PaymentSystem;
            private var buyList:List;
            private var loader:URLLoader;
            private var pastPurchases:Array = [];
            private var alltextformats:TextFormat = new TextFormat();
            public function Payment()
                paymentSystem = new PaymentSystem(); //etc
    What do I suposse to write down on frame 10 for the class to be initialized?
    Thanks!!!

    Normally what you need to do is instantiate a Payment object...
    import Payment;
    var payment:Payment = new Payment();

  • Problem to Import my own classes

    I try to import own classes to unother class
    I have all classes in the same map
    import StockTablePanel;
    when I tried to compile the code it says
    �.� expected
    StockTablePanel;
    What is wrong?

    I try to import own classes to unother class
    I have all classes in the same mapAlso if by the same map you mean the same folder then you don't even have to import the class.

  • ACK! Importing classes in JSP?!?! HELP!!!

    I am REALLY new to the JSP world and just finished creating a java applet that creates a graph and two combo boxes containing information that I need to display on a web page.
    The problem is that I have just been told to convert it to JSP? Is this possible? If it IS possible, how do you import a public class into JSP?
    Thanks sooooo much for your help!!!!!
    Adam

    Answer is yes you can import a java class
    Here is how it works
    use the following
    <%@ page import="com.temp.YourClass*" %>
    Assuming that you classpath is set properly
    Thanks
    Sampath Thummati.

  • Pls help!  How to put JSP import statement...

    Hi, I just created a simple iView JSP that imports htmlb classes and now I'd like to import my own java classes onto it.  For example, in my other projects, my JSP's have <%@ page import="project28.practice.contextClass" %> on top of the page.  I currently have a file called practice.jar 
    If I want to put this import statement into my simple iView JSP and use it, what would I have to do/configure?, do I have to transform it into a .par file?  Or can I  transport the jar file to the portal?  Any changes on NetWeaver?
    I am new to this so any detailed help or suggestions are greatly appreciated!
    Thanks again,
    Baggett

    Hi Detlev, thank you for your response!  I'd like to include more details of my situation right now:  I have 2 projects on NetWeaver:
    Project#1: Java Web application Project. (jar files, WEB-INF, WEB-INF/web.xml, JSP's...)
    Project#2: Portal Application Project. (JSPDynPage, sap plugins, PORTAL-INF/portalapp.xml, JSP)
    I'd want my JSP file in Project#2 to call some classes from the jar files of Project#1. 
    From my understanding, to do this I need to make a .par file out of Project #1 and then upload the par file to my SAP EP6.0 so that my future JSP's can import classes from it.  Am I correct?
    I am confused right now as to how to really do this.  On Netweaver, I am getting a Error when I try to do: File --> New --> Project --> Portal Application --> Create a Portal Application Project > I then enterProject Name: TestProject28, Project root folder: c:\TestProject\webapps\project1 
    --> "ERROR: Invalid project description, Reason:An error has occured while trying to create the project structure"
    If possible can you please provide detailed instructions on how to configure or build a par file out of my java web application stated above?
    Thank you so much for your time and help!
    Baggett

Maybe you are looking for

  • Getting 10.4 onto a G3 iMac w/o DVD drive

    So I'm having some Tiger taming trouble. I've been quite happy with my G4 iBook since I bought it; Tiger came with it, and I haven't made the Leopard leap, so it's running 10.4.11 with all current updates. I still have my old G3 iMac (Summer 2001 "Ki

  • How can i add Chinese language support to my N97

    Hi all of you!! i hope can some body help me i work in china and i bought my mobile from Dubai and it is just support Arabic and English so how can i add chinese support to my mobile?? i don`t want change product code beause i want arabic languge als

  • How to send a Row based in a view Object

    Hi, i has in the app module a method to insert but i want from the baking bean send a Row with the information but not function well ---this is my method in the app module public boolean CreaCliente1(Row row){ ViewObjectImpl vo =this.getClientesVo();

  • Update Plant in RFQ created with reference to a RFP.  - ME41 ME42

    Hi all, we're triyng to update field plant for RFQ (Request For Quotation)  that was created with reference to a RFP. We tryed updating T162 via SPRO to allow this, but was unsuccessfull. Does anybody know how to do this without an ABAPER?. Were runn

  • Reservation of the material

    hi all i have a scenerio here there is one manufacturing plant and 5 sales plants, the production sis make to stock.. and goods are send to different plants by sto here after production goods are stored in one storage location.. at this storage locat