Calling class methods from jsp

hi - this seems like it should be painfully obvious but I am missing something somewhere and can't seem to get it to work.
The end result I am looking for is to be able to call a method similar to how I would do it in PHP or ASP.
To do this I have writte the following class (just as an example) and combpiled it to /WEB-INF/classes/com/example/util/Echo.class:
package com.example.util;
class Echo
public static void main(String[] args)
System.out.println(args[0]);
I then have a sample JSP that I attempt to use this in that looks like:
<%@ page import="com.example.util.Echo" %>
<%
RDmail("I'm using my Echo class.");
%>
My expectation would be that when I run this page in a browser, I see the text "I'm using my Echo class." printed out on the page. Instead I get the following error:
An error occurred at line: 1 in the jsp file: /classtest.jsp
Generated servlet error:
[javac] Compiling 1 source file
/var/tomcat4/work/Standalone/localhost/raindance/classtest_jsp.java:47: cannot resolve symbol
symbol : method Echo (java.lang.String)
location: class org.apache.jsp.classtest_jsp
Echo("I'm using my Echo class");
^
1 error
What am I doing wrong?

Umm... I'm not entirely sure what you're attempting to do, but it looks like there's some discrepancy between your error message and your code...
RDmail("I'm using my Echo class."); in your code
and
Echo("I'm using my Echo class"); in your error message.
Is this just a cut/paste error?
Also, the main() method is only called from a command line, and will not be run when you instantiate your bean in a JSP. If you want to have your String printed out when you create a new object, you should put the print statement in the constructor. Which would then be called when you created a new object..
Echo e = new Echo("I'm using my Echo class");
Or, you could create a static method inside Echo.java that prints out the statement.
Finally, your System.out most likely will not print to your browser, but probably to a standard log, or perhaps a command window.

Similar Messages

  • Call jpf method from jsp

    Is there anyway to call a method in Controller.jpf from a jsp page? I want to have my jsp page call a method from the jpf controller through an onChange event in the select tag. Otherwise I will have to write a large amount of javascript directly into my jsp page and really defeats the purpose of the MVC architecture. Any help is greatly appreciated. Thanks in advance.

    The jsp might look something like this:
    <netui:form action="DoThisOnChange">
    <!--all other jsp stuff-->
    <netui:select dataSource"" optionsDataSource="" onChange="this.form.submit()"/>
    </netui:form>
    And in JPF declare action named "DoThisOnChange" and write the logic to be done on event "onChange".
    --SJ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Does calling class methods from bean and JSP cause collision?

    Hi,
    Please look at the class below:
    public class X
    // no member variable
    public X() {}
    // pay attention to static keyword
    public static int getY()
    Think a bean (say BeanZ) that make calls to getY() method without initializing the class X (like this: X.getY() )
    And think many users having "page scope" in JSP make call to BeanZ or directly calls it from JSP.
    I'm wondering if any collision occurs because of STATIC method? Should I use "SYNCHRONIZED" keyword with it? If so, what about Math.cos() which also is a non synchronized static method ? Shouldn't I use Math.cos() (and the other static methods) in JSP or bean?
    Thank you for your help.
    Ali Sadik

    Hi,
    Thank you for your quick answer. Think my class like this:
    public class X
    // no member variable
    public X() {}
    // pay attention to static keyword
    public static int[] getY(int a, int[] b)
    // i know there is no need for the extra array.
    // just for example ;)
    int[] ret = new int[b.length];
    for(int i = 0; i < b.length; i++)
    ret[i] = a * b;
    return ret;
    Does it the type of class that you've mentioned ? It makes calculation to produce dynamic result. Shouldn't I use it as static ? If your answer is yes, what about Math.cos()? Doesn't it have dynamic calculation?
    Thanks a lot.

  • Calling a Method From JSP

    Hello People!!!
    I'm trying to call a method inside a viewObject from a JSP page using taglibs, but I don't know how to do this.
    Anyone can help me to do this call ??
    I need to pass a parameter to the method... this parameter is a column value!!
    thanks

    Are you trying to set a whereclause? If so you can always set the whereclause as an argument to your datasource tag.. An example of this is done in the Online Orders sample app at:
    http://otn.oracle.com/sample_code/products/jdev/content.html (see search_results.jsp)
    In general you can use the scriptable variable that you define for your BC4J Datasource to access different BC4J methods.
    Here's some code snippets showing different ways to access the BC4J Rowset (View Object) or the Application Module..
    <jbo:ApplicationModule id="Mypackage3Module" definition="Project3.Mypackage3Module" releasemode="Stateful" />
    <jbo:DataSource id="ds" appid="Mypackage3Module" viewobject="EmpView3" rangesize="3"/>
    <%
    ds.getRowSet().executeQuery();
    ds.getRowSet().first();
    ds.getRowSet()....(etc)
    // etc..
    or
    ds.getApplicationModule()....(etc)
    %>
    JSP Codeinsight will pop up your options..
    To ensure that Insight will work, make sure you have a closing scriplet marker.. "%>"...
    -Chris

  • How to call class file from jsp without creating packages

    i m using tomcat 5.5
    i stored my class file into WEB-INF\Class directory
    how to call that class file. from my jsp page.
    i got some error.
    i used package concept,that works fine.

    i m using tomcat 5.5
    i stored my class file into WEB-INF\Class directory
    how to call that class file. from my jsp page.
    i got some error.
    i used package concept,that works fine.Then use packages.
    As of Java1.4, you can no longer import classes from the default package (no package declared) into classes that are packaged.
    All Tomcat classes are in packages, including the compiled JSP.
    Therefore: Your classes need to be in a package inorder to be imported and used by the JSP.
    Why the problem? If you know it works with packages, why try not to use them?

  • Call static method from jsp expression

    Hi, I'm using adf/bc 10.1.3.4 I'm wanting to call a static method of a class when an af:commandLink is clicked. This action attribute value for this af:commandLink would be an el expression. As an example, let's say I want to call a new static method, named test(), I've added to ADFUtils.
    My af:commandLink looks like this:
    <af:commandLink action="#{ADFUtils.test}" />
    Obviously, this doesn't work. I can describe my actual use case if it would help. For now I'll just say that I don't want to use a managed/backing bean to house this method. How can I create a class to house this method w/o using a managed bean and adding that managed bean reference to the faces-config.xml?? Thanks, James

    thanks for the interest john. i'll explain what it is i'm trying to do. I have two web applications, appA and appB, both running in the same app server instance. The apps are related in the sense that once the user logs in thru an sso mechanism, they can 'bounce' back and forth between applications. Not sure if that info is relevant, but I wanted to include it anyhow.
    We've created a common banner/header jsp that we include in every page of appA and appB. Included in that header jsp is a logout link (af:commandLink), which will need to execute some code when clicked. Here is where the dilemma starts. We don't really want to have to write the code for the logout in a managed/backing bean because although both applications can use that same bean (we have it set up in the repository so that when a checkout/update is done on either appA or appB, each app, utilizing an svn external rule, would get both the banner jsp and the logout code that goes with it), making good use of the reusability concept, we would also have to add a reference to that backing/managed bean in the faces-config.xml of each application in order for it to be instantiated and used by each app. I was hoping to implement a solution which wouldn't require the developer to have to do any 'setup' on an application by application basis to use the header jsp and the code behind the Logout link. I've described a simple scenario, but in reality we'll have multiple applications, which means multiple places (faces-config.xml) where we'd need to add a reference to the managed bean which contains the logout code. It wouldn't be the end of the world for us if we ended up doing it this way, but I just have a feeling like there may be a better way to implement this so that each application's faces-config doesn't need to be touched. Hope my explanation is clear. thanks for any help you can offer.
    Edited by: kcjim on Feb 25, 2009 8:21 AM
    Edited by: kcjim on Feb 25, 2009 8:22 AM

  • Calling class methods from listSelectionListener

    Hi,
    I have a GUI class which containt a few Jlist. I also have two listSelectionListener classes. How do I reach methods in the GUI class from the listSelection classes. Can I pass a reference of GUI to them somehow?
    Karl XII

    For the benefit of future readers, the answer is yes, either in your listSelectionListener constructor, or a listSelectionListener method you implement. In either case, just set a listSelectionListener member variable (added by you) to the desired value.

  • Calling method from jsp file

    Hi
    is it possible to call any method with in the class except handle method from jsp file?

    You can call , but it would not be a good design approach.A droplet can do the same task for you.
    otherwise :
    eg :
    <%@ page import="com.mypackage.MyClass"%>
    for Static access :
    <%
    String test= MyClass.myMethod();
    %>
    for normal classes :
    <%
    MyClass object = new MyClass();
    String test= object .myMethod();
    %>
    http://stackoverflow.com/questions/10918526/call-java-method-in-jsp-file
    http://www.javaworld.com/javaworld/jw-05-2003/jw-0523-calltag.html?page=2
    ```
    Praveer
    Edited by: Praveer Rai on Mar 26, 2013 5:08 PM

  • Calling a method from a super class

    Hello, I'm trying to write a program that will call a method from a super class. This program is the test program, so should i include extends in the class declaration? Also, what code is needed for the call? Just to make things clear the program includes three different types of object classes and one abstract superclass and the test program which is what im having problems with. I try to use the test program to calculate somthing for each of them using the abstract method in the superclass, but its overridden for each of the three object classes. Now to call this function what syntax should I include? the function returns a double. Thanks.

    Well, this sort of depends on how the methods are overridden.
    public class SuperFoo {
      public void foo() {
         //do something;
      public void bar(){
         //do something
    public class SubFoo extends SuperFoo {
       public void foo() {
          //do something different that overrides foo()
       public void baz() {
          bar(); //calls superclass method
          foo(); //calls method in this (sub) class
          super.foo(); //calls method in superclass
    }However, if you have a superclass with an abstract method, then all the subclasses implement that same method with a relevant implementation. Since the parent method is abstract, you can't make a call to it (it contains no implementation, right?).

  • Need help calling a method from an immutable class

    I'm having difficulties in calling a method from my class called Cabin to my main. Here's the code in my main              if(this is where i want my method hasKitchen() from my Cabin class)
                        System.out.println("There is a kitchen.");
                   else
                        System.out.println("There is not a kitchen.");
                   }and here's my method from my Cabin class:public boolean hasKitchen()
         return kitchen;
    }

    You should first have an instance of Cabin created by using
       Cabin c = ....
       if (c.hasKitchen()) {
         System.out.println("There is a kitchen.");
       } else {
            System.out.println("There is not a kitchen.");
       }

  • Calling a method from another class... that requires variables?

    I'm calling a method from another class to change the date (its a date object) in another class.
    I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
    My code is:
    public int changeDate()
         cycleDate.setDate();
    }I'm guessing I need to pass 3 parameters (day, month, year), but I'm not sure how! I have tried, but then I get errors such as ')' expected?
    Any ideas! :D

    f1d wrote:
    I'm calling a method from another class to change the date (its a date object) in another class.
    I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
    My code is:
    public int changeDate()
    cycleDate.setDate();
    }I'm guessing I need to pass 3 parameters (day, month, year), seems that way from the error you posted
    but I'm not sure how!
    setDate(16, 6, 2008);
    I have tried, but then I get errors such as ')' expected?
    Any ideas! :Dyou need to post your code if you're getting specific errors like that.
    but typically ')' expected means just that, you have too many or not enough parenthesis (or in the wrong place, etc.)
    i.e. syntax error

  • Help on Calling a method from another class

    how can i call a method from another class.
    Class A has 3 methods
    i just want to call only one of these 3 methods into my another class.
    How can I do that.

    When i am trying this
    A a=new A;
    Its calling all the methods from class A. I just want
    to call a specfic method.How can it be done?When i am trying this
    A a=new A();
    Its calling all the methods from class A. I just want to call a specfic method.How can it be done?

  • Calling a method from another class or accessing a component from another

    Hi all
    im trying to make a find/replace dialog box
    my main application form has a jtextpane and when i open up the find and replace dialog box it has two textboxes (find and replace)
    now i have the code to do the finding on my jtextpane but how do i call that code to do the find method?
    I have tried having the code in my main application class but then how do i call that method from my dialog box class?
    ive also tried having the code in my dialog box class, but then how to i tell it to work on my jtextpane which is in my main ap class?

    well if someone had been nice enough to provide me
    with a tutorial i wouldnt have gotten into this
    muddle, no need to be rude is there!I'm not rude. And you also wouldn't have gotten into the muddle if you searched yourself. This site provides many very good tutorials about all kinds of stuff.
    http://java.sun.com/docs/books/tutorial/java/javaOO/classes.htmlAmong other things, it mentions that "static" defines everything that belongs to a class, as opposed to an object.

  • How to call a method from class interface

    Hi ,
    I want to call a method from a 'class interface' in a BADI .
    Class Interface -- /SAPSRM/CL_PDO_DO_BASE
    Method -- /SAPSRM/IF_PDO_DO_PARTNER_BASE~UPDATE_ITEM_PARTNERS
    Please let me know how can I call this method in my BADI.
    Thanks-

    Hi Harmeet,
    Follow these simple steps.
    1. Create an instance of class interface /SAPSRM/CL_PDO_DO_BASE if method /SAPSRM/IF_PDO_DO_PARTNER_BASE~UPDATE_ITEM_PARTNERS is instance method and
    call instance -> /SAPSRM/IF_PDO_DO_PARTNER_BASE~UPDATE_ITEM_PARTNERS
    2.if method /SAPSRM/IF_PDO_DO_PARTNER_BASEUPDATE_ITEM_PARTNERS is static method ,call directly using class interface like /SAPSRM/CL_PDO_DO_BASE=> /SAPSRM/IF_PDO_DO_PARTNER_BASEUPDATE_ITEM_PARTNERS.
    If you feel any dificulty in declaring instances and call methods, 
    Goto EDIT-> Pattern ->ABAP Object Patterns, Give class name , instance name and method, you got the required code.
    Thanks,
    Prasad.

  • How do you call a method from  another class without extending as a parent?

    How do you call a method from another class without extending it as a parent? Is this possible?

    Why don't you just create an instance of the class?
    Car c = new Car();
    c.drive("fast");The drive method is in the car class, but as long as the method is public, you can use it anywhere.
    Is that what you were asking or am I totally misunderstanding your question?
    Jen

Maybe you are looking for

  • ERROR 1002 WHILE ROCOVERY DISK HP G60-441 US WINDOWS VISTA 32BIT

    I HAVE HP G60-441US MODEL WITH WINDOWS VISTA 32BITS, PRODUCT NUMBER NW142UA. I TRY TO MAKE ROCOVERY DVD DISK WITH RECOVERY MANAGER BUT IT IS FIALED ON 2ND DVD. THEN I TRY TO RECOVERY WITH RECOVERY MANAGER IT SHOWS ME ERROR 1002 WHILE I PRESS OK ; COM

  • Supressing characteristic  values in query

    Hi, I have 10 records in my infoprovider.Each record contains data for 5 fields. Is it possible to suppress a particular field(i dont mean data here. It is field+data) for 5 records and show the field and its values for the remaining 5 records. Regar

  • Mail Auto Retrieval - Nokia 5800

    Hi, Im having a problem with Nokia's Email App on my 5800XM. I just set up 3 mail accounts, but i can configure automatic retrieval only for 2 of them. Is it limited just for 2 account (auto retrieval)? Is there any way to increase this value?. Hope

  • How to Display Exchange Rate in ME23N

    Hello SAP Gurus, We are using 4.6C. We can change or display the exchange rate of a PO in ME22N but unable to display the exchange rate in ME23N. In Transaction OMF4 (Define Screen Layout) I don't see field selection key ME23N to select the exchange

  • Viewing Nikon D300 images in finder

    Hi, Is there anyone out there using Nikon D300 with Mac Book Pro under OSX 10.5.1? Can you see the thumbnails? Can you see the NEF, TIFF, or PSD files in Finder? How do you view your photos? In Finder, if you click on one single pictures, does it clo