Accessing A DB From A JSP

Hi,
I've been using the code at the bottom of this message to access a database. I've been having some trouble though when the user stops the browser session mid way through a page loading. Occasionally it can cause the web server to crash. I'm guessing a connection must be left open somewhere, and that is causing the problem. Has anyone got any advice on ways I can avoid this?
Cheers,
Lee
import java.sql.*;
import java.util.*;
public class DBAccess {
  // Username, password & URL for accessing tables
  private String uname = "username";
  private String pword = "password";
  private String url = "Conn URL here";
  // Declare connection and statement that will be used to create recordsets
  private Connection conn = null;
  private Statement stmt = null;
  private ResultSet rs = null;
  private int rowCount = 0;
  private int colCount = 0;
  private Properties props = new Properties();
  private Driver drv = null;
  // Get records from table and return in a 3D array
  public String[][] getTableRecords(String strSQL) {
    // Ensure that the variables used are set to 0 or null.  This will ensure
    // that there are no errors related to the results containing info from a
    // previous procedure call.
    rs = null;
    conn = null;
    stmt = null;
    rowCount = 0;
    colCount = 0;
    props = new Properties();
    drv = null;
    try {
      drv = (Driver) Class.forName("somedriver").newInstance();
    catch (Exception e) {
      System.out.println(e);
      return null;
    // Set properties for making a connection
    props.put("user", uname);
    props.put("password", pword);
    try {
      conn = drv.connect(url, props);
      stmt = conn.createStatement();
    catch (SQLException e) {
      System.out.println("SQL Error : " + e);
      return null;
    String[][] results = new String[0][0];
    // Execute SQL Query
    try {
      rs = stmt.executeQuery(strSQL);
      ResultSetMetaData rsmd = rs.getMetaData();
      // Get amount of columns.
      colCount = rsmd.getColumnCount();
      while (rs.next()) {
        rowCount++;
      // Remember to reset the resultset
      rs.close();
      rs = stmt.executeQuery(strSQL);
      if (rowCount < 1) {
        results = null;
      else {
        results = new String[rowCount][colCount];
        int currentRow = 0;
        while (rs.next()) {
          for (int i = 1; i <= colCount; i++) {
            String currentField = rs.getString(i);
            if (currentField == null) {
              currentField = "";
            // -1 is used to make sure that the rows/columns with an index of 0 are filled
            results[currentRow][i - 1] = currentField;
          currentRow++;
      // Close everything
      rs.close();
      stmt.close();
      conn.close();
    catch (Exception e) {
      results = null;
      System.out.println("SQL Error : "+ e);
    return results;
  // Execute some SQL that doesn't return a recordset
  public void execSQL(String action) {
    try {
      drv = (Driver) Class.forName("drivername").newInstance();
    catch (Exception e) {
      System.out.println(e);
    // Set properties for making a connection
    props = new Properties();
    props.put("user", uname);
    props.put("password", pword);
    try {
      conn = drv.connect(url, props);
      stmt = conn.createStatement();
      stmt.execute(action);
      // Close connection and statement
      stmt.close();
      conn.close();
    catch (SQLException e) {
      try {
        conn.close();
        stmt.close();
      catch (Exception f) {
      System.out.println("SQL Error : " + e);
  // Return the number of columns that are in the resultset
  public int getNoOfCols() {
    return colCount;
}

There are more than one possibilities out there. I want to describe two of it.
1) For rapid software development, you can use taglibs (Java Standard Tag Libraries or jakarta db taglibs) in your jsps. There are also other taglibs from different vendors, but I know only these two.
2) You can use JNDI to establish a database connection through a datasource object. This is the more often way in a production environment. There are also possibilities with pooling and so on.
It depends, on what you want to develop, for a simple page or prototyping, and low traffic, it is possible to use taglibs. For a complete web application, it is better to establish the connection through Datasources, which are handled by the JSP / Servlet container or the application server.
so long
ThK

Similar Messages

  • Can't access a Bean from a JSP page !

    Hello everybody,
    I work with Oracle 8i 8.1.7, it means Oracle HTTP Server + Oracle JSP 1.1.0.0.0. But i don't use the Oracle Servlet Engine.
    In this context, i try to load ` JSP page, which instantiate a Bean. But it is impossible to access to this bean !...
    1) In jserv.properties file, i have mentionned the CLASSPATH to beans directory, as said in the OracleJSP documentation :
    wrapper.classpath=D:\...\myBeansDirectory\
    2) i have copied the .class file of my bean in the bean directory ...
    So did i forget something ?
    Seeking desperatly help !
    Thanks.

    Hi,
    Did you restart the HTTP listener after adding the CLASSPATH to the jserv.properties file? The change in jserv.properties (and in any other configuration files) will take effect only after the listener is restarted.
    Good luck,
    Srinivas.

  • ClassNotFoundException when trying to access applet (jar) from a jsp page?

    I have my applet in a jar file and I am specifying the applet tag in my jsp page as follows:
    <applet code="website.utils.DragDropUploadApplet.class" name="DragDropApp" width="17" height="17" archive="utils.jar" codebase="." ></applet>
    I tried with and without the codebase. The jar file is at the same location as the jsp page which has the above applet tag, however I get a ClassNotFoundException in the Sun Java Console in Internet Explorer. Any inputs on resolving this will be much appreciated.
    Here is the error:
    load: class website.utils.DragDropUploadApplet.class not found.
    java.lang.ClassNotFoundException: website.utils.DragDropUploadApplet.class
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
    at sun.applet.AppletClassLoader.getBytes(Unknown Source)
    at sun.applet.AppletClassLoader.access$100(Unknown Source)
    at sun.applet.AppletClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 10 more
    Exception in thread "Thread-12" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception in thread "thread applet-website.utils.DragDropUploadApplet.class" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    load: class website.utils.DragDropUploadApplet.class not found.
    java.lang.ClassNotFoundException: website.utils.DragDropUploadApplet.class
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
    at sun.applet.AppletClassLoader.getBytes(Unknown Source)
    at sun.applet.AppletClassLoader.access$100(Unknown Source)
    at sun.applet.AppletClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 10 more
    Exception in thread "Thread-13" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception in thread "thread applet-website.utils.DragDropUploadApplet.class" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    load: class website.utils.DragDropUploadApplet.class not found.
    java.lang.ClassNotFoundException: website.utils.DragDropUploadApplet.class
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
    at sun.applet.AppletClassLoader.getBytes(Unknown Source)
    at sun.applet.AppletClassLoader.access$100(Unknown Source)
    at sun.applet.AppletClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 10 more
    Exception in thread "Thread-14" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception in thread "thread applet-website.utils.DragDropUploadApplet.class" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    load: class website.utils.DragDropUploadApplet.class not found.
    java.lang.ClassNotFoundException: website.utils.DragDropUploadApplet.class
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
    at sun.applet.AppletClassLoader.getBytes(Unknown Source)
    at sun.applet.AppletClassLoader.access$100(Unknown Source)
    at sun.applet.AppletClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 10 more
    Exception in thread "Thread-15" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    load: class website.utils.DragDropUploadApplet.class not found.
    java.lang.ClassNotFoundException: website.utils.DragDropUploadApplet.class
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed.
    at sun.applet.AppletClassLoader.getBytes(Unknown Source)
    at sun.applet.AppletClassLoader.access$100(Unknown Source)
    at sun.applet.AppletClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 10 more
    Exception in thread "Thread-16" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception in thread "thread applet-website.utils.DragDropUploadApplet.class" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception in thread "thread applet-website.utils.DragDropUploadApplet.class" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Thanks,
    Monisha

    Hi mshah101,
    This can happen if the applet is compiled using an higher version of java and the browser is pointing to an older version (even if minor version number is higher)

  • Accessing input field from the JSP in dynpage

    HI all,
          I am trying to access the input field of the jsp page in my JSPDynpage but it is always return null.My Input is a normal HTML element not a HTMLB element
    JSP File :
         <hbj:content id="myContext" >
      <hbj:page title="PageTitle">
      <hbj:form id="myFormId" >
         <div class="content">
            <table cellpadding="2" cellspacing="2">
                        <tr>
                               <td>
                                  <label for="name"><strong>UserName:</strong></label><span id="info_name">(This field is required)</span><br />                           
                                     <input name="name" id="name" size="10" maxlength="10" type="text" />
                               </td>
                        </tr>
                        <tr>
                             <td>
                                  <label for="email"><strong>EmailID:</strong></label><span id="info_email">(This field is required)</span><br />                           
                                     <input name="email" id="email" size="20" maxlength="20" type="text" /></td>
                        </tr>\
    </Table>
    JSPDynpage:
           InputField myInputField = (InputField) getComponentByName("name");
         if (myInputField != null) {
          name = myInputField.getValueAsDataType().toString();
                   InputField myInputField1 = (InputField) getComponentByName("email");
         if (myInputField1 != null) {
          name = myInputField1.getValueAsDataType().toString();
    In both the cases myInputField and myInputField1 are null . My Question is what should be the parameter that i need to pass for getComponentByName method.
    Regards,
    Raj.

    hi,
    The way you are trying to get the input field value works good with hbj type elements.
    either you change your input field to an hbj one or use java script inside your jsp page to catch the value
    like
    for HTML:
    [HTML Input Field|http://www.w3schools.com/HTMLDOM/met_doc_getelementbyid.asp]
    and for HTMLB
    refer this link:
    [SAP HTMLB GuideLines|http://www.sapdesignguild.org/resources/htmlb_guidance/index.html]
    Regards,
    Srinu

  • Accessing user libraries from deployed JSP. Problem

    I've created a workspace and project contining 1 web bean "AQABeanPK1.AQATableView" .
    I then used the 'manage libaries' to add it to Jdeveloper as a library.
    I also added the webbean to Jdeveloper via the manage web objects tool
    In my jsp project I included the library in the project settings
    created a JSP and used the web bean from the component palette.
    When I deploy the JSP I get the error :-
    Errors compiling:C:\jdev903\j2ee\home\application-deployments\webapp1\webapp1\persistence\_pages\\_CustomersView1__Browse.java
    Line # Error
    118
    [jsp src:line #:22]
    Class AQABeanPK1.AQATableView not found. AQABeanPK1.AQATableView CA = null;
    129
    [jsp src:line #:22]
    Class AQABeanPK1.AQATableView not found. CA = (AQABeanPK1.AQATableView) pageContext.findAttribute("CA");
    134
    [jsp src:line #:22]
    Class AQABeanPK1.AQATableView not found. CA = (AQABeanPK1.AQATableView) pageContext.findAttribute("CA");
    139
    [jsp src:line #:24]
    Variable CA may not have been initialized. CA.render();
    If I create the webbean in the same project as the JSP then I get a successful run.
    Any help on deploying user libraires would be appreciated
    Cheers
    Colin

    Place your web bean .jar file in the OC4J j2ee\home\lib directory.

  • Accessing a EJB from a JSP

              A scenario from some one new to web server, server application development.
              I have downloaded and installed an evaluation copy of WebLogic 7.x and successfully
              installed it (W2K version). The product starts up without error and I can connect
              to is successfully. I have created a simple java bean (actually an EJB) and have
              been able to deploy it successfully without any errors.
              I have a simple JSP invoked from a simple HTML page that contains a simple form.
              The JSP is attempting to instaniate the bean via the jsp:useBean tag however,
              all I am able to get back is an error that tells me that my class "could not be
              loaded". Here is the stack trace:
              weblogic.servlet.jsp.JspException: (line 3): class 'USDataworks.MICRworks.MICRworksBean'
              could not be loaded
                   at weblogic.servlet.jsp.JspLexer.jspException(JspLexer.java:710)
                   at weblogic.servlet.jsp.JspLexer.processBeanTag(JspLexer.java:1372)
                   at weblogic.servlet.jsp.JspLexer.mXML_OPEN_USEBEAN(JspLexer.java:3612)
                   at weblogic.servlet.jsp.JspLexer.mXML_THING(JspLexer.java:1924)
                   at weblogic.servlet.jsp.JspLexer.mTOKEN(JspLexer.java:1817)
                   at weblogic.servlet.jsp.JspLexer.nextToken(JspLexer.java:1745)
                   at weblogic.servlet.jsp.JspLexer.parse(JspLexer.java:959)
                   at weblogic.servlet.jsp.JspParser.doit(JspParser.java:90)
                   at weblogic.servlet.jsp.JspParser.parse(JspParser.java:213)
                   at weblogic.servlet.jsp.Jsp2Java.outputs(Jsp2Java.java:119)
                   at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java:258)
                   at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:353)
                   at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:211)
                   at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:164)
                   at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:517)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:351)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:306)
                   at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:5445)
                   at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:780)
                   at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3105)
                   at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2588)
                   at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
                   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
              If I leave out the jsp:useBean tag I am able to return a simple HTML page based
              on information sent to the server, so I know some of the environment is properly
              set up.
              I have browsed through some of the WebLogic site and have been referred to any
              number of configuration files (*.properties) which do not appear to exist. I
              am frustrated and confused and would appreciate any help in getting this to work.
              Thank you.
              

              In the Weblogic 7.0.2 instalation, there is a tool for creating taglibrary to wrap
              an ejb cals to jsp tags. The tool names simply ejb2jsp and is described in document
              : "Programming Weblogic JSP" (pdf). My problem is: when I try to load my ejb ...jar
              file, the tool throws this Null pointer exception: (below).
              Have anybody some experience with this? It's the same for gui and cmd-line version.
              Could you advice me?
              Thank you.
              D:\SRC\jbproject\TestEntity>java weblogic.servlet.ejb2jsp.gui.Main
              error occurred: java.lang.NullPointerException
              java.lang.NullPointerException
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:287)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
              at weblogic.servlet.ejb2jsp.Utils.createBeanDescriptor(Utils.java:343)
              at weblogic.servlet.ejb2jsp.Utils.createDefaultDescriptor(Utils.java:314
              at weblogic.servlet.ejb2jsp.Utils.createDefaultDescriptor(Utils.java:266
              at weblogic.servlet.ejb2jsp.gui.Main.loadFromPaths(Main.java:391)
              at weblogic.servlet.ejb2jsp.gui.Main.doNew(Main.java:378)
              at weblogic.servlet.ejb2jsp.gui.Main$5.run(Main.java:575)
              at weblogic.servlet.ejb2jsp.gui.MainWorker.run(Main.java:757)
              at java.lang.Thread.run(Thread.java:479)
              error occurred: java.lang.NullPointerException
              java.lang.NullPointerException
              at weblogic.servlet.ejb2jsp.gui.Main.doNew(Main.java:379)
              at weblogic.servlet.ejb2jsp.gui.Main$5.run(Main.java:575)
              at weblogic.servlet.ejb2jsp.gui.MainWorker.run(Main.java:757)
              at java.lang.Thread.run(Thread.java:479)
              "Xiang Rao" <[email protected]> wrote:
              >
              >EJB and Java Bean are two different things. I don't think you can use
              >useBean tag
              >for EJB. On the other hand, you can write a Java Bean to wrap your EJB
              >and use
              >useBean tag.
              >
              >"Marek Kossak" <[email protected]> wrote:
              >>
              >>A scenario from some one new to web server, server application development.
              >>
              >>I have downloaded and installed an evaluation copy of WebLogic 7.x and
              >>successfully
              >>installed it (W2K version). The product starts up without error and
              >>I can connect
              >>to is successfully. I have created a simple java bean (actually an
              >EJB)
              >>and have
              >>been able to deploy it successfully without any errors.
              >>
              >>I have a simple JSP invoked from a simple HTML page that contains a
              >simple
              >>form.
              >> The JSP is attempting to instaniate the bean via the jsp:useBean tag
              >>however,
              >>all I am able to get back is an error that tells me that my class "could
              >>not be
              >>loaded". Here is the stack trace:
              >>
              >>weblogic.servlet.jsp.JspException: (line 3): class 'USDataworks.MICRworks.MICRworksBean'
              >>could not be loaded
              >>     at weblogic.servlet.jsp.JspLexer.jspException(JspLexer.java:710)
              >>     at weblogic.servlet.jsp.JspLexer.processBeanTag(JspLexer.java:1372)
              >>     at weblogic.servlet.jsp.JspLexer.mXML_OPEN_USEBEAN(JspLexer.java:3612)
              >>     at weblogic.servlet.jsp.JspLexer.mXML_THING(JspLexer.java:1924)
              >>     at weblogic.servlet.jsp.JspLexer.mTOKEN(JspLexer.java:1817)
              >>     at weblogic.servlet.jsp.JspLexer.nextToken(JspLexer.java:1745)
              >>     at weblogic.servlet.jsp.JspLexer.parse(JspLexer.java:959)
              >>     at weblogic.servlet.jsp.JspParser.doit(JspParser.java:90)
              >>     at weblogic.servlet.jsp.JspParser.parse(JspParser.java:213)
              >>     at weblogic.servlet.jsp.Jsp2Java.outputs(Jsp2Java.java:119)
              >>     at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java:258)
              >>     at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:353)
              >>     at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:211)
              >>     at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:164)
              >>     at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:517)
              >>     at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:351)
              >>     at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:306)
              >>     at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:5445)
              >>     at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:780)
              >>     at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3105)
              >>     at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2588)
              >>     at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
              >>     at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
              >>
              >>If I leave out the jsp:useBean tag I am able to return a simple HTML
              >>page based
              >>on information sent to the server, so I know some of the environment
              >>is properly
              >>set up.
              >>
              >>I have browsed through some of the WebLogic site and have been referred
              >>to any
              >>number of configuration files (*.properties) which do not appear to
              >exist.
              >> I
              >>am frustrated and confused and would appreciate any help in getting
              >this
              >>to work.
              >>
              >>Thank you.
              >
              

  • Impossible to access a bean from a JSP in NES 4.0

    We are trying to use a bean in a JSP using the common tag <jsp:useBean id="... /> in a Netscape Enterprise Server 4.0.
    Always we obtain the same error: "JSP compilation error: java.lang.Exception: JSP parse error (line 43) - Incomplete tag ending of /jsp:useBean". Someone can help us?
    Thanks.

    Check NAS4.0 supports jsp 0.92 specs?
    use this tag...
    <USEBEAN name="..." type="..." lifespan="..." >
    </USEBEAN>

  • 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

  • Accessing file shares from JSP

    Hi,
    I need to be able to access file shares from a JSP page. Here's the JSP code:
    <%@ page language="java" %>
    <%@ page import="java.io.*" %>
    <%@ page errorPage="errorPage.jsp" %>
    <%
    String fileSystemPath = "\\\\130.26.1.199\\MeetingManager30\\test.txt";
    File f = new File(fileSystemPath);
    f.createNewFile();
    %>The above code resides in a server with IP 130.9.68.6 and is deployed onto the Tomcat on the server.
    When I tried to run the above code, I got this error
    java.io.IOException: Access is denied at java.io.WinNTFileSystem.createFileExclusively(Native Method) at java.io.File.createNewFile(File.java:827) at org.apache.jsp.test_jsp._jspService
    (test_jsp.java:55) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServletWrapper.service
    (JspServletWrapper.java:210) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at
    javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke
    (StandardWrapperValve.java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContextValve.invoke
    (StandardContextValve.java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422) at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171) at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke
    (StandardEngineValve.java:174) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199) at
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:833) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processCon
    nection(Http11Protocol.java:711) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run
    (ThreadPool.java:687) at java.lang.Thread.run(Thread.java:536) Seems like I'm having a system level security setting problem here.
    I know it's a security issue, because I've encountered the equivalent problem in ASP/IIS, and I had to give a domain user rights to both the IIS Virtual Directory, and the file share to be able to access.
    Any ideas how to set up Tomcat to be able to access the file share successfully?
    Thanks in advance!

    Hello Veer,
    From what you have posted it looks like while logging your error another problem occurred. Did you get any output from your System.out calls? If not can you try adding a few in order to home in the problem area.
    Hussein Badakhchani
    www.orbism.com

  • Accessing variable from another JSP

    Friends,
    say, I have a Test1.jsp which has a variable "input". Is it possible to access this variable from other jsp "Test2.jsp"?
    any ideas?
    Thanks
    Hari V

    hi hari,
    there are essentially 3 ways of doing it....
    1).Usage of Hidden Values
    2).Using Cookies
    3).Storing attribute value within the scope of request/session/appln
    The choice is all urs....???
    Regards,
    RAHUL

  • Can I access a SessionBean property from my JSP?

    Is there any way to access SessionBean1 properties from the JSP. I have a JSP that I use to access a servlet. I set the location of the servlet in my JSP script code.
    Example:
    <script language="javascript">
    var servletLocation = "http://123.456.7.890/SpyServlet/spy";
    </script>
    I do not want to hard-code the location because they are different between DEV and Produciton. I thought I could set the location via a configuration file into a session bean property and then retrieve it in my JSP script. Can anyone please tell me how to do this?

    If that doesn't work, you can add a session attribute as follows.
    First, define the attribute in a page's backing bean.FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    HttpSession session = (HttpSession)externalContext.getSession(false);
    session.setAttribute(<varName>, <varValue>);Depending on the attribute's type, you may have to import some packages into the JSP page.
    <jsp:directive.page import="java.util.*, java.text.*, com.cfi.office.schema.tables.*" />If the attribute is a Java bean, you may have to include the useBean directive in the JSP page.<jsp:useBean id="mgtAddress" type="com.cfi.office.schema.tables.Address" scope="session" />Second, get the attribute's value in the JSP.value = (<varType>)session.getAttribute(<varName>);

  • How can I access xml document from javascript whithin a JSP page

    how can I access xml document from javascript whithin a JSP page?
    I have a JSP that receives an XML document from a JavaBean, so I can access it within the entire JSP, but I need to access it from the javascript inside the JSP... and I have no idea how i can do this.
    Thanks in advance!

    The solution would only work on MS IE browsers, as other browsers do not support an XML DOM.
    It can be done, but you would be stuck with using the Microsoft broswer. If that is acceptable, I have some example code, and a book recommendation.

  • Accessing custom classes from JSP

    Hi Guys,
    I am having some problems accessing my custom classes from my JSP.
    1) I've created a very simple class, SimpleCountingBean that just has accessors for an int. The class is in the package "SimpleCountingBean". I compiled this class locally on my laptop and uploaded the *.class file to my ISP.
    2) I've checked my classpath and yes, the file "SimpleCountingBean/SimpleCountingBean.class" is located off of one of the directories listed in the classpath.
    3) When I attempt to use this class in my JSP, via the following import statement:
    import "SimpleCountingBean.*"
    I get the following compile error
    java.lang.NoClassDefFoundError: SimpleCountingBean/SimpleCountingBean
    I'm pretty sure that my classpath is properly setup because when I purposely garble the import statement, I get the "package not found" compile error.
    Do I need to upload some other files in addition to the class file? Any suggestions would of course be appreciated.
    Sonny.

    Trying to get some clearer view.. so don't mind..
    So you uploaded all your .jsp files into your account which is:
    home/sonny
    and it compiles and work. But custom classes doesn't seems to be working, where did you place your classes?
    From my knowledge of tomcat, classes are normally placed in, in this case:
    home/sonny/web-inf/classes
    Maybe it differs from windows enviroment to *nix enviroment.. well, I'm just saying out so if its not the case.. don't mind me.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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());
    %>

  • Problem with accessing init parameters from JSP file

    Hi,
    I have my init parameters and Jsp configured in web.xml
    <servlet>
              <servlet-name>TestJsp</servlet-name>
              <jsp-file>/Test.jsp</jsp-file>
              <init-param>
                   <param-name>username</param-name>
                   <param-value>Balboa</param-value>
              </init-param>
    </servlet> How do I access 'username' field from JSP file.
    Kindly help.
    Thanks.

    you can do this in the jsp
    <%=config.getInitParameter("username")%>or do it in the jspInit method in the jsp:
    <%!  String userName = null; 
      public void jspInit() {   
        ServletConfig config = getServletConfig();   
        userName   = config.getInitParameter("userName ");  
    %>
    Hello <%=userName%>

Maybe you are looking for

  • CRM 7.0 Email Spell Check

    Hello all, Iu2019m currently working on an upgrade project.  My client is upgrading  from CRM 4.0 to CRM 7.0.  During the upgrade we are implementing Email for CRM and my client is looking for auto spell checker to scan the body of the email.  My cli

  • How to set different icon for different type of document

    Hi, In my repository, we have different kinds of document (crystal report, word document, excel, jpg ...) and we wanna show specific icon for each kind. In my used ResourceRender I cann't see where to change (rnd:icon?) Could someone tell me how to a

  • The   symbol in the calendar is Off

    In the calendar the + symbol is off??

  • Using the iPhone with another SIM???

    Hi, I am really considering getting an iPhone 3GS at the weekend. However I was wondering if it would be fully operational using a sim card other than the one given with it. I know it will be locked to the network but I dont know if its a special sim

  • Specific number in Thailand has become unavailable...

    Hi Every now and then i need to call DTAC`s call center in Thailand to renew an internet subscription. From approximately two months ago calling +6622028100 (DTAC`s call center) gives the following message translated from norwegian "you can not call