Import packageless classes in a jsp : tomcat 5.0.16

Hi all,
I am trying to import a class, say one.class, which is stored in the /WEB-INF/classes folder of the webapplication into a jsp page. Like,
<%@page import="one"%>
I get the following error,
C:\jakarta-tomcat-5.0.16\work\Catalina\localhost\test\org\apache\jsp\testing_jsp.java:7: '.' expected
import one;
what could the problem be? I suppose, the problem is in accessing a class which is not inside a jar.
take care,
Siddharth.

Hi,
If you are using jdk 1.4 and above, you need to have package name for classes .
You could just give a try after removing the import statement . Perhaps the server could find the classes in your WEB-INF/classes directory. I doubt though.
-Amol

Similar Messages

  • Import java classes in a JSP

    hallo
    I have craeted aPackage "TestPackage" as subdirectory in the order
    tomcat\webapps\ROOT\WEB-INF\classes\TestPackage
    in this package ther ist the class Test
    I try to imort this class in the jsp
    <%@ page language="java" import="TestPackage.*"%>
    <jsp:useBean id="app" scope="page" class="Test"/>
    <%
    for(int i=0; i< 10; i++){
    %>
    <h1><%= app.getName()%></h1>
    <%
    %>
    error:
    [javac] C:\tomcat4\work\Standalone\localhost\_\test_jsp.java:43: cannot resolve symbol
    [javac] symbol : class Test
    [javac] location: class org.apache.jsp.test_jsp
    [javac] Test app = null;
    who ist the Problem ???
    thanks

    Hi Orient,
    Actually <jsp:useBean /> takes fully qualified class name.
    so your code for <jsp:useBean /> should be like this
       <jsp:useBean id="app" scope="page" class="TestPackage.Test"/>
      For more details please refer http://java.sun.com/products/jsp/tags/11/syntaxref1115.html
    Regards
    Goodieguy

  • 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.

  • Can't find the imported java class when run .jsp file

    Hi,
    I want to run a jsp web application using tomcat. I put all my .jsp files under "TOMCAT_HOME/webapps/junmin" directory, and put all .class files under "TOMCAT_HOME/webapps/junmin/WEB-INF/classes" directory. I set up TOMCAT_HOME AND JAVA_HOME already. But when I type in the address like below:
    http://db1.acad.emich.edu:8080/junmin/login.jsp
    The IE will give me error msg indicating that it can't find all the .class files which I imported them in login.jsp file.
    So, does anyone know that if I miss some configuration in order to let the .jsp file recognize the .class files. Thanks a lot!
    Sincerely, Junmin

    Ha, this might be the reason.
    Can I add sth like this:
    <Context path="/junmin" docbase="junmin" debug=0 reloadable=true>
    </Context>
    But in my local computer, I didn't add this <Context> either. It works well.
    Thanks a lot! I will ask the administrator to try this.
    And will write down the reason.
    Sincerely, Junmin

  • 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.

  • Importing java classes into jsp page

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

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

  • How to use Classes stored in "Classes" folder in JSP with tomcat ?

    Hello friends
    im using tomcat as server and MySQL as a Backend. now i am using the date calculation in Diff.class files which i have stored in catalina_home/webapps/prj_dev/Prj_files/classes/diff/DIff.class.
    now i am getting error that :
    Generated servlet error:
    Only a type can be imported. diff.Diff resolves to a package
    wht i have to do ?

    I don't include the "classes" word in my import anymore.. Waa.. I'm going nuts.. T.T
    Now, I'm trying to use the class through useBean..
    this is how my application looks like:
    /webapps
    -----/hangman-jsp
    ------------index.jsp
    ------------/WEB-INF
    -------------------web.xml
    -------------------MysteryPhrase.java
    -------------------/classes
    ---------------------------/beans
    ----------------------------------MysteryPhrase.class
    -----------/images
    -------------------hangman.gif
    This is what is in my MysteryPhrase:
    package beans;
    import java.lang.String;
    import java.lang.StringBuffer;
    public class MysteryPhrase {
         private String answer;
         private StringBuffer mysteryPhrase;
         private int guesses;
         private char[] alphabet;
         public MysteryPhrase () {
         this.alphabet = new char[26];
    public void setMysteryPhrase (String mysteryPhrase) {
         this.answer = mysteryPhrase;
         this.mysteryPhrase = new StringBuffer(mysteryPhrase.length());
         for (int i = 0; i < mysteryPhrase.length(); i++) {
              this.mysteryPhrase.setCharAt(i, '_');
    public void setGuess (char guess) {
         for (int i = 0; i < answer.length(); i++) {
              if (answer.charAt(i) == guess) {
                   mysteryPhrase.setCharAt(i, guess);
         guesses++;
    public String getMysteryPhrase () {
         return mysteryPhrase.toString();
    public String getAnswer () {
         return answer;
    public int getGuesses () {
         return guesses;
    This is what is in my index.jsp (It is not yet finished..I just started..)
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <jsp:useBean id="phrase" class="beans.MysteryPhrase"/>
    <jsp:setProperty name="phrase" property="MysteryPhrase" value="Hello!"/>
    <html>
         <head>
              <title>JSP/JSTL Implementation of Hangman</title>
              <style type="text/css">
                   div {
                        color: white;
                        background-color: gray;
                        position: absolute;
                        border-style: solid;
                        border-width: thin;
                        width: 20%;
                        height: 30%;
                        text-align: center;
                   #guessBoard {
                        top: 28%;
                        left: 42%
                   #mysteryPhraseBoard {
                        top: 50%;
                        left: 25%;
                        z-index: 2;
                   #statisticsBoard {
                        top: 57%;
                        left: 58%;
                        z-index: 2;
                   #categoryBoard {
                        top: 23%;
                        left: 10%
                   #hangman {
                        top: 7%;
                        left: 70%;
                   #char {
                        width: 20px;
                   body {
                        background-color: black;
              </style>
         </head>
         <body>
              <div id="categoryBoard">
                   <form method="post">
                        Please choose a category:
                        <select name="category">
                             <option>Category 1</option>
                             <option>Category 2</option>
                             <option>Category 3</option>
                             <option>Category 4</option>
                             <option>Category 5</option>
                             <option>Category 6</option>
                             <option>Category 7</option>
                             <option>Category 8</option>
                        </select>
                        <input type="submit" value="Change"/>
                   </form>
              </div>
              <div id="mysteryPhraseBoard">
                   The mystery phrase is
              </div>
              <div id="guessBoard">
                   <form method="post">
                        Enter a letter: <input id="char" type="text" name="letter"/>
                        or
                        Enter a word: <input type="text" name="word"/>
                        <input type="submit" value="Guess"/>
                   </form>
              </div>
              <div id="statisticsBoard">
                   Guesses: 0
                   Remaining Letters: 8
              </div>
              <div id="hangman">
                   <img src="images/hangman.gif"/>
              </div>
         </body>
    </html>

  • How to reference a DatabaseHandler servlet class from a jsp file in Tomcat

    Trying to create a database connection in the jsp file in webapps\project folder by referencing the DatabaseHandler class in webapps\project\WEB-INF\classes.
    Here is the code in the jsp to make the connection:
    DatabaseHandler db = new DatabaseHandler() ;
    String sql = "SELECT password FROM cms_users WHERE user =" + userName ;
    java.sql.ResultSet rs = db . selectQuery( sql ) ;
    Here is the DatabaseHandler class:
    import java.sql.*;
    public class DatabaseHandler
         // instance variables - replace the example below with your own
    private Connection connection;
         * Constructor for objects of class DatabaseHandler
         public DatabaseHandler()
    String url = "jdbc:odbc:javadatabase";
    // Load the driver to allow connection to the database
    try
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
    connection = DriverManager.getConnection( url );
    catch ( ClassNotFoundException cnfex )
    System.err.println( "Failed to load JDBC/ODBC driver." );
    cnfex.printStackTrace();
    System.exit( 1 ); // terminate program
    catch ( SQLException sqlex )
    System.err.println( "Unable to connect" );
    sqlex.printStackTrace();
    public ResultSet selectQuery( String query )
    Statement statement;
    ResultSet resultSet = null ;
    try
    statement = connection.createStatement();
    resultSet = statement.executeQuery( query );
    catch ( SQLException sqlex )
    sqlex.printStackTrace();
    System . exit( 1 ) ;
    return resultSet ;
    Here is the error i am getting when i try to run the jsp script:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 2 in the jsp file: /ValidateLogon.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\cms\ValidateLogon_jsp.java:47: cannot find symbol
    symbol : class DatabaseHandler
    location: class org.apache.jsp.ValidateLogon_jsp
    DatabaseHandler db = new DatabaseHandler() ;
    ^

    Just like in the class file you need to import any classes that you want to access in the JSP.
    http://java.sun.com/products/jsp/tags/11/syntaxref11.fm7.html

  • Not able to import a class in jsp

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

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

  • Can not call bean class from JSp/Tomcat 5.5

    hello everyone...
    i m using one bean class Parser which is called by discussion.jsp page. i put class file in webapps/grid/WEB-INF/classes and JSP page is in webapps/grid/. The whole combination is working fine for tomcat 3.3.2 but not working properly in tomcat 5.5.
    Error is as follow...
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 38 in the jsp file: /discussion.jsp
    Generated servlet error:
    Parser cannot be resolved or is not a typeplease help me....
    Thank in Advance

    You still need to import the class from the default package. As a word of advice you should put the class in a package. The later versions of Tomcat do not play well with bean classes that are not in packages.

  • How to import a java class in a JSP

    Hi All,
    I have a java class file called myTest.class (i made after compilation of myTest.java). I have a JSP page that uses this java class file.
    These 2 files are in same folder called c:/test
    and iam importing this java class file into my jsp file and that too at the start of this jsp file:
    <%@page import="myTest" %>
    BUt iam getting an error ..............when iam running this JSP page:
    /opt/bea81sp2/user_projects/domains/wliDomain/./Managed2/.wlnotdelete/extract/Managed2_myTest_myTest/jsp_servlet/__test.java:20: '.' expected
    probably occurred due to an error in /test.jsp line 5:
    <%@page import="myTest" %>
    Please advise how to solve this problem
    -sangita

    Don't bother with the import
    when iam not importing this class file into my JSP, then on my JSP, the class file is not found.
    Here is my code: and these 2 class file are in c:/test
    import org.apache.tools.ant.taskdefs.Ant;
    import org.apache.tools.ant.taskdefs.Property;
    import org.apache.tools.ant.types.*;
    import org.apache.tools.ant.*;
    import org.apache.tools.ant.taskdefs.ExecTask;
    import org.apache.tools.ant.types.Commandline;
    import java.io.File;
    * Creates an Ant project to run an Ant build
    * @author myself
    * @version 1.0
    public class RunTest extends Ant {
        String applicationName;
        String buttonClicked;
        String boxName;
        String targetName;
        public void applicationName(String applicationName){
         this.applicationName = applicationName;
        public void boxName(String boxName){
         this.boxName = boxName;
        public void buttonClicked(String buttonClicked){
         this.buttonClicked = buttonClicked;
      public RunTest() {
    public void goTest() {
         if(this.buttonClicked.equalsIgnoreCase("deploy") && this.applicationName.equalsIgnoreCase("scsmail") && this.boxName.equalsIgnoreCase("testnet")){
           this.targetName = "deploy-scsmail-testnet";
         if(this.buttonClicked.equalsIgnoreCase("undeploy") && this.applicationName.equalsIgnoreCase("scsmail") && this.boxName.equalsIgnoreCase("testnet")){
           this.targetName = "undeploy-scsmail-testnet";
        Project project = new Project();
        project.init();
        System.out.println("printing 1 ....");
        ExecTask exec = new ExecTask();
        exec.setProject(project);
        exec.setExecutable("/opt/bea/weblogic81/server/bin/ant.bat");
         exec.setDir(new java.io.File("/export/home/beamon/bin"));
         Commandline.Argument arg = exec.createArg();
         // arg.setLine("-f scsmail.xml test -listener org.apache.tools.ant.XmlLogger -logfile D:/antProject/src/log.xml");
         arg.setLine("-f build.xml "+ targetName + " -listener org.apache.tools.ant.XmlLogger -logfile /export/home/beamon/bin/log.xml");
         System.out.println("printing 2....");
        //exec.setOutput(new File("D:/antProject/logs/prob.txt"));
        exec.execute();
        System.out.println("printing 3....");
    -----------------------the JSP page is called as test.jsp
    <%@page contentType="text/html" %>
    <%@page import="java.io.*" %>
    <%@page import="java.util.*" %>
    <%@page import="java.net.*" %>
    <%@page import="RunTest" %>
    <HTML>
    <TITLE>TESTING ANT GUI</TITLE>
    <HEAD>
    <META HTTP-EQUIV="Refresh" CONTENT="3000" >
    <meta http-equiv="Cache-Control" content="no-cache">
    </HEAD>
    <BODY BGCOLOR="silver" TEXT="333333">
    <table border=0>
    <tr align="left"><td align="left"><FONT SIZE="-1"><B>  Test Page <FONT SIZE="-1"><B></td></tr>
    </table>
    <hr></center>
    <form action="./test.jsp" method="POST" name="testForm">
    <table>
    <tr>
    <td>
    <select name="appName" size=1>
    <option value="">Select Application Name
    <option value="scsmail">scsMail
    <option value="clientmanager">ClientManager
    </select>
    </td>
    <td>
    <select name="boxName" size=1>
    <option value="">Select Box Name
    <option value="testnet">TestNet
    <option value="production">Production
    </select>
    </td>
    </table>
    <table>
    <input type="submit" name="deploy" value="deploy">
    <input type="submit" name="undeploy" value="undeploy">
    </table>
    <%
       RunTest rt = new RunTest();
       rt.applicationName(request.getParameter("appName"));
        String deployButton = "";
        deployButton=request.getParameter("deploy");
        String undeployButton = "";
        undeployButton=request.getParameter("undeploy");
        if(!deployButton.equalsIgnoreCase("")){
            rt.buttonClicked(request.getParameter("deployButton"));
        if(!undeployButton.equalsIgnoreCase("")){
            rt.buttonClicked(request.getParameter("undeployButton"));
       rt.boxName(request.getParameter("boxName"));
        rt.goTest();
    %>
    </form>
    </table>
    </BODY>
    </HTML>

  • 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...

  • Unable to import a java class in a jsp file

    Hi,
    I am trying to import a java class in my jsp.
    ------------------jsp---------------
    <jsp:useBean id="form" class="com.company.portlets.searchApps.object.SearchOBJ" scope="request" />
    <jsp:setProperty name="form" property="*" />
    <input type="TEXT" name="projectID" value='<%= form.getProjectID() %>'>
    When I run the above JSP, it says that class 'com.company.portlets.searchApps.object.SearchOBJ' cannot be found.
    Why?
    My project structure looks like this:
    Project
    +Application Sources
    ++com.company.portlets.searchApps.object
    +++SearchOBJ.java
    +Web Content
    ++htdocs
    +++searchappsportlet
    ++++SearchAppsPortletShowPage.jsp
    ++WEB-INF
    +++index.jsp
    +Resources
    ++SearchApps.deploy
    Please advice...thanks!

    The way that JDeveloper organized the files was like this:
    C:\jdev1012\jdev\mywork\WksSearchApps\Project\classes\com\company\portlets\searchAPPS\object\SearchOBJ.class
    I am assuming that JDeveloper puts the file where they are suppose to be...if not, how do I change that?
    thanks,
    hussain

  • 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

  • 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

Maybe you are looking for

  • ***Calling Java finctions in XSLT MApping

    Hi All, How to  call java mapping functions in XSLT.I have created Value mapping function in java,want to call the same through XSLT. could you provide me  general XSLT prdefined functions with explanations that may be used commonly. Thanks, Srinivas

  • Iphoto directory structure and multiple copies

    I want to manage the directory structure of my photos because I use them with applications and want to put them where I want to. Thus, I never cared for iPhoto 08 and how it organized the directory structure how it wanted to. Additionally, it seems i

  • Update print-dependent data

    When I make : SPRO -> Material Management-> Purchasing -> Message -> Output Control->Message Types->Define message type for purchase order->Fine-Tuned Control: Purchase Order Somebody could explain me what means the U=>Update print-dependent data If

  • Apple update software for windows 7 X64 ultimate

    so apple support update pops up and says "HEY! YOU HAVE UPDATES!"  for quicktime and itunes.. problem is when i tell it to update the window just flickers.. it will not update, nor will it let me manually update quicktime.. i previously fixed itunes

  • Unknown Podcasts and combining music and podcasts

    Hi, I've been having a problem with a podcast that I subscribed to on my computer before I had to re-format my hard drive. iTunes stores these podcasts in a folder called "Unknown Podcast" and they don't show up in the podcast section or in my music