Accessing java class in JSP on Tomcat 5.5 server

Just i want to use a java class in JSP.
Explanation in following steps :
a. MY JSP Code - SimpleBean.jsp
b. My Java file - test.java
c. Path ( Root, jdk, jre , myfiles-test.java, SimpleBean.jsp )
d. Environment Variables
e. Error Message faced
Now Brief explanation.
a. MY JSP Code :
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,test" errorPage="" %>
<td>      
<%! test obj = new test();
obj.setAge(32); %>
<%= obj.getAge(); %>
</td>
b. My Java file - test.java
package test;
class test
private int age;
public int getAge()
     return age;
     public void setAge(int intage)
          this.age = intage;
c. Path ( Root, jdk, jre , myfiles-test.java, SimpleBean.jsp )
Tomcat Root : c:\Program Files\apache\tomcat5.5\webapps\ROOT
jdk : C:\Program Files\Java\jdk1.5.0\bin;
jre : C:\Program Files\Java\jre1.5.0\bin;
test.java : c:\Program Files\apache\tomcat5.5\webapps\ROOT\NRMS\test\test.java
SimpleBean.jsp : c:\Program Files\apache\tomcat5.5\webapps\ROOT\NRMS\test\SimpleBean.jps
d. Environment Variables :
PATH :
C:\Program Files\Java\jdk1.5.0\bin; C:\Program Files\Java\jre1.5.0\bin;
CLASSPATH :
.;C:\Program Files\Java\jre1.5.0\bin;
e. Error Message Faced : ( on accessing url http://localhost:8080/NRMS/SimpleBean.jsp )
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
Generated servlet error:
The import test cannot be resolved
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
test cannot be resolved (or is not a valid type) for the field SimpleBean_jsp.obj
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
test cannot be resolved or is not a type
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token(s), misplaced construct(s)
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token "32", delete this token
An error occurred at line: 28 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token ";", delete this token
     org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
     org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
     org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:389)
     org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
     org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
     org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
     org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.4 logs.
Apache Tomcat/5.5.4
Please explain where i am doing the mistake.
Thanks in advance.
Regards,
Lax.

>
<%@ page contentType="text/html; charset=iso-8859-1"
language="java" import="java.sql.*,test" errorPage=""
%>Your class is test.test.The compiler wouldnt know what test is from your import.
Change import as
java.sql.*,test.test
<%! test obj = new test();
obj.setAge(32); %>The symbol '!' ?

Similar Messages

  • How to access java method in JSP

    Hi all,
    I need to access java class (abstract portal component) method doContent() in a JSP which is under PORTAL-INF/jsp folder.
    I did
    <%@ page import = "com.mycompany.Aclass" %>
    <%com.mycompany.Aclass a = new com.mycompany.Aclass (); %>
    Aclass is coming as autofill/prepopulated with cntrl+space
    Till this time, it is working. no errors. But when I do
    a.
    a. (a dot) no methods are populating (autofill..cntrl+space) or If I forcebly add method a.doContent(req,res)... at runtime its giving error.
    It's not only with doContent method... Its with any simple methods in that class or any other class.
    (Other than doContent method in the APC java class are prepopulating/autofilling but giving error in runtime)
    Can anyone help me... how to access java method in JSP.
    I already gone through many SDN forum post... and implemented too---but no use I refered below forum thread
    Retrieve values from Java class to JSP
    URGENT! How to call a java class from JSP.
    Calling a java method from jsp file -
    this thread is same as my issue
    Thanks,
    PradeeP

    1st. The classes must be in packages. 2nd, the package that they are in must be under the WEB-INF/classes directory. 3rd Look on google and/or this site for web application deployment

  • Java Classes and JSP`s (urgent)

    hi, my question is:
    How can i invoke normal java classes` methods using Jsp`s for this??, is it possible??, if it is, then how do you do this, and where do you have to put the java classes in order to find them from a jsp.
    thanks

    Hi,
    You can access normal java classes in JSP pages. You have to import them in the header like this:
    <%@ page language="java" import="//your java class file with package"%>
    or if u r using java beans, then use the <usebean> tag. Put the java classes in the classes directory. Which server u r using? If it is JWS, then u have a specified classes directory, where u have to put all the class files along with their packages. Hope this will help.
    atanu.

  • How to load java class from jsp page?

    hi all!
    Does anyone know how to load java class from jsp page?
    I try to load java class from jsp page.
    Is it possible to load java class fom jsp page?
    thanks and have a good day!

    What I mean is How to load/open java class file from jsp page?
    I think we can open Applet from jsp page by using
    <applet code=helloApplet.class width=100 height=100>
    </applet>
    but, how to open java class which is an application made by Frame?
    thanks and have a good day

  • Calling java class from jsp page

    Dear Friends.
    I wrote jsp page and java class.
    Am calling java class from jsp page. after processing result,
    I have to refresh jsp page from java class.
    processing time may take 5 minutes or 1 minute etc. that depends on user.
    Can It be possible ? if possible , How ?

    Ok, I get a very strange error now:
    org.apache.jasper.JasperException: Unable to compile class for JSPerror: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
    What is this??? Anyone?

  • Accessing java classes from javascript

    Hi,
    I have the following javascript function
    function testjava {   
        var myString = new java.lang.String("Hello world"); // line 1
        alert("len:"+myString.length()); // line 2
    }It gives me a error at line 1 saying "'java' is undefined" in IE browser 5.5 sp2. But, both the lines execute correctly in netscape 6.
    Can someone please help..
    Thanks,
    Vijay.

    It seems that IE 5.5 doesn't support accessing java classes in JavaScript, so try to install IE 6 to see if it works or maybe, you doesn't have installed propertly support for JVM in IE.

  • Unable to compile class for JSP. apache-tomcat-6. What could be wrong?

    Hello, I am new to JSP and I am trying a very basic jsp and class file on Windows XP. I get the Unable to compile class for JSP.
    Steps that I have done:
    javac ch06_01.java , placed the ch06_01.class under
    C:\Apps\apache-tomcat-6.0.16\webapps\ch06\WEB-INF\classes
    Then grabbed the ch06_02.jsp and placed it under
    C:\Apps\apache-tomcat-6.0.16\webapps\ch06\
    When I run it (by placing this into Explorer or Firefox URL
    http://localhost:8080/ch06/ch06_02.jsp) I get the error further
    below. Things I have done and made sure they are in place are:
    set up JAVA_HOME to C:\Apps\jdk1.6.0_06
    Using CATALINA_BASE: C:\Apps\apache-tomcat-6.0.16
    Using CATALINA_HOME: C:\Apps\apache-tomcat-6.0.16
    Using CATALINA_TMPDIR: C:\Apps\apache-tomcat-6.0.16\temp
    Using JRE_HOME: C:\Apps\jre1.6.0_06
    I did a google on the error and I found people saying to place the
    tools.jar from the jsk into the lib directory under CATALINA_HOME. But
    the examples still don't work. What step could I be missing? Your help is greatly
    appreciated.
    This is the simple jsp file:
    <%@ page import="ch06_01" %>
    <HTML>
    <HEAD>
    <TITLE>Using a JavaBean</TITLE>
    </HEAD>
    <BODY>
    <H1>Using a JavaBean</H1>
    <% ch06_01 messager = new ch06_01(); %>
    The message is: <%= messager.msg() %>
    </BODY>
    </HTML>
    this is the simple ch6_01 java file:
    public class ch06_01
    public ch06_01()
    public String msg()
    return "Hello from JSP!";
    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: 6 in the generated java file
    The import ch06_01 cannot be resolved
    An error occurred at line: 9 in the jsp file: /ch06_02.jsp
    ch06_01 cannot be resolved to a type
    6: <BODY>
    7: <H1>Using a JavaBean</H1>
    8:
    9: <% ch06_01 messager = new ch06_01(); %>
    10:
    11: The message is: <%= messager.msg() %>
    12:
    An error occurred at line: 9 in the jsp file: /ch06_02.jsp
    ch06_01 cannot be resolved to a type
    6: <BODY>
    7: <H1>Using a JavaBean</H1>
    8:
    9: <% ch06_01 messager = new ch06_01(); %>
    10:
    11: The message is: <%= messager.msg() %>
    12:
    Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:316)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    Edited by: indikon1 on Jun 12, 2008 1:18 PM
    I just updated the directories of the variables to reflect the current status of my system.

    What is wrong is that you are using an "old" jsp tutorial :-)
    Since Java 1.4, JSPs have been unable to access classes in the "default" package.
    What you need to do:
    Put the java class ch06_01 in a package.
    Steps to do this
    - Edit ch06_01 and add the following to the very top of the file (without the quotes): "package mypackage;"
    - create a folder "mypackage"
    - move ch06_01.java into that folder
    - compile that class (now in the mypackage package)
    - place ch06_01.class under C:\Apps\apache-tomcat-6.0.16\webapps\ch06\WEB-INF\classes\mypackage
    In your jsp:
    <%@ page import="mypackage.ch06_01" %>
    I would suggest using a more up-to-date tutorial that uses JSTL.
    Take a look at this [Apache Tomcat tutorial|http://www.coreservlets.com/Apache-Tomcat-Tutorial/index.html]

  • Calling a external Java method from JSP - using Tomcat server

    Hi all,
    I am trying to call a method in an external Java file from my JSP. I am using Tomcat server.
    I have my class within the package package "mypackage" and it is called myclass.class. It has only one static method mymethod() which reads from a file and writes to a file.
    I compiled the java class and I put the class file under webapps/ROOT/web-inf/classes/mypackage/myclass.class
    I am trying to say something like this from my JSP file(which is under webapps/ROOT) :
    <%@ page import = "mypackage.myclass"%>
    <% myclass.mymethod(); %>
    I am not instatiating the class as its a static method.
    This is what I get while accessing my jsp file :
    javax.servlet.ServletException: try to access class mypackage.myclass from class org.apache.jsp.index_005ftest_jsp
    To put my problem in a nutshell, Can someone guide me how to access a method of an external class from a JSP page? I have a bunch of pages doing the same operation so I thought I would have it in a method and call it from every page. Even though I tried to put the file under web-inf/classes, The JSP is not able to see the class.
    Please help.
    Thanks
    -Uday

    I have a situation that is a bit similar. I have successfully used beans for storing methods used in JSPs and used by other methods in the same class as was suggested above. Now I would like to break some methods into another (utility) class since they are lower level and can be used by lots of things. They are for database operations (given a String query and String dbname, it queries and returns ResultSet for example). I want to have them in a separate class for reusability and OOP.
    I am having problems calling those public static methods in the public class from my bean that communicates with the JSP. I can't compile the class that calls the method in the database ops class. I get an error like :
    loginHelper.java:45: cannot find symbol
    symbol : variable sqlHelper
    location: class dbHelperBean.loginHelper
    and when I include the package name in the call I get
    loginHelper.java:45: cannot find symbol
    symbol : class sqlHelper
    location: package dbHelperBean
    That's strange since the package of both classes is dbHelperBean and the class is indeed called sqlHelper. I tried to compile it in the same directory as sqlHelper as well. What am I doing wrong?
    Thanks for any help.

  • How to invoke a 6 parameter java class within jsp

    i have just begun to learned jsp and java recently, so have the question below:
    Situation:
    My boss asked me to do a project for doing online data mining.
    He requested the thing below:
    1. Write a webpage by jsp with some textfield or pull down meun to get the parameter for getting the opinion and the parameter needed for the java class.
    2. When the user click the buttom in the website, then the java class have to be invoked.
    Questions:
    1. ask i put the .java in the server, i can simply use cmd and type the following command:
    java -Xmx800M P05context 1 1 3 6 F01xyz.txt F10xyz.txt
    which F01xyz is the prepared text file for the java class to read and the F10xyz.txt is the output file generated by the P05context.class
    but i don't know how to invoke the P05context.class by jsp
    My boss have suggested me two ways to do this:
    a. write a java virtual class to execute the java program.
    but i don't know how to write.
    i think conceptualy will be like this :
    public class run_java
    public void run java(parameter1,parameter2....,parameter6)
    //run the cmd command
    //java -Xmx800M P05context 1 1 3 6 F01xyz.txt F10xyz.txt
    b. write a javabean in the jsp. and i have try to use this code(at the end of the message:
    but the tomcat server reply a internal error to me
    how cani do ?
    the jsp file-->
    <jsp:useBean id="test" scope="session" class ="P05context" />
    <html>
    <head></head>
    <body>
    <% test.P05context(1,1,3,6,F01xyz.txt,F10xyz.txt); %>
    </body>
    </html>

    I still don't see why the form (the origin of the request) has to be a JSP, As you say, it might be static but forms I've written have usually had some kind of menu framework arround them and other variables. Also if the input is invalid you usually want to re-present the form, with an error message and the fields pre-populated according to what the user put in before. That does require a JSP and you may as well use the same JSP for an empty, as for a rejected request.
    the response to the form should be handled by a servlet. Both is HTML, but the
    form is static, and the reply dynamic. Using the combination; a servlet to do the data processing and a JSP to format the results is more flexible in a number of ways. For example, suppose you find the need to present the data form in, say, Greek? You don't want the processing to be duplicated in English and Greek versions of the results JSP.
    Suppose the boss wants to turn a graphics designer loose on your HTML. Don't want him mucking about with your processing code do you.
    The servlet typically takes the function of controller in the model/view/controller paradigm.
    Code in a servlet is cleaner, better formatted and easier to access with a debugger.

  • Problem while trying to execute Java class in JSP using  RunTime Class

    Hi,
    I want to execute a JAVA class through a JSP. For this I am using following code ....
    JSP (AAA.jsp) CODE ............
    try
    String[] cmd = new String[3];
    cmd[0] = "cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[2] = "java -DPeBS_CONFIG_HOME=D:/CASLIntegration/PeBS/srcvob/PeBS/config Service_Statement_Application 22/May/2001 22/May/2003";
    Runtime rt = Runtime.getRuntime();
    System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]);
    Process proc = rt.exec(cmd);
    // any error message?
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
    // any output?
    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    // any error???
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
    catch (Throwable t)
    t.printStackTrace();
    StreamGobbler THread class Code ..........
    import java.util.*;
    import java.io.*;
    public class StreamGobbler extends Thread
    InputStream is;
    String type;
    StreamGobbler(InputStream is, String type)
    this.is = is;
    this.type = type;
    public void run()
    try
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line=null;
    while ( (line = br.readLine()) != null)
    System.out.println(type + ">" + line);
    } catch (IOException ioe)
    ioe.printStackTrace();
    I have successfully compiled and placed the class file for the above class in JSP's servlet engine. However, when I execute the JSP through explorer Web Browser, I get following compile time error:
    An error occurred between lines: 36 and 86 in the jsp file: /casl/LocalApp/VehicleServiceStmt/AAA.jsp
    Generated servlet error:
    D:\Tomcat\work\localhost\_\casl\LocalApp\VehicleServiceStmt\AAA$jsp.java:118: No constructor matching StreamGobbler(java.io.InputStream, java.lang.String) found in class StreamGobbler.
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
    ^
    An error occurred between lines: 36 and 86 in the jsp file: /casl/LocalApp/VehicleServiceStmt/AAA.jsp
    Generated servlet error:
    D:\Tomcat\work\localhost\_\casl\LocalApp\VehicleServiceStmt\AAA$jsp.java:121: No constructor matching StreamGobbler(java.io.InputStream, java.lang.String) found in class StreamGobbler.
    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
    I am unable to determine the reason of why the constructor which exists in the StreamGobbler Class is not recevied in JSP. If I try to write the same code in JSP as a JAVA class, keeping StreamGobler class same, the programme executes successfully.
    Please help me find solution to this at the earliest. Thanks in advance,
    Prachi

    Thanks,
    I got it working by making the constructor Public.
    -Prachi

  • Ordinary java class and jsp page

    hi i want to use some java class(not javabean ) in my jsp . how do i import them and use them?

    You can just import the package into your JSP, and access it like any other class of the Standard Java API that you access.
    fun_one

  • Calling a java class in JSP in Weblogic 5.1

    Hi
    I am trying to call a java class in a jsp page. But it is giving an error:
    Compilation of 'C:\weblogic\myserver\classfiles\jsp_servlet\_knet\_buy.java' failed:
    C:\weblogic\myserver\classfiles\jsp_servlet\_knet\_buy.java:79: cannot access jsp_servlet._knet.e24PaymentPipe
    probably occurred due to an error in /knet/buy.jsp line 25:
    e24PaymentPipe pipe = new e24PaymentPipe();
    Is this a problem bcos of the wrong path of the class file which i am calling?
    Please help this is urgent

    Hello All
    As I tried to deploy the easiest project (dummy.war) on WebLogic 8.1.5, There is only one class (without package) Login.class
    *********** Listing of the dummy WAR ***********
    META-INF/
    META-INF/MANIFEST.MF
    WEB-INF/
    WEB-INF/classes/
    WEB-INF/classes/Login.class
    WEB-INF/web.xml
    index.jsp
    login.jsp
    ************ Output of deployment from Admin Console****************
    Log:     
         A log of the task's activities.
    [Deployer:149033]preparing application dummy on intranetAdmin
    [Deployer:149033]prepared application dummy on intranetAdmin
    [Deployer:149033]activating application dummy on intranetAdmin
    [Deployer:149033]failed application dummy on intranetAdmin
    [Deployer:149034]An exception occurred for task [Deployer:149026]
    Deploy application dummy on intranetAdmin.:
    Exception:weblogic.management.ApplicationException: start() failed.
    Module: dummy Error: weblogic.management.DeploymentException:
    [HTTP:101216]Servlet: "index" failed to preload on startup in Web application:
    " dummy ".
    weblogic.servlet.jsp.CompilationException: Compilation of D:\apps\wlsapp\
    INTRAN~1\.\intranetAdmin\.wlnotdelete\extract\intranetAdmin_ dummy _ dummy
    \jsp_servlet\__index.java failed.
    D:\apps\wlsapp\INTRAN~1\.\intranetAdmin\.wlnotdelete\extract\
    intranetAdmin_dummy_dummy\jsp_servlet\__index.java:22: '.' expected
    import Login; //[ /login.jsp; Line: 8]
    ^
    1 error
    at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:478)
    at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:246)
    at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:196)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.
    java:3430)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext.
    java:3387)
    at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext
    .java:3373)
    at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:3356)
    at weblogic.servlet.internal.WebAppServletContext.setStarted(WebAppServletContext.java:
    6208)
    at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:864)
    at weblogic.j2ee.J2EEApplicationContainer.start(J2EEApplicationContainer.java:2134)
    at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2175)
    at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.
    activateContainer(SlaveDeployer.java:2520)
    at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer
    .java:2438)
    at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2155)
    at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDeployer.java:2254)
    at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.java:2149)
    at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.
    java:2401)
    at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:
    883)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:591)
    at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:500)
    at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
    Caused by: java.io.IOException: Compiler failed executable.exec
    at weblogic.utils.compiler.CompilerInvoker.compileMaybeExit(CompilerInvoker.java:470)
    at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:328)
    at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:336)
    at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:321)
    at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:451)
    ... 22 more
    - with nested exception:
    [java.io.IOException: Compiler failed executable.exec]
    I put this class into a dummy package named sample, changed package declaration within this class and changed import statement within jsp pages like this :
    <%@ page import="sample.Login " %>
    <jsp:useBean id="logUsr" scope="session" class="sample.Login" />
    When I did like this, everything is ok. No more exception.
    If my application has so many java classes under WEB-INF/classes/ without creating package, it may be so inconvenience.
    Please kindly let me know why this exception (class not found exception) occurred.
    And what is the solution? I cannot deploy the application successfully yet.
    many thanks,
    Zin Ko Win

  • Import java-classes in JSP-page

    Hi,
    I'm starting with JSP and with trying one of the first examples in the book "beginning J2EE 1.4" from wrox, i got following problem.
    i'm trying to import a java-class in the package CH03 with
    <%@ page import="Ch03.FaqCategories" %>but he didn't find the package Ch03.
    I try already many things and i have no idea of the cause of the problem. So it's difficult to give information that leads to the solution.
    Maybe helpfull is the direcory-structure:
    jsp-page: /Ch03/welcome.jsp
    java-classe: /Ch03/WEB-INF/classes/Ch03/FaqCategories.class
    If you need source-codes or other information, just ask.
    Thanks,
    Dennis

    Thank you,
    Your help was one step into the good direction and that problem is solved.
    The application work now with studio one, but if i try it to work it with a stand-alone tomcat server it doesn't work anymore. I go first try to solve this problem by my self or at least try to describe the problem more exactly, before i ask for new help.
    but if you have any idea, that's always welcome...
    with regards,
    Dennis

  • Access extended class in JSP.

    I am reading <<JSP weekend crash course>>. Following is a example in the book.
    FruitMap.java
    public class FruitMap extends java.util.HashMap{}
    I saved FruitMap.java file <tomcat-install>\webapps\ROOT\Web-Inf\classes and executed javac FruitMap.java command.
    FruitMap.class was created succussfuly.
    I stop and restart the Tomcat server.
    The jsp file fruitPrice.jsp is following:(only first a few lines pertain to my question).
    <%@ page import="java.util.*" %>
    <%
    String selectedFruit = request.getParameter("selectedFruit");
    if (selectedFruit == null) {
    selectedFruit = "apples";
    %>
    <jsp:useBean id="fruitList" class ="FruitMap">
    <%
    fruitList.put("apples","2.99");
    fruitList.put("oranges","2.59");
    fruitList.put("plums","3.99");
    %>
    </jsp:useBean>
    <html>
    <head>
    <title>Fruit Price Calculation</title>
    <SCRIPT language="JavaScript">
    price = parseFloat(<%=fruitList.get(selectedFruit)%>);
    function submitForm() {
    document.fruitForm.submit();
    function roundNumber(number, digits){
    return Math.round(number*Math.pow(10,digits))/Math.pow(10,digits);
    function calcTotal() {
    document.fruitForm.total.value = roundNumber(price*parseInt(document.fruitForm.quantity.value),2);
    </SCRIPT>
    </head>
    <body onload="calcTotal()">
    <h1>Fruit Price Calculation</h1>
    To change the fruit, select a different fruit from the list.<br>
    To calculate the total price for the fruit you select, enter the number of pounds you would like, and hit the tab key on your keyboard.
    <form method="POST" name="fruitForm">
    <table border="1" cellpadding="3">
    <tr align="left" valign="top">
    <th bgcolor="#c0c0c0">Fruit Type</th>
    <td>
    <select name="selectedFruit" onchange="submitForm();">
    <%
    Iterator fruitNames = fruitList.keySet().iterator();
    while (fruitNames.hasNext()) {
    String newFruit = (String)fruitNames.next();
    out.print("<option value='" + newFruit + "' ");
    if (selectedFruit.equals(newFruit)){
    out.print(" Selected ");
    out.print(">" + newFruit);
    %>
    </select>
    </td>
    </tr>
    <tr>
    <th bgcolor="#c0c0c0"">Price($):</th>
    <td><input type="text" size="15" name="price" disabled readonly value="<%= fruitList.get(selectedFruit) %>"</td>
    </tr>
    <tr>
    <th bgcolor="#c0c0c0">Pounds:</th>
    <td><input type="text" size="15" name="quantity" value="1" onchange="calcTotal();"></td>
    </tr>
    <tr>
    <th bgcolor="#c0c0c0">Total($): </th>
    <td><input type="text" size="15" name="total" disabled readonly value="" ></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    When run the page by enter http://localhost:8080/fruitPrice.jsp
    I got these errors:
    Error: 500
    Location: /fruitPrice.jsp
    Internal Servlet Error:
    org.apache.jasper.JasperException: Unable to compile class for JSPC:\jakarta-tomcat-3.2.3\work\localhost_8080\_0002ffruitPrice_0002ejspfruitPrice_jsp_0.java:75: Class java.util.HashMap not found in cast.
    fruitList= (FruitMap)
    ^
    C:\jakarta-tomcat-3.2.3\work\localhost_8080\_0002ffruitPrice_0002ejspfruitPrice_jsp_0.java:75: Invalid cast from java.lang.Object to FruitMap.
    fruitList= (FruitMap)
    ^
    C:\jakarta-tomcat-3.2.3\work\localhost_8080\_0002ffruitPrice_0002ejspfruitPrice_jsp_0.java:80: Class java.util.HashMap not found in cast.
    fruitList = (FruitMap) Beans.instantiate(this.getClass().getClassLoader(), "FruitMap");
    ^
    C:\jakarta-tomcat-3.2.3\work\localhost_8080\_0002ffruitPrice_0002ejspfruitPrice_jsp_0.java:80: Invalid cast from java.lang.Object to FruitMap.
    fruitList = (FruitMap) Beans.instantiate(this.getClass().getClassLoader(), "FruitMap");
    ^
    Why the FruitMap class is not recognized? I am using Tomcat 3.2.3 .

    Hi silverbullet,
    U haven't imported the class FruitMap at the top of the JSP, import it and I think it should work.
    eg ..
    if FruitMap class has the default package then
    <%@ page import="FruitMap" %>
    And another thing, just for sharing........u don't have to import java.lang.* and java.util.* in JSP, they are imported by default..........
    Chandan.

  • Java Classes in JSP

    I'd like to use some of my java classes from my JSP pages, how do I do
              this?
              ie: I have a class
              public class Test
              public static void uselessFunx()
              //do nothing
              How would I get access to the Test class and call uselessFunx()?
              Thanx.
              

    Good point Toad. That is a loaded question!
              If you do want to 'hack' in your classes, then you should
              A) Use the PAGE directive to import the class package into your JSP <%@ page
              import="mypackages.myclasses.*" %>
              B) Instantiate the class using a scriptlet <% Test myTest = new Test(); %>
              C) Reference the class from a scriptlet <% String result =
              myTest.uselessFunx(); %>
              D) You can output results referencing these new variables using <%= result
              %>
              Make sure you're using packages. Otherwise you'll have great difficulty
              convincing the JSP that it's in the same package as your class.
              "Toad" <[email protected]> wrote in message
              news:[email protected]...
              > This is a loaded question. I would recommend using custom actions (tags)
              or
              > the built-in jsp:usebean tag. Though not recommended you can also
              > instantiate a class inside a sniplet. If these are unfamiliar topics
              > definitely consider reading an introductory JSP article or two.
              >
              > "S D" <[email protected]> wrote in message
              > news:[email protected]...
              > > I'd like to use some of my java classes from my JSP pages, how do I do
              > > this?
              > >
              > > ie: I have a class
              > >
              > > public class Test
              > > {
              > > public static void uselessFunx()
              > > {
              > > file://do nothing
              > > }
              > > }
              > >
              > > How would I get access to the Test class and call uselessFunx()?
              > >
              > > Thanx.
              >
              >
              

Maybe you are looking for