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}

Similar Messages

  • How to call Java Beans from JSP (eg.put them in a WAR or package)

    Can anyone explain to me what are the steps and ways to call java beans from JSP?

    1st, put the javabean classes in the right place:
    the web-inf/classes/your_bean.class directory of corresponding web application
    2nd in your jsp page:
    <jsp:useBean id="obj_var_name" class="your_bean"/>
    <jsp:setProperty name="obj_var_name" property="smthg" value="smthg_calue"/>
    Micheal

  • Calling Java Bean From JSP

    <%@ page contentType="text/html;charset=windows-1252" errorPage = "error.jsp"%>
    <%@ page import="java.sql.*,java.io.*,javax.sql.*, mypackage1.*"%>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <title>Process</title>
      </head>
      <body>
          <P align="center">
            <STRONG><FONT face="Algerian" size="6" color="#0033cc">Result from the Query</FONT></STRONG>
          </P>
          <P align="center"> </P>
          <P align="center"> </P>
          <P align="center"> </P>
          <P align="center"> </P>
          <P align="center">
       <%
            int rowsChanged;
            Connection con;
            try
              String sql;
              sql = request.getParameter("query");
              System.out.println(sql);
              session=request.getSession(true);
              String name = (String)session.getAttribute("theID");
              String password = (String)session.getAttribute("paswd");
              String driver="oracle.jdbc.OracleDriver";
              Class.forName(driver);
              String url ="jdbc:oracle:thin:@minerva.humber.ca:1521:grok" ;      
              con = DriverManager.getConnection(url,name,password);
              if(sql.substring(0,6).equalsIgnoreCase("Select"))
                  Statement stat = con.createStatement();
                     ResultSet rs = stat.executeQuery(sql);
          %>
         <jsp:useBean id="myBean" scope="page" class="mypackage1.Table" >
               </jsp:useBean>
             <jsp:setProperty name="myBean" property="*" param="<%rs%>"/>
          <%
            myBean.setTable(rs);
            out.println(myBean.getTable());
         %>
          <%
           else
              Statement stat = con.createStatement();
              rowsChanged = stat.executeUpdate(sql);
              out.println("<h3><STRONG><FONT face=Algerian size=5 color=#0033cc>Number of rows affected are: "+rowsChanged+"</h3></Strong></Font>");
           }//End of Try
           catch(Exception e)
              System.out.println(e+ "gd"+ e.getMessage());     
          %>
          </P>
            <P align="center">
            <a href="check.jsp">Please Click Here to Return to Main Page</a>
          </P>
      </body>
    </html>Above is my JSP file, which is calling a Java bean class called Table. The thing is that Its not returning any Table from the Table Class. I dont know how to use Java bean as I m new to it. Following is my Table Class. So If anyone can plz help me then it would be great. I m suffering from 2 days just because of this class and JSP.
    package mypackage1;
    import java.io.Serializable;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    public class Table implements Serializable
      private ResultSet rs;
      public Table()
      public void setTable(ResultSet result)
        rs = result;
      public String getTable()
             String output=null;
             try
                    ResultSetMetaData metadata;
                    metadata=rs.getMetaData();
         // find the number of fields in customer table
                    int col=metadata.getColumnCount();
                    output = "<table/><tr/>";
                    for(int i=1;i<=col;i++)
                        output+="<td/><b/>"+metadata.getColumnName(i)+"</b/></td/>";
                    output += "</tr/>";
                    while (rs.next())
                           output="<tr/>";
                           for(int i=1;i<=col;i++)
                             output+="<td/>"+rs.getString(i)+"</td/>";
                           output += "</tr/></table/>";
                    }//End of While
               catch(Exception e)
        return output;
      }//End of Table method
    }//End of Class

    First reaction: yuck.
    This is not something you should be using a bean for.
    Beans are meant for storing data, not for generating HTML from.
    I don't really like queries on a JSP page either, but thats a different story again.
    I would recommend you use JSTL for this.
    1 - it provides a c:forEach tag for looping
    2 - it provides sql tags for doing queries in a database
    IF you are going to do database queries from a JSP page, I absolutely recommend you use the JSTL tags.
    (end rant)
    Your problem is probably caused by the fact that in your bean you have the following
    try{
      // code here
    catch (Exception e){
      // completely ignore exception and carry on as if nothing bad happened.
      // what you should be doing is something like:
      System.out.println("Error occurred " + e.getMessage());
      e.printStackTrace();
      return e.getMessage();
    }Cheers,
    evnafets

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

  • How to call  java program from ABAP

    Hi Experts,
         My requirement is to call java programs from ABAP. For that i have set up SAP JCO connection by using this link http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/739. [original link is broken] [original link is broken] [original link is broken] Connection gets sucessfully. After this how to call java program from ABAP as per our requirement. Please help me out.
      Also i tried this way also.. but while executing the DOS Command line appear & disappear in few seconds. So couldnt see the JAVA output. Please help me out to call java programs in ABAP..
    DATA:command TYPE string VALUE 'D:Javajdk1.6.0_20 injavac',
    parameter TYPE string VALUE 'D:java MyFirstProgram'.
    CALL METHOD cl_gui_frontend_services=>execute
    EXPORTING
    application = command
    parameter = parameter
    OPERATION = 'OPEN'
    EXCEPTIONS
    cntl_error = 1
    error_no_gui = 2
    bad_parameter = 3
    file_not_found = 4
    path_not_found = 5
    file_extension_unknown = 6
    error_execute_failed = 7
    OTHERS = 8.
    Thanks.

    This depends on the version of your Netweaver Java AS. If you are running 7.0, you will have to use the Jco framework. The Jco framework is deprecated since 7.1 though. If you want to build a RFC server in 7.1 or higher, it is adviced that you set it up through JRA.
    Implement an RFC server in 7.0:
    http://help.sap.com/saphelp_nw04/helpdata/en/6a/82343ecc7f892ee10000000a114084/frameset.htm
    Implement an RFC server in 7.1 or higher:
    http://help.sap.com/saphelp_nwce72/helpdata/en/43/fd063b1f497063e10000000a1553f6/frameset.htm

  • 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 API from BSP?

    I have a requirement to call Java API from BSP application.
    I have checked the forum and found that it is possible by using some ABAP codes.
    However there is no pointer on how this is done.
    Can someone explain the details on how to call Java API from BSP is done?
    I found class CL_EJB_JAVA_OBJECT_METHODS to call a method in EJB but can't find function or SAP class to call Java API.
    Actually is there any BSP extention which can used to call Java API?
    Thanks,
    Hendri

    check out these weblogs, it should give you an idea how to go about it.
    /people/ignacio.hernndez/blog/2006/12/04/speech-synthesis-listen-the-application-server-is-talking-to-you
    /people/puru.govind/blog/2006/12/20/let-abap-speak
    Regards
    Raja

  • How to call java implementations from C language

    How to call java implementations from C language....
    I know using JNI java can call C code....is the converse also possible????
    -Rams

    How to call java implementations from C language....
    I know using JNI java can call C code....is the
    converse also possible????Yes.

  • 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 call java function from PL/sql in oracle applications

    I am trying to call a java function from plsql procedure. Can any one explain how to call java function, and in which directory I have to store my java function in oracle applications. Do I need to register that java function from Application developer.
    Thanks
    Kranthi

    http://www.oracle.com/technology/tech/java/jsp/index.html
    Good Luck,
    Avi.

  • Stepping into Java Beans from JSP

    I am trying to figure out how to step into the Java Source code for my beans that are used in my JSP pages. I need to be able to debug them by stepping into them, using break points, etc.
    I have Nitro installed and a sample JSP page with the import to my test Java Bean class. What I did was create two projects in my work space. One as a Web project application and one as a Java project. I referenced and opened both projects. Everything compiles fine and the syntax is correct.
    The problem is I can not make the link for importing the class.
    I get this error: Class com.BrianTest.MyBean not found in import com.BrianTest.MyBean
    Anyone got a clue or a good example? I did try and add the class path and I tried to put it in a Jar file and attach the source to the Jar, but same problem.
    Thanks :?

    Stepping into jsp:useBean is not possible, but you can step-into jsp getter & setter tag.
    Since you are using java bean from a dependent project you need to configure your server with DevLoader.
    And currently only Tomcat server can be configured with Sysdeo Devloader to handle this situation
    Download Sysdeo DevLoader for Tomcat from http://www.sysdeo.com/eclipse/tomcatPlugin.html
    NOTE: If the project is self sufficient and not dependent on other projects/locations for classess/libraries then NitroX picks up all the libraries & classes present within default WEB-INF/lib & WEB-INF/classes respectively. And in this case you need not modify server configuration.
    Sysdeo DevLoader is to allow your web project to use libraries/classes from dependent projects. All you need to do is extract DevLoader.zip present within tomcatPluginV3.zip inside your Tomcat/server/classes folder.
    For more information about DevLoader please refer to http://www.sysdeo.com/eclipse/readmeDevLoader.html
    This will solve your problem and you should be able to run/debug your application. And most important make sure you have the correct NitroX build that supports Sysdeo DevLoader, refer http://www.m7.com/whatsnew.htm document against your build id (Help > About NitroX > NitroX Icon)

  • How to call java files from different directories

    hi, how do i call java files from a different directory??
    let say i got partA.java, and i need to include functions from partB.java which is in a different folder. how can i do that?

    Chicon wrote:
    Hi nuttynibbles,
    Before the class declaration in partA.java, you must have an import statement like :
    import someDirectory.partB;
    public class partA {
    ... and before you ask... you'll probably want to read through this http://java.sun.com/docs/books/tutorial/java/package/index.html

  • How to call a webservice from JSP

    I want to call a webservice from JSP? How can I do that .

    Check out this OBE and I think it's pretty well documented in JDeveloper help.
    http://www.oracle.com/technology/obe/obe1013jdev/10131/wsfromplsqlpackage/devwsfrom%20plsql.htm
    Thanks, Rob

  • How to call java class from pl/sql procedure ?

    Hello everyone,
    My query is..
    There is one pl/sql stored procedure which is doing some business logic and storing data in some columns of one table, suppose the table name is 'ABC' .. and the rest of columns of table ABC are getting updated using java class. Now my problem is whenever I insert data in ABC using store proc.. i have to call that java class so that it will update the rest columns ( why java class for updating the columns in ABC is ..because that logic cant be done from pl/sql proc.. it has to be done using java )
    and the other thing is.. oracle is in one machine and java is in another .. :(
    hope ..u can help me out !!
    Thank in advance !!

    but that updation have to be done from java code only.. we are using GIS tools .. have to create some shape files and update the column with that shape file.. so creation of shape file has to be done from java code only..
    so how to call java class file which is on another machine and oracle in another..

Maybe you are looking for