Importing classes into a jsp

I have created a class file called BindListener.java and put it in my root directory in my web module. I cannot however get the import statement for the jsp right, my root directory is called JBuilder. I have tried putting it in the WEB-INF classes folder also but still when I try to execute thr jsp it dosent work.
There is no package declared in the classs file and it does not extend any other class, however it implements the HttpSessionBindingListener interface.
I can call servlets from my JSP in the WEB-INF classes dir using /JBuilder/ServletName
I am mondo confused please help

I have created a class file called BindListener.java
and put it in my root directory in my web module. I
cannot however get the import statement for the jsp
right, my root directory is called JBuilder. I have
tried putting it in the WEB-INF classes folder also
but still when I try to execute thr jsp it dosent
work.
There is no package declared in the classs file and
it does not extend any other class, however it
implements the HttpSessionBindingListener interface.You have to put the class in a package, then put the .class file in a package directory under WEB-INF/classes. So for example:
package beans;
public class BindListener ...
//goes into this directory structure
<APP_ROOT>/
  *.jsp
  WEB-INF/
    web.xml
    classes/
      beans/
        BindListener.class
//And is imported into your JSP using one of the following
// -- EITHER --
<%@ page import="beans.BindListener" %>
<%
  BindListener bl = new BindListener();
%>
// -- OR --
<jsp:useBean id="bl" class="beans.BindingListener"/>>
I can call servlets from my JSP in the WEB-INF
classes dir using /JBuilder/ServletName
I am mondo confused please help

Similar Messages

  • Can't import class into JSP

    Hi,
    I am trying to import a class into my JSP and am getting the following error at runtime:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: -1 in the jsp file: null
    Generated servlet error:
    [javac] Compiling 1 source file
    [javac] D:\jwsdp-1.2\work\Catalina\localhost\pe\org\apache\jsp\guestbook_jsp.java:7: '.' expected
    [javac] import MessageGetter;
    My import statement in the JSP is simply:
    <%@ page import="MessageGetter" %>
    and I am placing the class in the WEB-INF/classes directory. This is stumping me - if you've come across this or a similar problem, please let me know. Thanks.
    P

    Try posting your question in the JSP forum (http://forum.java.sun.com/forum.jsp?forum=45)
    cheers,
    Mike

  • Importing class in a jsp using Tomcat

    Hello All,
    Using Tomcat:
    I have class here:
    examples/WEB-INF/classes/ package/myclass.class
    I have a .jsp here:
    examples/JSPFolder/myjspfile.jsp
    I want to import the class into the jsp.
    I have tried the following combinations of importy lines based on previous posts on these boards and each have failed with same error:
    Unable to load class for JSP
    <%@ page import="myclass" %>
    <%@ page import="myclass.*" %>
    <%@ page import="package.myclass" %>
    <%@ page import="package.myclass.*" %>
    <%@ page import="WEB-INF/classes/package/myclass%>
    I have seen a number of posts for this same problem, and have tried those solutions as well, but none work. I am sure that this is simply a problem of finding the right directory, as I can successfully run the .jsp file iwhen I remove the import line.
    Can someone please help?

    There is a folder for shared packages
    tomcat_root\lib; or
    tomcat_root\common
    also most versions have a lib or common folder for each webapp for packages that are not to be shared.
    tomcat_root\webapps\appname\web-inf\lib
    Agreed that it is strange to allow servlets to import from the classes foler but not JSPs. It should make no difference but it is convension to place single classes in the same folder as the app's directory and packages (especially jar's) in the lib directory.

  • Can I put a class into a jsp??

    I want to put this class into a jsp.. and reference it when I need it... can i just dumped it into a jsp... or do I have to do anything specific to it...
    public class areaformat {
         public synchronized static String replace(String str, char oldchar, String newstr)     {
              StringBuffer sb = new StringBuffer(str);
              int len = sb.length();
              try     {
                   for (int i=0; i<=len; i++)     {
                        if (sb.charAt(i) == oldchar)     {
                             sb = sb.replace(i, i, newstr);
                             sb.deleteCharAt(i + newstr.length());
                             i = i + newstr.length() - 1;
              }catch(StringIndexOutOfBoundsException sioobe)     {
                   if (len == 1 && str.equals("'")) {
                        sb = new StringBuffer(newstr);
              return sb.toString();
    Thx RIch

    No, you can't. You can put only the function in the beginning of your jsp file like:
    <%!
    public void myFunction(...){
    %>
    So, you can use myFunction wherever you want in the page.
    The other method is to compile your class in a file called "javac className.java" and the put the .class file generated in your WEB-INF/classes folder of your web-container.

  • Importing classes into JSP page

    Hi There,
    I am new to this and here is my problem.
    I am doing a shopping cart tutorial and trying to get a JSP page to import two classes :
    <%@ page language="java" contentType="text/html"
    import="ShoppingBasket,Product"
    errorPage="errorpage.jsp" %>
    I get :
    C:\jakarta-tomcat-4.1.30\work\Standalone\localhost\_\shop_0002dbasket_jsp.java:7: '.' expected
    import ShoppingBasket;
    ^
    C:\jakarta-tomcat-4.1.30\work\Standalone\localhost\_\shop_0002dbasket_jsp.java:8: '.' expected
    import Product;
    ^
    C:\jakarta-tomcat-4.1.30\work\Standalone\localhost\_\shop_0002dbasket_jsp.java:50: cannot resolve symbol
    symbol : class ShoppingBasket
    location: class org.apache.jsp.shop_0002dbasket_jsp
    ShoppingBasket basket = null;
    The classes compile ok . I read that instead of comma seperating the classes it might be better to put them in a package but I do not know the correct syntax or where to put the package if this is correct.
    The tutorial is from this book and the shopping cart source code is here.
    http://www.ineasysteps.com/books/?1840781971
    Any help appreciated
    Jim Ascroft

    A little beginners explanation of classpaths and packages is in order here. A package works like an extension of the name to keep class names unique. For example, if you have a ShoppingBasket.class and you want to use my ShoppingBasket.class along with it the two class names must be unique or different from one another in some way. Yours could be in com.yourcompany package and mine could be in org.mycompany package. When you reference you Shopping backet in your code you would use com.yourcompany.ShoppingBasket and when you reference mine in the same code you would use or.mycompany..ShoppingBasket. Shorthand for the class can be used by adding an import at the top of the referencing java file. An import is like saying "hay compiler, whenever you see ShoppingBasket look for it in the com.mycompany package!" That brings us to the next point. The package name must always be reflected in the directory structure of the .class file location in order to be found. Your shopping basket must be stored under the directory com/yourcompany if it is in package com.yourcompany. That directory structure should extend off of a classpath entry in order to be made available to the JVM. Classpath entries point to folders, jar or zip files that contain packaged and unpackaged classes. So If you have a classpath entry that points to C:\jakarta-tomcat-4.1.30\webapps\ROOT\WEB-INF\classes then all unpackaged classes (classes compiled from a .java file without a package statement) will be pulled directly out of this folder. Also, packaged classes will be pulled out of they're packaging directory structure, which should be located in this folder. You can have as many classpath entries as you want but the classes will be pulled out of the first entry that they can be found under. Now with a web app you don't normally fuss with the setting of classpaths since they are already predefined and configured for you. You just need to know to put all of your class files under the WEB-INF/classes directory in the root of your web app. You do, however, still need to know how they work. You also should know that any jar files should be placed in the lib folder of your web app and not under the classes folder.
    Getting back to your immediate problem, why are you getting class not found errors? Well this stems from what was said above. To fix these kind of problems follow these steps:
    1st off, find out exactly which .java file the .class file was compiled from. (This can be a problem in some environments where multiple copies of source hang around.) This step may involve a recompile and paying close attention to the compiler arguments. In an IDE there should be a setting or dialog that lets you find out exactly where it's placing the .class files created from you source.
    Next, determine what package the .class file should be in by examining (and maybe changing) the package statement at the top. For example, if you intended to put ShoppingBasket in the com.bloodoo package make sure it has a package "com.bloodoo;" statement at the top.
    Next recompile the .java source and move the packaging directory structure into the classes folder of your app. (This would be WEB-INF/classes under the root of the web-app.) For example if ShoppingBasket.class was compiled into the com/bloodoo folder under C:\Program Files\YourIDE\projects\yourproject\output then copy the com folder out of the output folder and into the WEB-INF\classes folder.
    Next examine the calling code (JSP or servlet .java code) and make sure it references the problem class out of the right package. For example, yourpage.jsp should reference the class com.bloodoo.ShoppingBasket and not ShoppingBasket if the shopping basket is deployed in package com/bloodoo. This gets tricky with jsp usebean tags because the desire is to use shorthand but I'm not sure if that works with the use bean tag. Make any modifications and recompile if necessary.
    Lastly, as a rule of thumb avoid wild-card imports (eg. import com.package.*) because they are a common cause of confusion especially when refactoring package names and resolving these kind of issues.Those steps should allow you to resolve 85-90% of your class not found issues. The other 10-15% are rare cases involving the use of custom classloaders, the Java extension mechanism and/or classpath trickery. If you still have questions/problems post back.
    Cliff

  • Using an imported class in a JSP file

    When you import a class you wrote into a JSP file, is there a way to submit values from forms to the entire class, or can you only use the methods within the class??

    When you import a class you wrote into a JSP file, is
    there a way to submit values from forms to the entire
    class, or can you only use the methods within the
    class??Yes, there is a way in JSP. You can use,
    <jsp:useBean id="your_bean_id" scope="page or request etc" class="your_class">
    <jsp:setProperty name="your_bean_id" property="*"/>
    </jsp:useBean>
    So, <jsp:setProperty> sets all the values inside your request object into the bean, if the class is having the properties (variables) with same name as of request object's parameters. You must have coded set method for all the properties whatever you want your jsp to set the values in the bean.
    if your request is .../yourjsp?name=xxxx&age=25
    then <jsp:setProperty> method will set the name and age inside bean if you have,
    public class YourBean {
    String name;
    int age;
    public void setName(String name) {
    this.name=name;
    public void setAge(int age) {
    this.age=age;
    Hope this helps.
    Sudha

  • 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

  • How to import classes into labview project?

    Hi everyone 
    I start objected oriented program with labview, I have two sample project and I want to import their classes into my new project? is it possible to do that ? how can I import them ?
    thanks 

    You can simply add them like you would any other VI or library. I would recommend creating a virtual folder for your classes so you can keep your project organized.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Importing Custom Classes into a JSP page

    Hello,
    I have created custom package com.srjgroup.report. It sits in C:\workspace\src\com\srjgroup\report directory. I have java files as well as compiled classes there. No jar files there.
    did amend classpath to point to this directory.
    In my JSP page I have the import statement as following
    import="java.sql.*, java.util.*, java.text.SimpleDateFormat, com.srjgroup.report.*"It imports all the packages without any errors. However, when I try to use one of the classes in the package, I get error
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 3 in the jsp file: /SQLServer.jsp
    Generated servlet error:
    SRJReports cannot be resolved to a type
    SRJReports is one of the classes that I am trying to use in that package. When I comment out all references to the class, everything is fine.
    So, to fix this I moved the entire package to
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\lib direcory, preserving the hierarhy. So, now my custom package is located here:
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\lib\com\srjgroup\report again there are no jar files, only java and classes here. Still, no go.
    What am I doing wrong ?

    Put the class in
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\classes\com\srjgroup\report
    One more thing, there is no subdirectory in lib directory. You may look at the example within tomcat for reference. I start from there.

  • Importing classes for a jsp

    Hi,
    I'm trying to get a jsp working. This is part of the code of test.jsp:
    <%@page import="First, Second" %>
    <HTML>
    <HEAD>
    <TITLE>JSP Example 3</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFCC">
    <CENTER>
    <H2>Date and Time</H2>
    First.hello() is: <% First.hello(); %>
    Second.hi() is:  <% Second.hi(); %>
    </CENTER>
    </BODY>
    </HTML>This is the output of the compilation in Tomcat:
    org.apache.jasper.JasperException: Unable to compile class for JSP:
    An error occurred at line: 6 in the generated java file
    The import First cannot be resolved
    An error occurred at line: 7 in the generated java file
    The import Second cannot be resolved
    An error occurred at line: 9 in the jsp file: /date3.jsp
    First cannot be resolved
    6: <BODY BGCOLOR="#FFFFCC">
    7: <CENTER>
    8: <H2>Date and Time</H2>
    9: First.hello() is: <% First.hello(); %>
    10: Second.hi() is:  <% Second.hi(); %>
    11: </CENTER>
    12: </BODY>First.class and Second.class are the two files who share the directory with test.jsp
    I'm flabergasted with this error. As I am using very basic code for this example you would think it works (or is this error one of the NullPointerException kind?).
    Abel
    Edited by: Abel on Dec 12, 2007 6:21 AM
    Changed to a more basic type of example

    I found the answer myself ~:-).
    Add the files you want to import to a jar file
    * To be more precise, in the directory I have the jsp, I created first a directory WEB-INF, and in that directory created a directory lib, and finally created a directory test. I moved the two Java files to the test directory. I changed the Java files (added a package statement). So the configuration is now:
    <%@page import="test.*" %>
    <HTML>
    <HEAD>
    <TITLE>JSP Example 3</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFCC">
    <CENTER>
    <H2>Date and Time</H2>
    <%
       First first = new First();
       out.println ("First says: " + first.hello());
    %>
    </CENTER>
    </BODY>
    </HTML>And the two java files:
    package test;
    public class First {
         public String hello() {
              return ("Hello from First");
    package test;
    public class Second {
         public String hi() {
              return ("Hi from Second");
    }And finally I added the two classes I got after compilation to a jar file in the WEB-INF\lib directory:
    jar -cvf test.jar test\First.class test\Second.classI just explain what I did wrong, as I saw many comparable posts without an answer. And this basic problem can keep you away from the real work.
    Abel.

  • Importing classes that implement jsp tags

              I was making a custom JSP tag library. The tag functionality was implemented in
              a class called, lets cay ClassA. I made the tld file and put it under the WEB-INF
              directory. The class which implemented the functionality was placed under WEB-INF/classes
              directory. I had the imported the tag library using the taglib directive. I was
              getting an error which said "cannot resolve symbol". But when I in the JSP file
              I imported the class file which implemented the taglib functionality the error
              vanished. Is it necessary to import the class files even if the taglib is imported.
              The documentation does not say so. Or is there some configuration I have to make.
              

    I think was a side effect of the .jsp changing redeploys the web app in 6.0.
              When the web app was redeployed your directory structure was reread and thus
              it found your .tld.
              Sam
              "bbaby" <[email protected]> wrote in message
              news:3b422db7$[email protected]..
              >
              > I was making a custom JSP tag library. The tag functionality was
              implemented in
              > a class called, lets cay ClassA. I made the tld file and put it under the
              WEB-INF
              > directory. The class which implemented the functionality was placed under
              WEB-INF/classes
              > directory. I had the imported the tag library using the taglib directive.
              I was
              > getting an error which said "cannot resolve symbol". But when I in the JSP
              file
              > I imported the class file which implemented the taglib functionality the
              error
              > vanished. Is it necessary to import the class files even if the taglib is
              imported.
              > The documentation does not say so. Or is there some configuration I have
              to make.
              >
              >
              

  • Java class into jsp page

    hi i,m a beginnner
    how can i run my own java class into a JSP file?
    please help me!
    thanks

    If you understand the OO concepts and wrote the Java class right, then all you need to do is something like:YourJavaClass yourJavaClass = new YourJavaClass();
    yourJavaClass.doSomething();After all I rather recommend to use servlets for business logic instead of JSP (read: scriptlets).

  • How to import outer classes into package inner classes?

    Hi, hope you all under stand my question. Sample as below:
    import A.*;
    public class ClassA{
        public ClassA{
            ClassB.CA = this;
    package A;
    public class ClassB{
         public static ClassA CA;  //Problem Here
    }As the sample above, i cannot declare public static ClassA CA in ClassB. Any way I can solve this? Can I import ClassA into package A? Thanks.
    Edited by: ocboon8 on Apr 6, 2008 6:50 AM

    A class that is in a package cannot access a class that is not in a package.
    db

  • New syntax to import .class Files???

    Using JDK 1.2.2 i coul import my own class files by typing
    import ClassName;
    Using the j2sdk1.4.0 compile I get the Error Message
    `.` expected
    Is there a new synatx for importing .class files???

    Normally I don't help anyone under this username, but since the idiot Kayaman is here being his usual jerk-ness providing no meaningful help whatsoever (as usual), I'll let you in on the fact that 1.4 doesn't let you import un-packaged classes anymore. So just remove the import statement, or change your imported class into some kind of package.

  • Importing .class file into jsp file

    i am unable to import a .class file into my .jsp file
    please give me the correct method to import and also tell me where to deploy the .class file

    i am unable to import a .class file into my .jsp
    file
    please give me the correct method to import and also
    tell me where to deploy the .class filehttp://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-JSP.html#Section5

Maybe you are looking for

  • Using Smartform after preview print with a selection screen

    Hi experts,      I am facing with some smartform printing problem.     Here is the problem:     We develop an add_on program for printing some FI report and we use F:Front end Printing in SPAD Access Method.     The problem that we faced is: After en

  • How can I import address book contacts from 10.2 to 10.6?

    I have an uncle who recently had a computer with 10.2 that crashed.  I recovered all his files.  His new computer is now at 10.5 or 6, and will not import old contacts from 10.2.  Anyone know how I can import them?

  • GetOrderByClause() Not Working???

    I have noticed that ViewObject getOrderByClause() method always return null if order by clause is not set explicitly using setOrderByClause(). For example in this case: String myQuery = "select * from employees order by last_name, first_name"; ViewOb

  • Can I share the .m7project file

    In a CVS (or other shared code environment), can we share the .m7project file?

  • JDeveloper 10.1.3 - Browser does not automatically open

    i just recently migrated from jdeveloper 10.1.2 to jdeveloper 10.1.3. When i try to run my jsp files it compiles succesfully but no browser opens. In 10.1.2, the browser opens automatically. Is there something that I'm missing? Do I need to modify a