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.

Similar Messages

  • How to run jsp using  tomcat server?

    hai friends,
    i'm using jsp for my application and for that i'm using tomcat server.
    i was runing my jsp files like this
    http://localhost:8080/examples/jsp/myapp/index.jsp but instead of this
    i need to run my jsp files like this
    http://localhost:8080/myapp/index.jsp
    what r the changes that i should do in tomcat installation to run myapplication in such a way.
    thanks in advance

    you need to redefine the server root...
    for that do the following...
    copy all the directory tree rooted at
    JAKARTA-HOME/webapps/ROOT/examples/jsp/myapp/ to
    JAKARTA-HOME/webapps/ROOT/myapp/
    -OR-
    in the server.xml, search for "Tomcat Root Context" and un-comment the code defining Root Context...
    change the docBase value from "ROOT" to "ROOT/examples/jsp"
    that shud help...
    -Pranav
    hai friends,
    i'm using jsp for my application and for that i'm
    using tomcat server.
    i was runing my jsp files like this
    http://localhost:8080/examples/jsp/myapp/index.jsp but
    instead of this
    i need to run my jsp files like this
    http://localhost:8080/myapp/index.jsp
    what r the changes that i should do in tomcat
    installation to run myapplication in such a way.
    thanks in advance

  • How to call stand Alone java program from jsp

    Hello all...
    I want to use the stand alone java program in jsp page. I compiled the java program and place the class file in classes folder under web-inf. But when i try to instantiate the java class inside jsp it is not recognizing the class. Where might be the problem
    Plz help....
    Shamim

    hi , this is dheeraj.. i need to know that how to execute java code and class in jsp.. if anyone know about if bt tell me.. i just know that we can use java code by java beans in jsp.. if you know any knowledge regarding this topic please send me.....

  • Using java beans in jsp using tomcat

    hi i have made a form to enter user first name and last anme with html and then i have made a value javabean in which i want to store the information filled bu user. i want to display the information stored in java bean in jsp page i have made the full application and i have made class file of java bean as well as jsp file but when i try to run this web application in tomcat i am getting class not found exception.
    could anybody tell me that where i should store the bean class in tomcat and do i need to make any package in which i have to place my java bean file plz tell me complete procedure along with code if possible

    whew thats a lot of questions... All of this is pretty basic stuff. I would recommend you take a look at the web services tutorial: http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
    lets see.
    Starting a package name with com is just a generic standard which is followed.
    It is most correct when creating commercial packages to create packages like com.companyName.project
    http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html
    You should not need a page import directive unless you are using classes in scriptlets: ie <% %> tags in your JSP. Your jsp:useBean tag will automatically import necessary classes - you don't need to import classes for beans specifically
    <jsp:useBean id="myClass" scope="session" class="com.myPackage" />
    Your directory structure should be something like this
    webApplicationRootDirectory
    - page1.html
    - page2.html
    - page3.jsp
    - page4.jsp
    - WEB-INF
         - web.xml
         - classes
           - com
             - myPackage
               - myClass.classerrrm. Thats about it I think.

  • Calling java application from jsp using onUnload

    I have tried to find the answer to this by searching many jsp, js and java forums, but have not had much luck. I hope someone here can help out. I have written a jsp page that passes a sql string to a java application when it loads. That application creates an xml file (a report) and returns the filename, which is the target of an onclick event. What I want to do, is to delete the file when the page unloads. I have written a separate application that will delete the file, but onclick and onunload events apparently only take JavaScript commands. I have tried to embed the jsp code into an onunload event, but it runs when the page is originally loaded. In addition, I created a separate jsp page that deletes the file, and I call that page onunload using window.open(). I can set that page to self.close(), but I can't get the page to not show itself. Even if I set the height and width to 0 (or 1), it seems to appear 100X100. Can anyone give me any suggestions on what to do in this situation? Thanks.

    When my jsp page loads, I create the file using this code:
    String filename = printtasktest.createxml(closed,encodedSQLString);
    printtasktest is a java application on the server, that
    creates a file on the server, and passes the filename back to the jsp page. Later I use this filename as a target of an onclick event:
    <div class="button" onclick="printTask('<%=filename%>')">Print This Page</div>
    printTask() is a javascript function that opens the printable page using window.print() and self.close().
    The problem I have is that the file hangs around after, and I want to delete it when the user leaves the page.

  • Calling more than a Java method from C++

    Hi everyone,
    I haven't found any example with infomation about calling a second Java method from C++,after creating a VM from C++ also.
    Here is the code I'm testing:
    JNIEnv *env;
    JavaVM *jvm;
    JDK1_1InitArgs vm_args;
    jint res;
    jclass cls;
    jmethodID mid;
    jobject jobj;
    char classpath[1024];
    vm_args.version = 0x00010001;
    JNI_GetDefaultJavaVMInitArgs(&vm_args);
    sprintf(classpath, "%s%c%s",
    vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
    vm_args.classpath = classpath;
    res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
    if (res < 0) {
    fprintf(stderr, "Can't create Java VM\n");
    exit(1);
    cls = env->FindClass("Consola");
    if (cls == 0) {
    fprintf(stderr, "Can't find Prog class\n");
    exit(2);
    mid = env->GetMethodID(cls, "<init>", "()V");
    if (mid == 0) {
    fprintf(stderr, "Can't find Prog.main\n");
    exit(3);
    jobj = env->NewObject(cls, mid);
    if (jobj == 0) {
    fprintf(stderr, "Can't find Prog.main\n");
    exit(4);
    jmethodID mid2 = env->GetMethodID(cls, "isVisible", "()Z");
    if (mid2 == 0) {
    fprintf(stderr, "Can't find Prog.main\n");
    exit(5);
    jboolean b = env->CallBooleanMethod(cls, mid);
    All works fine till the last line.
    Folowing message appears in screen running the last code line:
    Runtime error!
    Program: s:\client\mcc_cyg\debg\debug\debgnt.exe
    abnormal program termination
    What to do ?
    Thanks in advance.
    Ignasi Villagrasa.

    There should be examples of this in the JNI tutorial.
    Also suggest a book: essential JNI by Rob Gordon
    Briefly, what you need is a reference to the JVM. (I assume you have this - either because it was given to you when your C code started the JVM, or because it was passed as an argument to your native method.)
    With the reference, you can look up a class, and look up a method, and call the method.
    What about an object reference?
    o You can call a method on an object which was passed to your native method.
    o You can ask one object for a reference to another object.
    o You can call a java constructor, which will return a reference.

  • 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

  • I want to call External Java class from the PL/SQL

    Hi,
    I am using Oracle Apps R11i (11.5.7), I wanted to call external Java class from the PL/SQL. This external Java class is residing in another application server.
    How do I do this.
    I know one way. Develop C routine in Oracle Apps to call external java class and call this C routine from the PL/SQL.
    Is there any simple method available? or any other method?
    Thanks in advance.
    -Venkat

    First of all, this is a Java application you're talking about, right (i.e. it has a main() function)? It's not just a class that you're trying to instantiate is it? If it's an application, you obviously have to start a new virtual machine to run it (rather than using the virtual machine built into the database like stored java). I'm a little leary of your mention of an "application server" as this would more commonly mean that a virtual machine is already over there running with access to this class. In which case, you'd typically interface with SOAP or some other RPC API.
    All that aside, as long as you have physical disc access (through NFS or whatever) to the class file, you could use a java wrapper class with a system call to do this. In fact, there is a thread in just the last day or so on this very forum that has the code to do just that (see " Invoking OS Commands from PL/SQL"). However, it's worth noting that the virtual machine will be running on the database server in this case and not the application server.

  • Calling Java Methods from Stored Procedures

    Can I call Java Methods from Oracle Stored Procedures? I have a Java framework that logs events and would like to reuse it for logging events that occur in stored procedures.
    null

    You need to publish java class methods to plsql.
    Attached below is some information.
    Although both PL/SQL modules and Java classes are stored in the database
    and are managed by many of the same mechanisms, each of them resides in
    its own namespace. Therefore, Java methods are not accessible from SQL
    and PL/SQL by default. In order to expose Java methods to the SQL and
    PL/SQL engines, first publish that Java method to the SQL namespace using
    a 'Call Spec'.
    Note: A 'Call Spec' does not create an additional layer of
    execution so there is no performance penalty incurred.
    A 'Call Spec' is simply a syntactical mechanism used to
    make a method known in the SQL namespace.
    The SQL name established by the 'Call Spec' can be top-level or packaged.
    The syntax differs only slightly and is consistent with that used for
    PL/SQL procedures and packages. For more information on the exact
    syntax, see the references listed in 'Related Topics'.
    In general, a top-level procedure 'Call Spec' takes the form:
    CREATE OR REPLACE PROCEDURE procname ( pname mode ptype, ... )
    AS LANGUAGE JAVA NAME 'javaname ( javatype, ... )';
    Where: procname is the SQL name you wish to publish
    pname is the name for a parameter to procname
    mode is the parameter mode (i.e. IN, OUT, IN OUT)
    ptype is a valid SQL type (e.g. NUMBER, CHAR, etc.)
    javaname is the fully qualified name of the Java method
    javatype is a Java type for the corresponding parameter
    Likewise, a top-level function 'Call Spec' takes the form:
    CREATE OR REPLACE FUNCTION fname ( pname mode ptype, ... ) RETURN rtype
    AS LANGUAGE JAVA NAME 'javaname ( javatype, ... ) return javatype';
    Where: fname is the SQL name you wish to publish
    rtype is the SQL return type of the function
    Note: Within the NAME clause, everything within quotes is case
    sensitive. For example, if the keyword 'return' is in all
    CAPS, this Call Spec will not compile.
    Other optional parts of this syntax have been omitted here for simplicity.
    Additional examples in subsequent sections illustrate some of these options.
    eg
    CREATE PROCEDURE MyProc (rowcnt IN NUMBER, numrows OUT NUMBER)
    AS LANGUAGE JAVA NAME 'MyClass.MyMethod(int, int[])';
    There are several important things to note here:
    1.) The 'Call Spec' for a JSP must be created in the same schema as the
    corresponding Java class that implements that method.
    2.) IN parameters are passed by value. This is the only parameter mode
    available in Java. OUT parameters, therefore, must be passed as single
    element arrays in order to emulate pass by reference.
    3.) Parameter names do not need to match, but the number and types of
    the parameters must match (with just one exception - see item 5 below).
    Oracle 8i supports conversions between an assortment of SQL and Java.
    See the references listed in 'Related Topics' for additional information.
    4.) Primitive types (e.g. int, float, etc.) are not required to be fully
    qualified with any package name. However, standard Java object types
    (e.g. String, Integer, etc.) as well as any user defined object types
    (e.g. like those generated by JPublisher) must be prefixed with a
    corresponding package name (e.g. java.lang) if applicable.
    5.) The 'main' method which takes a single String[] parameter can be
    mapped to any PL/SQL procedure or function which takes some number
    of VARCHAR2 or CHAR type IN parameters. For example, the java method:
    public static void main ( String[] args ) { ... }
    can be mapped to each of the following:
    PROCEDURE MyProc2 ( arg1 IN CHAR ) ...
    PROCEDURE MyProc3 ( arg1 IN CHAR, arg2 IN VARCHAR2 ) ...
    PROCEDURE MyProc4 ( arg1 IN VARCHAR2, arg2 IN VARCHAR2 ) ...
    and so forth. Parameters map to the corresponding element of the String
    array (e.g. arg1 -> args[0], arg2 -> args[1], etc.).
    null

  • Call java method from button in UIX page

    Greetings,
    I want to call a java method from a button on a uix page.
    Does it have to be a submit button or it maybe a simple button.
    If it was from a JSP page, it would be a much more different process ?
    This method should delete a row from another view (View2).
    delete from tableB ta where ta.field1 = &1
    My question is how do I build the method to delete a row and how do I invoke the method using the button ?
    Thanks

    This sounds like a JDeveloper/ADF issue that is not related to JHeadstart. Can you please log a TAR at MetaLink ( http://metalink.oracle.com/ ), or ask this question at the JDeveloper forum at http://otn.oracle.com/discussionforums/jdev.html ?
    Thanks,
    Sandra Muller
    JHeadstart Team
    Oracle Consulting

  • How to call external Java code from Animate project?

    I am creating a trainer using Animate that needs to interface with an aircraft model written in Java.  Is there a way to call external Java functions from Animate?
    Thanks!

    you can import external java files by yepnope
    yepnope({nope:[
                                  'your java script file address.js',
                             ],complete: init});
    function init() {
    codes that work with your js file can be write in here
    Zaxist

  • How to call java method from actionscript

    I've just now started working on Flex. May be its basic question but I’m not aware of it – how can I call a java method from actionscript. I want to call some java method on double click of a event. Can you please let me know how to proceed on this?

    OK. So, I think we can all conclude that you don't need to call any Java method, can't we? And, that wfUpdateMetadata is the command that will update your metadata.
    Now, the question is what are its arguments. It has two - the first is the name of a custom metadata field to be updated (let's suppose that one field is called xMinorVersion, and the other xMajorVersion), the other is the new value, e.g. <$wfUpdateMetaData("xMinorVersion", "New value.")$>As for new value - do you insist on using strings? Since you want to increase the value, it would be more convenient to work with numbers. For instance, with integers you could go with <$wfUpdateMetaData("xMinorVersion", xMinorVersion + 1)$>With strings you will need to convert it to numbers and back to strings. Besides, what happens if you have more than 100 minor versions? (you mentioned you want to add 0.01, but that would finally increase the major version, wouldn't it?) So, I think these two numbers are independent (perhaps, with exception that increase on the major version set the minor version to .00).
    If you want to present it, you can use profiles that will construct for you the representation 2.304 out of MajorVersion = 2, MinorVersion = 304
    Solved?

  • How to call java method from xsl

    hi friends,
    How to call a java method from xsl, i have a xsl file which will call the java method and retrieve the value and display it to the user. but its work well when i set xalan.jar and xerces.jar and the java class files in my classpath and run as
    java org.apache.xalan.xslt.Process -in navigate.xml -xsl nav-exst.xsl -HTML -out navoutpage.html[b]
    in the command prompt but when i deploy it as web application it gives error as
    [b]Namespace 'MyPack' does not contain any functions[b]

    OK. So, I think we can all conclude that you don't need to call any Java method, can't we? And, that wfUpdateMetadata is the command that will update your metadata.
    Now, the question is what are its arguments. It has two - the first is the name of a custom metadata field to be updated (let's suppose that one field is called xMinorVersion, and the other xMajorVersion), the other is the new value, e.g. <$wfUpdateMetaData("xMinorVersion", "New value.")$>As for new value - do you insist on using strings? Since you want to increase the value, it would be more convenient to work with numbers. For instance, with integers you could go with <$wfUpdateMetaData("xMinorVersion", xMinorVersion + 1)$>With strings you will need to convert it to numbers and back to strings. Besides, what happens if you have more than 100 minor versions? (you mentioned you want to add 0.01, but that would finally increase the major version, wouldn't it?) So, I think these two numbers are independent (perhaps, with exception that increase on the major version set the minor version to .00).
    If you want to present it, you can use profiles that will construct for you the representation 2.304 out of MajorVersion = 2, MinorVersion = 304
    Solved?

  • How to call java bean from jsp

    hi
    How to call a java bean from jsp page..
    Is any other way to call javabean from jsp page apart from this sample code...
    <jsp:useBean id="obj" class="com.devsphere.articles.calltag.TestBean"/>
    thnx in advance

    If you also use servlets, you can attach beans to the request or session and use them directly in your JSP's. So if you do:
    request.setAttribute("name", yourBean);and then forward to a JSP, you can reference the bean like:
    ${requestScope.name}

  • How to call java method from workflow script?

    Hi
    I have a requirement of updating field value 'Document Status' based on review/approve of content from Workflow and hence need to update the version number. For that I need to call my java method from workflow during submit of review/approve condition. Please let me know how to call java method from workflow?
    Is there any alternative better way to achive this requirement from workflow? Please suggest.
    Thanks,
    Sarang

    OK. So, I think we can all conclude that you don't need to call any Java method, can't we? And, that wfUpdateMetadata is the command that will update your metadata.
    Now, the question is what are its arguments. It has two - the first is the name of a custom metadata field to be updated (let's suppose that one field is called xMinorVersion, and the other xMajorVersion), the other is the new value, e.g. <$wfUpdateMetaData("xMinorVersion", "New value.")$>As for new value - do you insist on using strings? Since you want to increase the value, it would be more convenient to work with numbers. For instance, with integers you could go with <$wfUpdateMetaData("xMinorVersion", xMinorVersion + 1)$>With strings you will need to convert it to numbers and back to strings. Besides, what happens if you have more than 100 minor versions? (you mentioned you want to add 0.01, but that would finally increase the major version, wouldn't it?) So, I think these two numbers are independent (perhaps, with exception that increase on the major version set the minor version to .00).
    If you want to present it, you can use profiles that will construct for you the representation 2.304 out of MajorVersion = 2, MinorVersion = 304
    Solved?

Maybe you are looking for

  • Change apple id retain data

    i have got a iphone 4s from my partner, as see has upgraded and would like to change the apple id, app store accounts settings to mine, but i have been playing a game on it and would like to retain my progress on this game is this at all possible?

  • WHY WE NEED TO ADD PORT NUMBER 1433 TO TCP/IP PROTOCOL INSTEAD OF UDP PROTOCOL

    HELLO EVERYONE, WHILE INSTALLING SQL SERVER I HAD ENCOUNTERED A WARNING MESSAGE REGARDING  WINDOWS FIREWALL. AFTER SOME RESEARCH , I GOT TO KNOW THE STEPS TO TROUBLE SHOOT. IT SAYS I NEED TO GO TO WINDOWS FIREWALL AND ADD THE PORT NUMBER 1433 IN INBO

  • ERROR:Unreportted Exception java.io.IOEcxeption

    import java.io.*; public class MyFileWriter{      BufferedReader br;      InputStreamReader isr;      PrintWriter pw;      FileWriter fw;      File f;      String data; public MyFileWriter(){      isr=new InputStreamReader(System.in);      br=new Buf

  • Error message "ABAP/4 error during dynamic assign" on Contact Log creation.

    Hi, We are getting an error message "ABAP/4 error during dynamic assign beyond program bounds" displayed while creating contact log using transaction "BCT0". Please suggest what can be the cause of the error message and how we can remove this. Regard

  • Problem related to class loader and bootstrap loader

    how class are loaded and how bootstraping please explain it in detail?