Directive page import

pleze
can i import all packages in java api with directive page import ?
<%@ page import="anypackage" %>
or just some packages and if it , what are these packages can i import ?
thanx

The JSP import works just like a Java import. You can import everything in a directory, non-recursively.
E.g.:
<%@ page import="java.awt.*" %>
Gets all of the imports under java/awt/, e.g. "java.awt.LayoutManager". But if you need an AWT event, such as "FocusEvent", then you have to go down one more layer, e.g.:
<%@ page import="java.awt.event.*" %>
You can repeat the "page import" as many times as you need to import the classes you're using.
Hope that answers the question?

Similar Messages

  • Trying to page import directive in a JSP  access a class in default package

    I am trying to import a class the is in my default package directory for Tomcat 4.1.18 (context-root\web-inf\classes\*.java). I am getting the following error
    This is error using Tomcat 4.1.18
    org.apache.jasper.JasperException:Unable to compile class for JSP
    C:\Program Files\Tomcat4.1\work\Standalone\localhost\csc297\HTML\SearchByName_jsp.java:9: '.' expected
    import Product;
    C:\Program Files\Tomcat4.1\work\Standalone\localhost\csc297\HTML\SearchByName_jsp.java:10: '.' expected
    import Category;
    This is error using Tomcat 4.0.6
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    C:\forte4j\tomcat401\work\localhost\C_3A_5Cforte4j_5Ctomcat401_5Cwebapps_5Ccsc297\HTML\SearchByName$jsp.java:5: Class Product not found in import.
    import Product;
    ^
    C:\forte4j\tomcat401\work\localhost\C_3A_5Cforte4j_5Ctomcat401_5Cwebapps_5Ccsc297\HTML\SearchByName$jsp.java:6: Class Category not found in import.
    import Category;
    Here is snippet of code from my JSP:
    <%@ page import= "java.util.*"%>
    <%@ page import= "java.text.DecimalFormat"%>
    <%@ page import="Product"%>
    <%@ page import="Category"%>
    Remember these classes are in my default package of my context-root
    Any ideas would greatly appreciated

    Weird error. Never seen this one before.
    Try packaging your classes eg:package myClasses;and import them:<%@page import="myClasses.*"%>Should fix the problem.
    Anthony

  • JSP page import directive

    I'm running JSPs and servlets under Netscape (Tomcat) web server and am getting errors with my jsp file's first line:
    [%@page import="java.util.*, myclass" %]
    Netscape server throws an error saying that it can't import myclass. I've put the myclass.class file in various locations in the server but it still can't find it. Does anyone know a foolproof way to make the server find such a class when it's compiling jsp's?
    Thanks,
    David

    I think you have to specify package name of your class & not your calss name.

  • %@ page import="..." % does not seem to be working correctly

    Hi,
              I am running Weblogic 6.1 sp1 and I am having a problem with import page
              directive. <%@ page import="my.package.*" %> does not appear to be working
              correctly when I try to reference classes in imported packages (my.package,
              etc.) from the useBean tag.
              The following code works with Resin, but not Weblogic:
              <%@ page import="my.package.*" %>
              <jsp:useBean id="errorBean" class="ErrorBean" scope="request"/>
              If, I take out the page directive, and change the useBean tag to:
              <jsp:useBean id="errorBean" class="my.package.ErrorBean"
              scope="request"/>
              then the page compiles and runs just fine.
              Michael
              

    Here's a snippet from Sun's j2ee tutorial
              (http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPBeans4.html):
              <jsp:useBean id="beanName"
              class="fully_qualified_classname" scope="scope"/>
              But I agree with you, the excerpt you posted seems to include the
              useBean tag, which is misleading.
              Nils
              Michael Hill wrote:
              >
              > I don't think this is the way it is "supposed" to be. Here is an excerpt
              > from the JSP Syntax reference on http://developer.java.sun.com
              > on the page directive:
              >
              > import= "{ package.class | package.* }, ..."
              > A comma-separated list of one or more packages that the JSP file should
              > import. The packages (and their classes) are available to scriptlets,
              > expressions, declarations, and tags within the JSP file. You must place the
              > import attribute before the tag that calls the imported class. If you want
              > to import more than one package, you can specify a comma-separated list
              > after import or you can use import more than once in a JSP file.
              >
              > ---
              >
              > It says the packages are available to tags within the JSP file as long as
              > you place the import before the tag that calls the imported class. In my
              > case, I am placing the import before the <jsp:useBean> tag.
              >
              > Michael
              >
              > "Nils Winkler" <[email protected]> wrote in message
              > news:[email protected]...
              > > I'm pretty sure that you have to specify the fully qualified class name
              > > in the useBean tag. import won't help you here.
              > >
              > > Nils
              > >
              > > Michael Hill wrote:
              > > >
              > > > Hi,
              > > >
              > > > I am running Weblogic 6.1 sp1 and I am having a problem with import page
              > > > directive. <%@ page import="my.package.*" %> does not appear to be
              > working
              > > > correctly when I try to reference classes in imported packages
              > (my.package,
              > > > etc.) from the useBean tag.
              > > >
              > > > The following code works with Resin, but not Weblogic:
              > > >
              > > > <%@ page import="my.package.*" %>
              > > > <jsp:useBean id="errorBean" class="ErrorBean" scope="request"/>
              > > >
              > > > If, I take out the page directive, and change the useBean tag to:
              > > >
              > > > <jsp:useBean id="errorBean" class="my.package.ErrorBean"
              > > > scope="request"/>
              > > >
              > > > then the page compiles and runs just fine.
              > > >
              > > > Michael
              > >
              > > --
              > > ============================
              > > [email protected]
              ============================
              [email protected]
              

  • Include directive with import tags how to

    I mostly the same classes throughout many of my jsp pages. If I use the include directive to import the classes - it doesn't work. What is the proper directive / way / tag to include those tags? Sorry if I am not wording this properly. Here's an example:
    most of my classes use the following classes so I use the @import tag:
    <%@page import="web.urls.DisplayUrls"%>
    <%@page import = "web.beanObjects.display.DisplayPage"%>
    <%@page import="web.db.admin.TypesDbHandler"%>
    <%@page import="web.db.admin.CategoryDbHandler"%>
    I would like to put all of those in one file and only have one line of code so I don't have to cut & paste into every jsp page whenever there's a change:
    <%@include file="/include/imports.jsp"%>
    Unfortunately this isn't working, it's not recognizing the classes...
    Thanks!

    hi,
    since both the files are located in the same folder, why don't you try the following:
    <%@ include file="hello.jsp" %>
    hope this helps

  • A  classpath error while  importing a class with @page import property

    Hi ,
    I am using Tomcat contaniner for jsp applications. I have developed a page that i have import a class. when i use
    <%@ page import="myclass" &>
    i got an error that myclass not found. I have placed into tomcat\webapps\myproject\web-inf\classes directory. So How will I set the classpath for myclass to work?
    thanks.

    I was able to simulate your problem when I created a mismatch in the case of the name of the class.
    for example if my program is called MyClass.java
    and in the import I do <@page import="myclass" %>
    Are you sure about the case of class name that you are using? Please check that the file is called myclass.java the class defined inside it is called myclass and the class file that is copied into the WEB-INF/classes directory is also myclass.class. There should be no difference in the case of the names. like MyClass.java or MyclaSS.class
    Other things to check are
    1. If myclass is defined in a package then you have to import with the package.
    2. Make sure that your jsp is located in the myprojects directory and the class file is copied under myprojects/WEB-INF/classes.
    Let me know if things still don't work
    regards,
    Abhishek.

  • Jsp:useBean vs page import in JSP

    Hi,
    What is the difference between jsp:useBean vs page import in JSP?
    By using page import also I can call the method of the class, apart from jsp:useBean does have scope associated with it. I don't think there is any change between both the 2. Yes by using jsp:useBean we can set the property and get the property as well.
    Is there any major differences between the 2 and when to use which ? Please clarify.
    Thanks.

    797836 wrote:
    Hi,
    What is the difference between jsp:useBean vs page import in JSP?
    By using page import also I can call the method of the class, apart from jsp:useBean does have scope associated with it. I don't think there is any change between both the 2. Yes by using jsp:useBean we can set the property and get the property as well.
    Is there any major differences between the 2 and when to use which ? Please clarify.
    Thanks.Yes there is a difference.
    If you use import, then you have to create/use the reference object to use the class methods. And you can't define the scopes like session, page .. etc. Apart from this you will be using scriptlets <% %>.
    if you are using jsp:useBean , then you can skip the above activities. useBean takes care of it.
    or you can say jsp has provided a utility to access the beans without creating its object or using scriptlets.

  • JSP page import problems

    Hi,
    i've got a problem with importing java classes into my jsp file. i use the following method:
    <%@ page import="Person" %>
    Person is originally a selfwritten class which lies in the subdirectory WEB-INF/classes of my webapps directory of my tomcat server. when i use the above method i get the following error output:
    org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 125 in the jsp file: /ShowPersonsView.jsp Generated servlet error:
    [javac] Compiling 1 source file 3 3 /usr/local/tomcat/work/Standalone/localhost/address/ShowPersonsView_jsp.java:7: '.' expected
    import Person;
    ^
    /usr/local/tomcat/work/Standalone/localhost/address/ShowPersonsView_jsp.java:231: cannot resolve symbol
    symbol : class Person
    location: class org.apache.jsp.ShowPersonsView_jsp
    Person tempperson;
    ^ An error occurred at line: 125 in the jsp file: /ShowPersonsView.jsp Generated servlet error:
    /usr/local/tomcat/work/Standalone/localhost/address/ShowPersonsView_jsp.java:238: cannot resolve symbol
    symbol : class Person
    location: class org.apache.jsp.ShowPersonsView_jsp
    tempperson = (Person)it.next();
    ^
    3 errors at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:120)
    at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
    at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:313)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:324)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:184)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
    at ShowPersonsPrepare.doGet(ShowPersonsPrepare.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
    at java.lang.Thread.run(Thread.java:536)
    Thus, the Person class can not be found but i dunno why. Where do I have to make an entry? I already tried to set a classpath to this file, but it doesn't work. Has anyone an idea?
    Thanx

    Put the class in a package and call it accordingly. Example:
    WEB-INF
       |
        --- classes
               |
                --- example
                       |
                        --- Person.java
    //then in Person add:
    package example;
    //and in jsp
    <%@ page import="example.Person" %>

  • Page extends vs page import

    What is the difference between
              <%@ page extends="com.beasys.commerce.portal.admin.PortalJspBase"%>
              and
              <%@ page import="com.beasys.commerce.portal.admin.PortalJspBase"%>
              

    "Kenneth Lee" <[email protected]> wrote in message news:<3bebfe13$[email protected]>...
              > What is the difference between
              > <%@ page extends="com.beasys.commerce.portal.admin.PortalJspBase"%>
              > and
              > <%@ page import="com.beasys.commerce.portal.admin.PortalJspBase"%>
              On the terminology extends vs import:- First, your jsp is basically a
              servlet. Whether your servlet is a kind of another class (extends) or
              use (import) another class is up your requirement.
              In your case, in theory, it shouldn't make a difference. Why? Because
              PortalJspBase is like a utility "Singleton" class (seemed like most of
              the functions and variables are static)! Deriving this class would
              possibly save some coding effort. However, since you are making a
              portlet (aren't you?), making it to be a "kind-of" weblogic portlet
              means that you must derive (or in the Java world, extend) from the
              above.
              Only my 2 cents worth.
              Regards
              drit
              

  • Page Imports in Abstract Portal Component

    Hi,
    I have created an abstract portal component where I have called a JSP using IResource.
    The JSP is called and displayed.
    <%@ page import = "java.util.*;" %>
    <%@ page import = "com.sapportals.portal.prt.component.*;" %>
    <html>
    <body>
    hello
    </body>
    </html>
    In my JSP the moment I add the second import i.e. prt.runtime, it throws an error when I run the application:
    Error when rendering jsp.
    Am I missing out something?

    Hi Prem,
    Add that particular jar file in the lib folder of your application and also add it to the build path of your project properties.
    <b>Project -> Properties -> Java Build Path -> Libraries</b>
    Add to this build path as well.
    I hope this helps you.!!
    Regards
    Pravesh
    PS: Please consider rewarding points if solved and helpful.

  • Muse Website issue - I can't send direct page links to clients

    Hi all
    I would like to send my client a direct page link from my website so that they can view some photos I have taken for them. 
    The page is purposefully not listed on the site menu so that is has a low level of privacy.
    When I enter www.domain.com/photos.html on a browser I get a error 404 message back. I have also noted that when I look at the live website I only ever see www.domain.com on all the pages I navigate too. It never changes to show www.domain.com/intro.html for example.
    Insight would be greatly appreciated.

    Sounds like you haven't moved your domain name, but instead the Muse site is being presented inside a frameset that's hosted wherever your domain is. If you "View Source" on your home page you should not see any mention of "frameset". If you do, you'll likely also see the URL for where your site really is. If you use that domain name, probably xyz.businesscatalyst.com, the direct links will work fine. They'll also work if you really assign your domain to the site rather than just showing the new site's contents inside a frameset hosted somewhere else.
    Assuming you're hosting with Adobe Business Catalyst, see steps 5 and 6 here <Launching a Muse Site | Adobe Muse CC>.

  • Page Import

    Hello,
    I am trying to do a page import from application A to application B. The import seems to go fine until I run the page and I find that the page does not run because various issues have arose with the page i.e. no template defined for the page or any of the regions. Some of the issues with the page I can not figure out how to fix.
    The following process is how I did the page import.
    * export app. A
    * export app. B
    * import app. A over app. B
    * export pages from new app. B (really A)
    * import app. B
    * import pages into app. B
    Other Info:
    * both apps. are in the same workspace
    * HTML DB version 1.4.3.00.30
    Any help would be awesome!!! I have quite a few pages to import by COB tomorrow and not a lot of time fixing all of them.
    Thanks for your help,
    Paulette

    Paulette,
    It sounds like you used the procedure Raj described at Synonyms Please see the caveat at the bottom of that thread. It says:
    "I know you restated the caveat about shared components, but I don't think users will appreciate that that means templates, LOVs, tabs, authorization schemes, etc. won't be correct on the newly installed page. So to use this procedure for simple pages is probably more difficult that just recreating the page on the new instance. But using the procedure for complex pages will result in a complex page with a whole lot of stuff that doesn't work."
    If these are the problems that have arisen, they are an expected part of the procedure that you followed and you'll have to fix them manually by creating (copying) any shared components that are missing, e.g., templates, and hooking them up with the Builder.
    If the problems are something else, please let us know.
    Scott

  • @ page import=..... OR jsp:useBean id.....

    I'm a newbie in JSP, and I found uses <@ page import=.....> to run the java (*.class) is similar as uses <jsp:useBean id.....>, can anyone tell me what's the different between them??
    Thx a lot~

    I didn't find any necessary to use "import" tag before use "<jsp:useBean...>" when I used "Weblogic 5.1/6.0", "JRun 3.0/3.1". But I'm sure "Tomcat4.0" have to "import" first. Some documents showed the "import" tag was not necessary in "Tomcat" before version "4.0". I don't know the special feature from this version is good or not. Could someone tell me whether it's the future feature in JSP?

  • Page import trouble

    Hi and thanks for previous answers, but my page import trouble continues.
    I have now compiled a class, myBean.class and placed it in this folder ...
    ROOT/WEB-INF/classes/peters/beans/
    when I use ...
    <%@ page import="peters.beans.*" %>
    Tomcat finds the path, but using
    <%@ page import="peters.beans.myBean" %>
    a class not found exception appears.
    I can�t understand why, it it something wrong with the public/private properties in myBean?
    This is the syntax ...
    public class myBean
      ��private String sName="Pette";
       public myBean()
       public String getName()
         return sName;
    Thanks for any answers.
    Have a nice day / reg. PG

    Jippy, I found a solution!
    First I added the line - package pg; - to the testBean class and placed the file in ROOT/WEB-INF/classes/pg
    The I used the following jsp-tags in my .jps-file
    <%@ page import="pg.*" %>
    <jsp:useBean id="theBean" scope="page" class="pg.testBean" />
    /pg

  • Error on Page import

    I installed Oracle Portal 3.0.8.9.8 on Windows 2000.
    I am trying to import the page
    pageimp.cmd -s portal30 -p portal30 -o portal30 -m new -d d:\0p\csumb.dmp -c newdb
    and getting error:
    Start Portal Page Import
    Please Wait...
    declare
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "PORTAL30.WWUTL_POB_TRANSPORT", line
    1879
    ORA-01403: no data found
    ORA-06512: at line 6
    I got the same error trying to install MyCompany demo.
    Please help !!!!!!!!!!!
    null

    Can you provide some additional info? For e.g., what is the version of Portal from where you exported the page, What does the page contain, etc. Remember, export-import does not work in between versions i.e., you cannot export from 3.0.7 and import into 3.0.8

Maybe you are looking for

  • Can I watch videos on my iPad and browse at the same time?

    I want to watch a Ted talk that I downloaded and browse the internet, but everytime I try to leave iTunes it automatically shuts off what I'm watching. Can this thing seriously not do more than one thing at once? It seems odd. Same thing happens, if

  • Do I need a different back cover for wireless charging with the Droid Turbo?

    Do I need to get a different back cover for Qi wireless charging on the Droid Turbo?  Or do I just need the charging pad?

  • Splitting document question

    I am a machinist and have just received a bunch of drawings that are 55"x160" long (rediculous I know).  I would like to split and shrink the drawing to fit onto 3- 11"x17" pages.  I can crop and save and merge and resave, but does anyone know of an

  • Mirrored Raid Set

    I have two disks arranged as a mirrored RAID set and wonder how I will know when one of the disks fails and which one it is.

  • CSCud17778 - memory leak in middle buffers due to snmp traps

    The bug details list these as the conditions required to cause the symptom.  They don't specify whether these three conditions are an AND or an OR, but I'm assuming that all three must be satisfied: Conditions: 1) more than one snmp-server hosts are