JSP import statement problem

Hey, I got confused with all import statement with jsp.
Here is my problem.
Folder structure:
C:\Program Files\netbeans-4.1\enterprise1\jakarta-tomcat-5.5.7\webapps\ROOT\WEB\S\A
This folder contains a.jsp.
JSP code:
<%@ page
     language="java"
     import="java.sql.*, MyPackage.DataBase"
     errorPage=". . ."
     contentType="text/html; charset=windows-1251"
%>
<%
       Connection connection = null;
     Statement statement = null;
       DataBase dataBase = new DataBase( connection, statement );
%>
...Error message that I get:
org.apache.jasper.JasperException: Unable to compile class for JSP
Generated servlet error:
C:\Program Files\netbeans-4.1\enterprise1\jakarta-tomcat-5.5.7\work\Catalina\localhost\_\org\apache\jsp\WEB\S\A\a_jsp.java:7: package MyPackage does not exist
import MyPackage.DataBase;
                   ^
An error occurred at line: 104 in the jsp file: /WEB/S/A/a.jsp
Generated servlet error:
C:\Program Files\netbeans-4.1\enterprise1\jakarta-tomcat-5.5.7\work\Catalina\localhost\_\org\apache\jsp\WEB\S\A\a100_jsp.java:147: cannot resolve symbol
symbol  : class DataBase
location: class org.apache.jsp.WEB.S.A.a_jsp
       DataBase dataBase = new DataBase( connection, statement );
        ^
...How do I import that class so I can use it?
Do I need to use useBean?
What do I need to do?
Thanks

DataBase class does not extend java.sql.
I put this into my jsp page
     import="java.sql.*;"
     import="MyPackage.DataBase;" Here is the error message
Generated servlet error:
C:\Program Files\netbeans-4.1\enterprise1\jakarta-tomcat-5.5.7\work\Catalina\localhost\_\org\apache\jsp\WEB\S\A\a_jsp.java:7: 'class' or 'interface' expected
import MyPackage.DataBase;;
^
1 error
...

Similar Messages

  • JSP import Statement importing a Class File giving ERROR

    Hey guys,
    There is a problem to which I dont know the reason,
    Consider the code below:
    <%@ import Converter, ConverterHome %>
    It gives me a Compile Time error of this type:
    '.' Required in import Converter ;
    but when i put these classes in a package suppose "converter"
    and the above import statement like this :
    <%@ import converter.Converter,converter.ConverterHome%>
    It gives me no error
    So whats the reason behind this? Cant I compile a JSP program by refrencing classes without in any package?
    please Reply
    Thanks in advance..

    So whats the reason behind this?
    Cant I compile a JSP program by refrencing classes without in any package?No, I do not beleive you can, is you are using Java 1.4. In 1.4, you can only reference classes in the Default Package (none) from other classes in the default package. If you are in a package, then you can not import from the default package. And this is for ALL java classes, not just JSP and Serlets. Since the JSP servlet would be part of a package (which depends on the server you are using) you will need to put your classes into packages to import them...

  • Java import statement problems

    Hello...
    I have the book "Java in a Nutshell, 2nd ed" and have a query about a nested top-level interface example they have in the book.
    Basically there's two files/classes. The first, LinkedList.java, is as follows:
    public class LinkedList {
        public static interface Linkable {
            // Linkable interface details here
        // rest of LinkedList class here
    Next is LinkedList.java as follows:
    import LinkedList.*;
    class LinkableInteger2 implements Linkable {
        // rest of LinkableInteger2 class here
    Now I thought the import statement had two forms - and both used a package name as part of the statement:
    import package.class;
    import package.*;
    Obviously, neither class has a package statement.
    As written, these classes do not compile. Am I right in assuming the lack of a package name is causing this problem, or is there something else going on here?
    Thanks...
    Mark.

    Since you don't have package statements in the files, the classes are being placed in the default package. You cannot explicitly import classes from the default package. Al classes in the default package, the java.lang package and the current package are always imported automatically. Your import statement is incorrect - remove it.

  • 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

  • Weird import statement problem

    Hi
    I have a strange problem with an application I just developed. Once compiled, if I try to run it on another machine other than the one I developed on, I get a NoClassDefFoundError relating to a class that I did not use. I look at the class file (in a decompiled state) and there is an import statement in there that is not in the source file!! Can anyone tell me why this might have happened?
    the import is a symantec class/package I have never used to my knowledge at all and yet it shows up in the binary class file after compilation.
    Thanks for any suggestions.

    I did use Visual Cafe during parts of the development but I have never imported anything like what is in the class file. I assumed it was VC that was doing it but wasn't sure.
    Thanks.

  • Package-import statement problem: Part II

    Hello again everyone...
    It seems all of you have mistaken my original problem to some degree. The beginning part of my DataAddingTest.java file reads like this:
    // This class tests adding data to the data structures in my Risk(c) game.
    package risk.tests;
    import risk.*;
    DataAddingTest.java is in my C:\Java\risk\tests\ directory. I am trying to import a whole bunch of files from my main risk directory, i.e., C:\Java\risk\. And it is just not working. I have no idea why. I'm pretty sure I have the correct syntax for what I'm doing; it should work. The exact error message I get at compile-time is this:
    DataAddingTest.java:5: package risk does not exist
    import risk.*;
    ^
    There is indeed a C:\Java\risk\ directory (of course), and it contains many java files, all of which have "package risk;" declared at the top. And yes, I have also compiled those before I try to compile this file. Someone please help! Thanks for everyone's time.
    -Billy Mahabir
    PS. Reply to http://forum.java.sun.com/thread.jsp?forum=31&thread=392985
    to earn some Duke Dollars for your trouble; if you can help me.

    Thank you for your help; you are the first one to
    successfully help me. I'll give you some DD's if you
    reply to my original post:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=39
    985
    Thanks again!
    -Billy MahabirHuh??
    Maybe you should go back to your original post and check the last two replies.
    Both tell you to do exactly that: Set your classpath!

  • Package-Import statement problem

    Greetings JDC Community...
    This problem has been driving me insane for over an hour. It's a simple package-import problem. I have a file called DataAddingTest.java which is in my C:\Java\risk\tests\ directory and it has a package statement "package risk.tests;". Then I try to import all of the files I have in the risk directory by using "import risk.*;" and it whines in error that "package risk does not exist". I'm about ready to throw my computer... can someone help me? Thanks for your time.
    -Billy Mahabir

    Hello again everyone...
    It seems all of you have mistaken my problem to some degree. The beginning part of my DataAddingTest.java file reads like this:
    // This class tests adding data to the data structures in my Risk(c) game.
    package risk.tests;
    import risk.*;
    DataAddingTest.java is in my C:\Java\risk\tests\ directory. I am trying to import a whole bunch of files from my main risk directory, i.e., C:\Java\risk\. And it is just not working. I have no idea why. I'm pretty sure I have the correct syntax for what I'm doing; it should work. The exact error message I get at compile-time is this:
    DataAddingTest.java:5: package risk does not exist
    import risk.*;
    ^
    There is indeed a C:\Java\risk\ directory (of course), and it contains many java files, all of which have "package risk;" declared at the top. And yes, I have also compiled those before I try to compile this file. Someone please help! Thanks for everyone's time.
    -Billy Mahabir

  • Import statement problem

    I am getting this error message:
    Generated servlet error:
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\OBJAVA\WEB\a100_jsp.java:8: package MakePosting does not exist
    import MakePosting.*;
    Where do I need to place my classes?
    How does the folder structure should look like in tomcat?
    Thanks.

    Your web-application should have a WEB-INF directory and a classes directory inside that. All classes should be placed in the classes directory.
    Here is the link -http://jakarta.apache.org/tomcat/tomcat-5.5-doc/appdev/deployment.html - on the organization of your directories in a j2ee web application.
    cheers,
    ram.

  • JSP and Tomcat Problem

    Folks,
    My apologies if this is off-topic for this forum, but I've been having this problem using Tomcat and JSP. I'm fairly new to Java.
    Basically, I'm writing a webapp that uses servlets and JSP together. The servlet and backend classes all compile fine. Now, basic frontend page is called Console.jsp, and one of the commands that it runs is <%@ page import="DJUser">
    Here's the problem: Console.jsp is in $CATALINA_HOME/webapp/
    DJUser (and the rest of the classes I'm using) are in $CATALINA_HOME/webapp/WEB-INF/classes
    When I attempt to run Console.jsp I get this error:
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSP
    Generated servlet error:
    The import DJUser cannot be resolved
    An error occurred at line: 9 in the jsp file: /Console.jsp
    Generated servlet error:
    DJUser cannot be resolved to a type
    An error occurred at line: 11 in the jsp file: /Console.jsp
    Generated servlet error:
    user cannot be resolved
    An error occurred at line: 11 in the jsp file: /Console.jsp
    Generated servlet error:
    DJUser cannot be resolved to a type
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    The ROOT CAUSE is listed as:
    java.lang.ClassNotFoundException: org.apache.jsp.Console_jsp
         java.net.URLClassLoader$1.run(URLClassLoader.java:200)
         java.security.AccessController.doPrivileged(Native Method)
         java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:133)
         org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:65)
         org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:596)
         org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:137)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    I'm running Tomcat 5.5.12 on Mac OS X 10.4. Could this be a permissions issue somehow? For right now (testing purposes only) I have tomcat running under my (non root) account.
    I've been scouring the web for a while, and I can't really find anything on this. I'd appreciate any help you could give me.
    Thanks!
    Dylan

    Put the DJUser java file in a package (say com.myClasses) and recompile. Then put the DJUser class file under the WEB-INF/classes directory in the proper package structure (WEB-INF/classes/com/myClasses/DJUser). Stop and restart the server to pick up the new classes. Make sure to change the jsp import statement ( <%@ page import="com.myClasses.DJUser">)

  • Jsp declaration and import statement

    Hi All
    I have some problems with JSP.
    I have wrtten a declaration in jsp like this.....
    <%@ page language="java"%>
    <%!
    Date date = new Date();
    List al new ArrayList();
    public List getList(){
    al.add("Hi");
    return al;
    %>
    The List is-> <%= getList()%>
    Note that i did not import anything, it gives the output without any compile time/runtime error. How it is happening?
    If i write any thing in scriplets.......like List, Date, it is giving compile time error asking to import this.
    I am using weblogic8.1
    May i get the correct answer for this ASAP?
    Thanks and Regards
    Kasim
    [b]

    weblogic includes certain import statements in the JSP page when it is compiled.
    That is why u r not getting an error some times!!
    Check your weblogic documentation to find more details abt that
    But it is better to include the import statements , so the code will work in any server.

  • Import statement in JSP

              Hi
              I am maintaining a system done by one of our vendors.
              Application is deployed in WLS 7.0.
              When I imported the Jsp's into my IDE , I got errors where java.util classes are
              used in the JSP's and the import statement is missing.
              Most of the Jsp's are like this,
              It is working fine in the production server.
              In the IDE i am forced to put the import statement and that is what I expect.
              But how can it work in the production server without any issue.
              Can someone advise me on this
              Thanks
              DN
              

    <%@page import="java.util.calendar" %>
    Oops... forgot the "page" in there ...That's what I get for using GUI's too much!!! :)

  • Import statement in .java files and .jsp files

    Guys I have few mysteries about this import statement.
    Please correct me if I am wrong.
    1)Suppose if I have a folder c:\SourceFolder it has one.java and two.java files.If I compile one.java then one.class files is created in c:\ClassFolder .Now two.java uses one of the method of one.java,and without using import statement I am able to compile two.java, and two.class file is created in c:\ClassFolder.I assume that the path of one.class was taken from the CLASSPATH environment variable,hence I there was no need for import statement .........am i right ?
    BUT... in My.jsp,which is in C:\JspFolder, if I want to use one.class,then I have to specifically import the class I want to use.That is i have to say
    <%@page import="one"%>
    and since the classpath is C:\ClassFolder ,it finds one.class in the C:\ClassFolder.(Note that My.class is created in a folder different from c:\ClassFolder )
    But I am wondering why was there no need for me to import one.class in two.java.
    (Note I am using JDeveloper and Apache server)
    Please help.
    In this case the pSo I am wondering in JSP why it doesn't take the class I am looking for from the classpath .
    Help.

    You have to understand Java scoping rules. In the 1st scenario with the two Java files I am guessing neither one of them begins with a package statement. This means that they belong to the default package. When you compile the compiler uses the classpath to resolve method calls looking in the default package since there was no import statement specified in two.java. JSP is a little different. Now I just read this here in these forums a couple of days ago. Since the classfiles generated from the JSP files are not in the CLASSPATH they are loaded by a different classloader. This is why you have to import all references to all classes in the default package.

  • Import statement in .java files and .jsp files ..correction

    Guys I have few mysteries about this import statement.
    Please correct me if I am wrong.
    1)Suppose if I have a folder c:\SourceFolder it has one.java and two.java files.If I compile one.java then one.class files is created in c:\ClassFolder .Now two.java uses one of the method of one.java,and without using import statement in two.java I am able to compile two.java, and two.class file is created in c:\ClassFolder.I assume that the path of one.class was taken from the CLASSPATH environment variable,hence I there was no need for import statement .........am i right ?
    BUT... in My.jsp,which is in C:\JspFolder, if I want to use one.class,then I have to specifically import one.class in My.jsp .That is i have to say
    <%@page import="one"%>
    in My.jsp.
    and since the classpath is C:\ClassFolder ,it finds one.class in the C:\ClassFolder and MyJsp is compiled sucessfully.(Note that My.class is created in a folder different from c:\ClassFolder )
    But I am wondering why was there no need for me to import one.class in two.java.
    (Note I am using JDeveloper and Apache server)
    Please help.

    It has to do with packages. Most java classes are in a package, the name of which must conform to its place on the filesystem relative to the classpath. By that I mean that if you have com.mystuff.One.java, it must be in a folder com/mystuff where com is located somewhere in the classpath.
    What you've done is a little different. I'm assuming a couple of things:
    1. you have no package declaration at the top of one.java or two.java
    2. you have the current directory "." in your classpath.
    Java has the concept of the "default package", which covers classes without a declared package, and in your case is the current directory.
    So when you're in c:\sourcefolder and run the compiler, then "."="c:\sourcefolder", and that directory is part of the default package. No import statements are necessary for classes that are in the same package. This is why two.java can call methods in one.java without an import statement.
    When you run your jsp, the "current directory" part of your classpath is not c:\sourcefolder, but some other value (probably the directory you start your jsp engine from) You will have to import all non-java-library classes because the jsp itself becomes a java class, with a package that is determined by the jsp engine.

  • Import statement in a JSP

    How do you write an import statement in a JSP? I did this but it isn't working...
    <%!
    import="java.util.Calendar"
    %>
    Thanks.
    P.S. - I got a dog on Saturday!

    <%@page import="java.util.calendar" %>
    Oops... forgot the "page" in there ...That's what I get for using GUI's too much!!! :)

  • Which one better to use - jsp:useBean or import statement

    Hi,
    I just want to know that which one is better to use jsp:useBean or import statement .
    I can instantiate and call method of myclass -
    1) by importing the class through import tag in jsp as <%@page import="myclass"%. or
    2). by using <jsp:useBean tag....
    i have these two option to do the same thing. i know that basically useBean is used to call setter and getter method of bean class and but it can be used to call a normal java file that have some logic .
    so what should i used , which one is better and why?
    useBean provides scope and object instance so no need to create object by new operator. and with import you have to create an instance .
    but which tag should i use in my jsp?
    i am confused???

    ok, means i can use jsp:useBean tag for all my
    classes that are not actually bean. so it will be
    instantiated at run time and provide efficiency .No. Jsp:useBean is used for java bean components.
    >
    but when should i use import statement in my jsp and
    it happen at translation time so will it create any
    type of burden for my code if i import multiple
    classes.For non-java beans, you need to import the classes, period.
    It's not a burden, it's a necessity.

Maybe you are looking for

  • Is there a way to get rid of iOS 5.0.1 on the iphone 4s

    I just got my phone and the first day my battery ran awesome then i did the update and now its draining my battery. Is there a way to just get rid of the update? Like should i do a restore on my phone and just not use icloud and start off brand new,

  • Question about Dates in Project View

    I usually have no problems when it comes to date metadata, changing dates if need be, batch changes, etc... But this is something that is confusing me and I haven't been able to solve it. My wife found one of her old PAS digital cameras, and it had i

  • HT5622 How to verify an apple id

    How to verify a apple id

  • Where to load thin driver

    where do you load the thin driver in a machine with oracle8 enterprise version and how do you call the driver in the program

  • Dumps generting due to background job failing

    Hi Experts, The following backround job getting failed frequently caused dumps generation, Background running with the below program, Dump:: Can you please some one help me on this issue. Rgds, Venkat