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

Similar Messages

  • How to call java method using jsp

    how to call java method using jsp.....
    anyone can help me.....i having problem here...coz i very new in java and jsp.....
    thanks.....

    keep an eye on this person's thread...they have code there and everything.
    http://forum.java.sun.com/thread.jspa?threadID=777263&tstart=0

  • How to access class method in jsp page

    hi ,
    I am new to JSP . I want to access a method returning an arraylist
    of a class.
    this class i saved in WEB-INF>classes folder > where other classes like logonform , etc. are saved ....
    import stmt is <%@ page import="java.io.*, java.util.*, readXml " %>
    <% readXml rd= new readXml();
    Arraylist list=rd.parseDoc();
    %>
    It is not recognizing readXml class......
    Can any body help me in this regard......
    plz help .... i m in urgent need
    thanks in advance.......

    better to put class in a pkg inside webinf> classes folder ...
    but in my case constructor was not public......
    public readXml(){}
    now it works fine...... :)

  • How to call java method in jsp file?

    can anyone guide me or teach me how can i call the java method into the jsp file? do i need a main method to call it in? or just call the method that i need 2 use only??
    below is the coding that i did. one is java and another one is jsp. hope that someone can help me on it. Thanks!!!! Really appreciate it.
    Country Method.java
    package Test;
    import java.io.File;
    import com.db4o.*;
    import com.db4o.ObjectContainer;
    import com.db4o.ObjectSet;
    public class countryMethod {
         public final static String filename = "C:\\TestStore.yap";
         public String record;
         public int value;
         public String cName1;
         private static ObjectContainer db = Db4o.openFile(filename);
         public static void storeData() {
              //Delete existing data file
              new File(filename).delete();
              //Open Database
              db = Db4o.openFile(filename);
              //Add value into database
              Country c1 = new Country(100, "Malaysia");
              Country c2 = new Country(200, "Thailand");
              Country c3 = new Country(300, "Sing");
              Country c4 = new Country(400, "Japan");
              Country c5 = new Country(500, "Indian");
              db.set(c1);
              db.set(c2);
              db.set(c3);
              db.set(c4);
              db.set(c5);
              System.out.println("abc");
         public String getData() {
              String str = "";
              try {
                   //open database
                   ObjectContainer db = Db4o.openFile(filename);
                   //Create empty object
                   Country country = new Country(0,null);
                   //Object dataset
                   ObjectSet result = db.get(country);
                   //System.out.println(result.size());
                   while(result.hasNext()){
                        Country a = (Country)result.next();
                        record = a.getName();
                        value = a.getValue();
                        str = str +" | "+ value;
                        //System.out.println(str);
                        //System.out.println(a.getValue());
              }catch(Exception s){
                   s.printStackTrace();
              str = str +" | "+ record;
              return str;
         /*public int getValue(){
              return value;
    }and the jsp.
    <%@page import com.db4o.ObjectContainer%>
    <html>
    <head><title>Testing page</titile></head>
    <body>
    <jsp:useBean id="link" class = "Test.countryMethod" />
    <%=link.getData() %>
    </body>
    </html>

    i try on the easier that i can but still i have error displaying it
    here are the files
    package com;
    public class CountryPeople {
         public String name;
         private int value;
         public CountryPeople(String name, int value){
              this.name = "Eric";
              this.value = 2;
         public String getName() {
              return name;
         public int getValue(){
              return value;
    }JSP file will be
    <html>
    <head><title>Testing page</titile></head>
    <body>
    <jsp:useBean id="store" class="com.CountryPeople"/>
    <jsp:setProperty name="store" property="name" />
    <jsp:setProperty name="store" property="value" />
    <%= store.getName() %>
    <jsp:getProperty name="store" property="name" />
    <jsp:getProperty name="store" property="value" />
    </body>
    </html>JAVA File
    <html>
    <head><title>Testing page</titile></head>
    <body>
    <jsp:useBean id="store" class="com.CountryPeople"/>
    <jsp:setProperty name="store" property="name" />
    <jsp:setProperty name="store" property="value" />
    <%= store.getName() %>
    <jsp:getProperty name="store" property="name" />
    <jsp:getProperty name="store" property="value" />
    </body>
    </html>The end message is
    the error message
    at [org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
         at java.lang.Thread.run(Unknown Source)
    Hope that you guys can me. Thanks

  • How to use protected method in jsp code

    Could anyone tell me how to use protected method in jsp code ...
    I declare a Calendar class , and I want to use the isTimeSet method ,
    But if I write the code as follows ..
    ========================================================
    <%
    Calendar create_date = Calendar.getInstance();
    if (create_date.isTimeSet) System.out.println("true");
    %>
    ============================================================
    when I run this jsp , it appears the error wirtten "isTimeSet has protected access in java.util.Calendar"

    The only way to access a protected variable is to subclass.
    MyCalendar extends Calendar
    but I doubt you need to do this. If you only want to tell if a Calendar object has a time associated with it, try using
    cal.isSet( Calendar.HOUR );

  • How to access a method in webservice catalogued component in BPM Process

    Hi
    Can anyone explain me how to access a method in webservice catalogued component in BPM Process using an imported jsp in bpm process.
    Thanks & Regards
    Ashish

    If Class B only has a reference to an Interface A, and that reference points to a concrete instance of Class A, then of course Class B can still call the method on Interface A. The method for concrete instance Class A is called behind the scenes.
    That's how interfaces work. That's what they're good for.
    Look at the code in the java.sql package for examples. Connection, Statement, ResultSet - all are interfaces. But behind the scenes you're using the concrete implementations provided by your JDBC driver. You don't know or care what those classes are or their package structure. All you do is make calls to the java.sql interface API, and it all works. - MOD

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

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

  • How to call java method having array as argument from c++ ?

    Hello sir,
    how to call java method having array as arguments from c++;
    here is java code which is called from c++
    class PQR {
         public void xyz(int[] ia) {
         System.out.println("hi");
              for (int i = 0; i < ia.length; i++)
                   System.out.println(ia);
    suppose all jvm invocation is done...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    For someone well versed in java, C++ and JNI although tedious that should be obvious.
    For someone not well versed in all three it is going to be very difficult.
    Even for someone that does have knowledge in all of those areas coming up with a C++ interface that reflects that functionality in a dynamic way such that anyone is will to use it is going to be quite an adventure.
    At any rate to start building it you do exactly the same thing that you would in java.
    1. Extract everything in the jar via the zip package
    2. For each found instance extract all of the methods, return types, parameters, etc and build a description tree for each class.
    Doing all of that in C++ is going to take a LOT of code. If someone wanted an estimate from me it would take me 6 months to do it. And before I would even attempt it I would get them to explain to me in detail exactly how they thought they were going to use it when I was done because I can't see any reasonable way to do that.
    I left out the description tree itself. I suppose you could duplicate the entire reflection api in C++.
    Now perhaps if it was much, much more constrained, like to only those classes that implement a single interface then that would be more reasonable.

  • How to call java method on page load?

    How to call java method on page load?
    Thanks

    Hey Dan,
    Well, if you want to execute a java method when page is load, you need to put the clientlistener in af:document. Let me to show you an example (I can't find my post :P),
    JSPX page:
    <f:view>
    <af:document>
    <f:verbatim>
    <script>
        function loadPage(event) {
            alert('Hello World!');
    </script>
    </f:verbatim>
    <af:clientListener method="loadPage" type="load"/>
    </af:document>
    </f:view>If you try this code you can see that when the page has been load, you recieve the alert "Hello World!".
    Furthermore, this is the javascript AJAX function that let you to call a servlet:
    function ajaxFunction () {
        var httpRequest;
        if (window.XMLHttpRequest) {
            httpRequest = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            httpRequest.overrideMimeType('text/xml');
        httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
        httpRequest.open('GET', '/appname/servletname', false);
        httpRequest.send('');
    function alertContents(httpRequest) {
        if (httpRequest.readyState == 4) {
            if (!httpRequest.status == 200) {
                alert('Request error. Http code: ' + httpRequest.status);
    }Where 'appname' is your application name and 'servletname' is the name of the servlet that you want to call. Obviously, you can call any URL ;)
    JVN

  • Error while accessing EJB method from JSP

    Hi,
    I am trying to access a bean from a JSP and have the foll. code piece:
    String url = "t3://localhost:7001";
    public Context getInitialContext() throws Exception {
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    p.put(Context.PROVIDER_URL, url);
    return new InitialContext(p);
    String getStackTraceAsString(Exception e)
    // Dump the stack trace to a buffered stream, then send it's contents
    // to the JSPWriter.
    ByteArrayOutputStream ostr = new ByteArrayOutputStream();
    e.printStackTrace(new PrintWriter(ostr));
    return(ostr.toString());
    %>
    <%
    String op="";
    try {
    // Contact the AccountBean container (the "AccountHome") through JNDI.
    Context ctx = getInitialContext();
    out.println("initial context got !!");
    DemoHome home = (DemoHome) ctx.lookup("demo.DemoHome");
    out.println("home got !!");
    %>
    <p>
    <%
    Demo ac = null;
    try {
    ac = (Demo) home.create();
    out.println("create called!!");
    if (ac==null)
    out.println("ac is null!");
    catch (Exception ee) {
    out.print("exception 1");
    %>
    <p>
    <%
    try {
    out.println("going to call method!");
    if (ac!= null)
    op = ac.demoSelect(); /* FAILURE POINT */
    else
    out.println("ac is null->error!!");
    out.println(ac.demoSelect());
    out.println("string got!!");
    out.println(op);
    catch (Exception e) {
    getStackTraceAsString(e);
    e.printStackTrace();
    out.println("error 2");
    catch(Exception e)
    out.println("error 3!");
    It gives an error on trying to access the method "demoSelect".
    e.printStackTrace gives the output:
    java.lang.RuntimeException: javax.ejb.EJBContext.getEnvironment is deprecated in EJB 1.1. EJB 1.1 compli
    ant containers are not required to implement this method. Use java:comp/env instead.
    <<no stack trace available>>
    JSP output is as foll.-->
    getting initial context initial context got !! home got !!
    create called!!
    going to call method! error 2
    What is wrong???
    pls help!

    Greetings,
    Hi,
    I am trying to access a bean from a JSP and have the
    foll. code piece:
    <%
    String op="";
    try {
    // Contact the AccountBean container (the "AccountHome") through JNDI.
    Context ctx = getInitialContext();
    out.println("initial context got !!");
    DemoHome home = (DemoHome) ctx.lookup("demo.DemoHome");
    out.println("home got !!");Though it doesn't seem to be the problem in this case, good EJB coding practices dictate that your code should be narrowing the home reference before calling any of it's methods (i.e. create(...) )... WebLogic may allow handling of its protocol objects in their native state, but other vendors do not... your application is not portable without narrowing.
    It gives an error on trying to access the method "demoSelect".
    e.printStackTrace gives the output:
    java.lang.RuntimeException: javax.ejb.EJBContext.getEnvironment is deprecated inThe error is not in your JSP, but in the bean... it seems your bean is attempting to acquire its "environment properties" in the pre-1.1 style, when...
    EJB 1.1. EJB 1.1 compliant containers are not required to implement this
    method. Use java:comp/env instead. ...instead, it should be looking them up in its JNDI namespace.
    What is wrong???
    pls help! Regards,
    Tony "Vee Schade" Cook

  • How to access class members in jsp??

    i m working in jsp and i make a class Student having attribute name and id and i store it at tomcat\classes\Student.java
    and i store a jsp page at tomcat\webapps\root\student\index.jsp
    now i create object of class Student in jsp page it works
    but when i try to access name(Student.name) or id(Student.id)(or any class member of Student class)it shows error message
    now pls tell me how can i access class members in jsp page.

    i m working in jsp and i make a class Student having attribute name and id and i store it at tomcat\classes\mypack\Student.java
    and i store a jsp page at tomcat\webapps\root\student\index.jsp
    now i create object of class Student in jsp page it works
    but when i try to access name(Student.name) or id(Student.id)(or any class member of Student class)it shows error message
    now pls tell me how can i access class members in jsp page.
    Note: class members r public.

  • How to access a method of a class which just known class name as String

    Hi,
    Now I have several class and I want to access the method of these class. But what I have is a String which contain the complete name of the class.
    For example, I have two class name class1and class2, there are method getValue in each class. Now I have a String containing one class name of these two class. I want to access the method and get the return value.
    How could I do?
    With Class.forName().newInstance I can get a Object. but it doesn't help to access and execute the method I want .
    Could anybody help me?
    Thanks

    Or, if Class1 and Class2 have a common parent class or interface (and they should if you're handling them the same way in the same codepath)...Class c = Class.forName("ClassName");
    Object o = c.newInstance(); // assumes there's a public no-arg constructor
    ParentClassOrInterface pcoi = (ParentClassOrInterface)o;
    Something result = pcoi.someMethod(); Or, if you're on 5.0, I think generics let you do it this way: Class<ParentClassOrInterface> c = Class.forName("ClassName");
    // or maybe
    Class<C extends ParentClassOrInterface> c = Class.forName("ClassName");
    ParentClassOrInterface pcoi = c.newInstance();
    Something result = pcoi.someMethod();

  • Urgent-how to access custom tag from jsp tag

    I have a problem accessing a custom tag from a jsp expression.
    Details: I have a custom tag that returns a string variable. I need to access that variable from jsp expression <%%>.
    Can any body help me?

    Tags don't "return" values as in the normal sense.
    They can only support TEI (Tag Extra Information) that just stuffs a declared variable into the page's state.
    For example, if the tag class had a public method called getValue(), you could do the following:
    <xmp:mytag id="foo"/>
    <%
    out.println("value is " + foo.getValue());
    %>

Maybe you are looking for

  • **Tech explanation why BACKUPS take long, how to make it very short, etc*

    I noticed my backups to increase quite a bit over the last few days. I also noticed so many posts on why are backups taking so long, what can I do (only solution given is to click x or modify so that backups are not done, etc). Well to answer all tho

  • Activating Cost Component Split

    Hi People, I have to do some tests and for while i need to activate the "cost component split" in the path: \IMG\ Controlling\ Product Cost Controlling \ Actual Costing/Material Ledger \ Actual Costing \ Activate Actual Cost Component Split  (by valu

  • Unable to get package configuration option in .dtsx file.

    Hi Team, I am unable to get see the package configuraiton option on my package. I have created SSIS project in VS Data Tool of SQL SERVER 2012. Can you please, correct me with appropriate setting.

  • Problems with iPad Music App in iOS 5

    In iOS5 on my original iPad, the Music app is much more difficult to use. Right now a song is playing but I have a mostly black screen and no clear way to make the album art or lists of music visible. Any suggestions? I liked the iPod app before; thi

  • Traffic Shaping on a 2600 router (IOS ver 12.2.31)

    I have configured traffic shaping on a Fastethernet subinterface as follows; f0/0.1 traffic-shape rate 256000 7936 7936 1000 After reviewing the management graphs it looks as though the Traffic Shaping is not working as the graph shows a utilization