Jsp :: Importing Classes
I have followed a jsp tutorial with regards to a simple set of scripts.
I have stored a class in the /cyb/WEB-INF/NameHandler folder that is called NameHandler.class
When I call the import statement in the index.jsp file:
<%@page import="hello.NameHandler"%>
I get the following error:
"Only a type can be imported. hello.NameHandler resolves to a package"
After some research, I have ensured that the NameHandler is compiled, and stored in the apprpriate WEB-INF/Classes/NameHandler directory within the tomcat system.
Does this have anything to do with the tomcat's classpath directive?
I am using a windows xp platform.
Edited by: Cyberconian on Feb 11, 2009 4:49 AM
Hi,
Your class name is NameHandler and you are trying to import the class in your JSP page as hello.NameHandler.
Syntax of page directive to import the class in JSP looks fine (still use spaces, like <%@ page import="java.util.*" %>). Please make sure hello.NameHandler (hello is the package) class is available in WEB-INF/classes directory of your context root.
Thanks,
Mrityunjoy
Similar Messages
-
Error when I import classes using directive JSP page
Hi all!
I have installed JDeveloper 11g (11.1.1.3.0)
My applications are located in the C:\dir (JDEV_USER_DIR = C:\dir)
I Created application "Appliation1". In it i created 2 projects (Project1, in it beans session entity and other java classes; Project2, in it JSP).
I want import classes from Project1 to Project2 using next directive:
<%@ page contentType="text/html;charset=windows-1252"
import="project1.*"%>
so in Project properties of Project2 set the way to classes in Project1.
When i run JSP an error occurred:
Error(4,9): The import project1 cannot be resolved
Maybe i'm not set correctly the way to the classes
Thanks in advance.angelr, thanks, it helped me)
In jdeveloper 10g i set address in Project Properties->Libraries and Classpath->Add JAR/Directory;
and set the way to my classes;
and it worked.
in the 11 version seems different -
Problem importing classes and beans
Hey there. Im having one major fustrating problem! When I code supporting classes and beans for my JSPs I get a code 500 internal server error when trying to import (via <%@ page import="class" %> and <jsp:useBean/>) Im storing my classes and beans in the WEB-INF folder and the calling JSPs are located in /ROOT/tests/8/jsp.jsp. Im using the following to import a class or bean:
<%@ import="aClass" %>
Seen as tho its in the WEB-INF folder I won't have to explicitly refer to where the class is located, just the class name.
I never had this problem when I was using my hosting service. Its only on my localhost server in which I get the Internal Server error.
Help appreciated, thx.
PS: Im quite new to JSP/Java Servlet.import (via <%@ page import="class" %> and
<jsp:useBean/>) Im storing my classes and beans in the
WEB-INF folder try put your class file in WEB-INF/classes.
or first put bean in the package, like WEB-INF/classes/packagename/beanclass
in jsp page:
<jsp:useBean id="Mybean" class="packagename.beanclass" scope="request" />
Question: is /ROOT a context entry in your server.xml?
Which JSP Container (version) you use? Maybe your localhost server's set up is different with your hosting. -
Error wile importing class file
hi,
i am trying to import a class file(exp) in jsp, but it gives error mesg like unable to find the class file. the code is
class file is plcaced in "C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes"
<%@ page language="java" import="exp" %>
<html>
<body>
<%! test t = new test(); %>
Length of Sabarish is <%= t.strLength("Sabarish") %>
</body>
</html>kindly helphai,
try placing ur class in a package and provide fully qualified class name in jsp import
hope this will help
regards,
varma. -
Jsp import package error after upgrading to jdk1.4.2_08 and tomcat 5.0
I am trying to upgrade the jdk and tomcat from 1.3/3.3 to 1.4/5.0.
My jsp imports worked fine prior to the upgrade, but now I get the following:
Jun 6, 2005 10:01:17 AM org.apache.jasper.compiler.Compiler generateClass
SEVERE: Error compiling file: /C:/Tomcat/work/Catalina/localhost/Print//org/apac
he/jsp\BillingPrompt_jsp.java [javac] Compiling 1 source file
C:\Tomcat\work\Catalina\localhost\Print\org\apache\jsp\BillingPrompt_jsp.java:11
: package com.adware.print.database.inquire does not exist
import com.adware.print.database.inquire.*;
^
1 error
A fatal error has occured for user: Unable to compile class for JSP
Generated servlet error:
C:\Tomcat\work\Catalina\localhost\Print\org\apache\jsp\BillingPrompt_jsp.java:11
: package com.adware.print.database.inquire does not exist
import com.adware.print.database.inquire.*;
The package in the import statement "import com.adware.print.database.inquire.*" actually has no classes in it. The classes are contained in "import com.adware.print.database.inquire.controller.*". If I change the import statement everything works. The problem is that I have 100s of jsps. If there is a work-around outside of changing the import statements, that would be best.
Can anyone help? Thanks.do you know what url is being looked up? the message is complaining that the url is starting with the string "an]", which seems pretty bogus.
-
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,
BaggettHi 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 -
JSP import fails unless Jars are included in the PAR
Hello,
We have a simple EP6 iView for displaying the Universal Worklist entries (UWL) using a JSPDynPage.
We import the UWL library symbols and compile/use them in the Java code without problems (e.g. import com.sap.netweaver.bc.uwl.Item; )
The following entry is made in the portalapp.xml file to make sure the UWL symbols are found at runtime:
<property name="ServicesReference" value="SAPJ2EE::library:tckmcbc.uwl~api"/>
The problem occurs when we try to import the UWL symbols into our JSP with this code:
<%@ page import="com.sap.netweaver.bc.uwl.Item" %>
The UWL symbols are just not found. Here are the exception headers:
#1#com.sapportals.portal.prt.component.PortalComponentException: Error in service call of Resource
Component : pcd:portal_content/MikesFolder/com.lds.mlp.MikesTest1
#1#com.sapportals.portal.prt.servlets_jsp.server.compiler.CompilingException: Error occurs during the rendering of jsp component
Caused by: com.sapportals.portal.prt.servlets_jsp.server.compiler.CompilingException: D:/usr/sap/EP1/JC00/j2ee/cluster/server0/apps/sap.com/irj/servlet_jsp/irj/root/web-inf/portal/portalapps/mikestest1/work/pagelet/_sapportalsjsp_helloiviewpage.java:22: package com.sap.netweaver.bc.uwl does not exist
import com.sap.netweaver.bc.uwl.Item;
^
1 error
Now if I add the bc.uwl.service.api_api.jar into PORTAL-INFlib everything is fine. However this seems like such a 'hack'. We really shouldn't be distributing a system file in our PAR.
This person seems to have had the same problem with the system mail jars ( JSP MAIL ERROR ).
Can anyone please shed some light on this problem? Do we really have to distribute the system jars to make this JSP import work properly?
Thanks & Cheers,
Mike Pastor
"always generous with points"Hi,
This is exactly the portalapp.xml of the sap application com.sap.netweaver.bc.uwl.par
check out the difference between this and yours?
Dont miss out on anything important here. I think it should work.
If you are still facing problem only while using in jsp I have a cure.
Write a clean java class in your app which queries the apis in this jar.
Also add sharing reference to this application in your portalapp.xml. Query your class in your jsp rather than the "standard jar"
<?xml version="1.0" encoding="utf-8"?>
<application>
<registry>
<entry path="/runtime/hooks/deployment/UniversalWorklistDeploymentHook" name="UniversalWorklistDeploymentHook" type="service"/>
</registry>
<application-config>
<property name="startup" value="true"/>
<property name="releasable" value="true"/>
<property name="ServicesReference" value="SAPJ2EE::library:tckmcbc.uwl~api,SAPJ2EE::service:webdynpro,com.sap.portal.runtime.system.inqmy, com.sap.portal.ivs.connectorservice,com.sap.portal.ivs.systemlandscapeservice, urlgenerator, com.sap.portal.usermapping, usermanagement, com.sap.portal.runtime.application.rfcengine,com.sap.portal.runtime.config,knowledgemanagement"/>
<property name="PreservedConfigPaths" value=""/>
<property name="Vendor" value="sap.com"/>
<property name="SecurityArea" value="NetWeaver.KMC"/>
</application-config>
<components/>
<services>
<service name="com.sap.netweaver.bc.uwl" alias="UniversalWorklistService">
<service-config>
<property name="className" value="com.sap.netweaver.bc.uwl.core.portal.UWLPortalService"/>
<property name="classNameFactory" value=""/>
<property name="classNameManager" value=""/>
<property name="poolFactory" value="0"/>
<property name="startup" value="true"/>
<property name="SafetyLevel" value="low_safety"/>
</service-config>
</service>
<service name="UniversalWorklistDeploymentHook">
<service-config>
<property name="className" value="com.sap.netweaver.bc.uwl.core.portal.UWLDeploymentHook"/>
<property name="classNameFactory" value=""/>
<property name="classNameManager" value=""/>
<property name="poolFactory" value="0"/>
<property name="startup" value="true"/>
<property name="SafetyLevel" value="low_safety"/>
</service-config>
</service>
</services>
</application> -
i just installed tomcat 4.1.18 and pretty much copied over all my applications and did the configurations in the server and web files...the only problem i noticed was that importing classes not part of the java libraries throws a jsp init() exception.
is the syntax still the same:
<@page import ="java.util.*,MyJavaBean" %>
in this case it complained about the MyJavaBean as an unrecognizable object, however it is in the WEB-INF/classes folder for this app. This syntax works for tomcat 4.0.1Hi,
As I know in Tomcat 4.1.x you have put your classes into packages. Putting the classes into WEB-INF/classes directory is not enough. You should try the following:
1. create a directory test under WEB-INF/classes directory and put your MyJavaBean class into this directory.
2. add the following line to the top of your MyJavaBean.java
package test;
3. Compile as : javac test/MyJavaBean.java
Try this...
nurettin -
Hi , i have created a class called cookiecheck and have placed it in the / web directory of my tomcate context and i would like to import it. how should my import command look. at this moment it looks like this, import cookiecheck; ,but this does not work ,please could you tell me what i am doing wrong.
but when i upgraded one of the jsp tries to import a
class (that does not have a package)
eg: import site
complains that there is no site.*
any helpThat's the key. Once again, (since Java 1.4) you cannot import classes which do not belong to a package. Creating classes with no package has always been discouraged and since 1.4 that discouragement is even stronger. Refactor. -
Error in JSP : Ambiguous class
In application i am getting following error :-
Error in JSP, Ambiguous class: java.beans.Statement and java.sql.Statement
here java.beans package is not imported still it gives error.
if i write java.sql.Statement then it works fine.
Code is as follows :-
<%@ page
language="java"
import="java.sql.*"
%>
<%
String a="Hello World";
out.println(a);
Statement st = null;
%>
Regards
RahulHi Rahul,
Someone had a similar question in another java newsgroup and there
someone explained that "java.beans.*" is added to the imports in the
generated Java file by the jsp container. Thus it seems to be an
implicit import so as you already figured out you need to write the full
path name to make it unambigous.
Regards,
/Helena
Rahul wrote:
In application i am getting following error :-
Error in JSP, Ambiguous class: java.beans.Statement and java.sql.Statement
here java.beans package is not imported still it gives error.
if i write java.sql.Statement then it works fine.
Code is as follows :-
<%@ page
language="java"
import="java.sql.*"
%>
<%
String a="Hello World";
out.println(a);
Statement st = null;
%>
Regards
Rahul -
Error in compiling: file javax\servlet\jsp\PageContext.class not found
Hi,
i'm getting an error when I'm trying to compile an java file. The error is as follows:
cannot access javax.servlet.jsp.PageContext
file javax\servlet\jsp\PageContext.class not found
Isn't the javax package included in jdk? I've installed jdk 1.3.1_03 and j2re1.4.0_02. Shouldn't this PageContext.class be automatically loaded when i've installed jdk?
I'm getting desperated! I've tried almost everything: i've changed the classpath, moved the directory of the java file I'm trying to compile over and over but i'm getting no success!
Any help is very welcome!
Thankx,
Nuno.hmmm... i had a look and it seems that what you are trying to "import" is actually in a package... instead of import try:
package javax.servlet.jsp;you may need to go download this "package" and complile it in the directory you are working in.
my advice: try the above statement (which does compile for me), if it doesn't work, you will need to find the source code for this package and compile it just like you do any other source code.
hope this helps. -
How to convert JSP Compiled class file back to JSP
Is their any way to convert the JSP converted class file back into JSP file, I have few JSP files missing in my application but i do have class files deployed corresponding to the JSP file. Is their any way where i can convert my JSP class file back to JSP. I tried used decompliers but it conerts the class file into JAVA files, Is their any such decompiler that converts the JSP converted class file into Java files.
Thanks in Advance.nope...its not et al possible...!!!
You cant convert class file back to JSP....!! -
I was reading the tutorial on importing class's. This is what
I read
Importing classes
To reference a class in another script, you must prefix the
class name with the class's package path. The combination of a
class's name and its package path is the class's fully qualified
class name. If a class resides in a top-level classpath
directory--not in a subdirectory in the classpath directory--then
its fully qualified class name is its class name.
To specify package paths, use dot (.) notation to separate
package directory names. Package paths are hierarchical, where each
dot represents a nested directory. For example, suppose you create
a class named Data that resides in a com/xyzzycorporation/ package
in your classpath. To create an instance of that class, you could
specify the fully qualified class name, as shown in the following
example:
var dataInstance = new com.xyzzycorporation.Data();
My Question is about com/xyzzycorporation/ . would the full
class parth be c:/com/xyzzycorporation/ . Why do they never state
the drive letter when teaching about directories.Because there is no need. you don't need to reference the
drive letter.
Here's the basic jist of what they are saying....
Single Class File...
If you create your own custom class and want to use it in
your flash file, save it into the same directory as the fla file
and call the classes constructor. By default flash will look inside
the folder where the fla resides in for the class files if it
cannot find it inside the default directory.
Multiple Class Files - 1 Project (often referred to as
packages)
Use your qualified domain name but backwards.....
my domain is www.sd-dezign.com so if I was going to include a
package of utility class files in my document I would do the
following
Create a folder in the same folder with my fla name it com
and inside that a folder called sddezign and inside that utils and
all my as files would be in there...the folder structure might look
like this....
myfile.fla
com
>sddezign
>>utils
>>>box.as
>>>circle.as
To call the constructor for each class, I have two options.
The first which is by far the easiest looks like this
In whatever frame you need to call that class constructor
include "com.sddezign.utils.*";
var myBox:Box = new Box();
The second method requires more typing and can get tedious
var myBox = new com.sddezign.utils.Box();
Hope this helps you a bit better. -
Not allowed to import classes without package names?
Hi,
I have a few questions on Packages and importing?
1. Is the following true that it is illegal to import classes in the same package as the current class, will this cause a comilation error? If this is the case where in the Java Language specification is this actually written as I could not find it?
2. This has probably been answered by question 1 but if I have 2 classes in the same package and if I import 1 of the classes into the other class, is it illegal to import it by just using the class name and not the package name as well, ie
if the package name is ie.tcd
and the 2 class names are exp1.class and exp2.class, can I do this in class 2
package ie.tcd;
import exp1;
public class exp2 {
3. Is it illegal to import classes that are not explicitly part of any package or must a class be part of a package to be imported. I read somewhere that while this was always illegal it is only after jdk 1.4.2 that this is being enforced? If this is the case where in the Java Language specification is this actually written as I could not find it either?
Thanks very much for any help,
JohnWas just also wondering, 1 other thing, I am looking
at someone elses code they have 2 classes (Class A
and Class B) in the same package (pkg). The person
imports class A into B:
package pkg;
import A;
public class B {
Is this legal code (or was it ever)?Not if A is really in pkg.A. If there is an A in the unnamed package it was legal, or at least it was understood by the compiler, and now it isn't (to both).
Can you import or is there a point in importing a class in the same
package?Only by naming the package in the import statement. If the current and the import statement are in the same package the import is redundant.
If there is a point would you import just be
using the class name (this would be illegal after jdk
1.4) or should you use the whole package name even
though it is in the package anyways?As I understand it you must always use the whole package name in imports. -
Compilation Error for import classes not found in generated Proxy Class
Hi,
We are generating java classes for the COM dll using JCOM com2java compiler.
We are getting a compilation error for import class not found when compiling the
generated Proxy java source code. It can't find the com.bea.jcom.Dispatch class that
the generated Proxy java source code extends. It also can't find com.bea.jcom.Variant
or com.bea.jcom.Param. These are interfaces or data types or classes used by COM
library.
I added weblogic.jar to my class path and the only Dispatch class i found inside
the weblogic.jar is com.linar.jintegra.Dispatch;
We have com objects for which we want to develop an EJB client to interface with
the COM object using JCOM with Native Mode disabled.
Any help on the compilation error..I tried changing the extends for Dispatch to com.linar.jintegra.Dispatch
but the other errors are still there.
To begin with, I think the generated code should not refer to any of the COM data
types.
Any help please.
Thank you in advance,
Regards,
Rahul Srivastava
[email protected]Hi,
I resolved the other errors by changing all references from com.bea.jcom.Variant
etc to com.linar.jintegra.class name..all were present under the com.linar.jintegra
package.
Thank you all anyways,
Regards,
rahul
"Rahul Srivastava" <[email protected]> wrote:
>
Hi,
We are generating java classes for the COM dll using JCOM com2java compiler.
We are getting a compilation error for import class not found when compiling
the
generated Proxy java source code. It can't find the com.bea.jcom.Dispatch
class that
the generated Proxy java source code extends. It also can't find com.bea.jcom.Variant
or com.bea.jcom.Param. These are interfaces or data types or classes used
by COM
library.
I added weblogic.jar to my class path and the only Dispatch class i found
inside
the weblogic.jar is com.linar.jintegra.Dispatch;
We have com objects for which we want to develop an EJB client to interface
with
the COM object using JCOM with Native Mode disabled.
Any help on the compilation error..I tried changing the extends for Dispatch
to com.linar.jintegra.Dispatch
but the other errors are still there.
To begin with, I think the generated code should not refer to any of the
COM data
types.
Any help please.
Thank you in advance,
Regards,
Rahul Srivastava
[email protected]
Maybe you are looking for
-
I've updated the software on my Macbook to the most recent version; regretting it now; and iPhoto has now become the Photo's app. The problem is I can no longer back up my photo and video files taken on my phone, saved to my mac, by copying them and
-
Samsung HD LCD. Purple dots after powering on
Samsung LCD. HD, Direct TV.. Hit the power button on the Direct TV remote, TV makes the beeping noises like it's turning on.. Nothing. Try again, picture comes up, but has purple dot pixels on the screen. Power off, turn on again and it's fine.. any
-
The pages are also jumbled up when I get to near the end of the book, very frustrating!!
-
Macbook Pro Retina I7 Cant install a purchased Mountain Lion in Israeli app store
I bought the new Macbook pro with Retina display, now a while ago i purchesed the Mountain Lion for my previous version Macbook pro (mid 2010). when i try to download the Mountain Lion now, it says that it cannot be installed on this mac? i am in the
-
MacBook Pro will not shut down correctly
When I try to shut down my MacBook Pro, it'll shut down then start up again. However, when the login comes up after it has started up, I press "Shut Down" and it works perfectly. Why is it doing this?