Using java class from JSP page

I have a class that connects to the database and return the result in form of array of objects, now I wrote a tester and I was able to print the result on the console but when it came to JSP how can I use this class I am a bit confused, how can I declare an array of objects and save the result that comes from the class method
note: my class is not a bean it is a service class that contain methods to retreive different information from the database.
I would apritiate any help but please make it in sequence for example declaring an array to hold the result then call the method that returns the array of objects..etc
please help, I am really confused and don't know what to write
thank you

You can access a class in the same way as a bean, after all a bean is just a class that follows a set of rules.
You need to put your classes in packages to access them.
I have 2 packages, params and DTO. I set the class that returns the Data Transfer Object, or array of objects up as I would a bean
<jsp:useBean id="DTO" scope="request" class="params.DTO" />
I think you skip the above declaration and access it directly in code using
params.DTO();
but setting it up as I would a bean allows me to simply use
DTO();
DTO is the class that passes back the array of objects.
Objects themselves I have in a seperate package, also called DTO (sorry if this is confusing, made sense at the time :-) ) You dont need them in seperate packages, just helped me keep DTO objects seperate from business logic classes......
Now before I use params.DTO() I declare a variable of the Object type DTO() returns
<%! DTO.workSheet[] ws; %>
So, ws is the object type that will be returned by params.DTO()
Then to get my array of objects back from params.DTO() :-
ws = DTO.workSheet(day);
or if you dont like the bean declaration
ws = params.DTO.workSheet(day);
You need to put your packages under WEB-INF/Classes when using Tomcat
So I have
Tomcat 5.0\webapps\myApplication\WEB-INF\classes\params
Tomcat 5.0\webapps\myApplication\WEB-INF\classes\DTO
Under which reside the classes

Similar Messages

  • 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

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

  • Calling my Java class from JSP page

    Hello, I am trying to call my Java class from my JSP page passing parameters to it and getting back a collection of result sets. Can someone tell me what I might be doing wrong:
    JSP code to call Java class:
    <%
    String strEssUser = "test";
    String strProcessingMonth = "JUL";
    String strProcessingYear = "2002";
    strQueryList=new ListReturn(strEssUser.toString(), strProcessingMonth.toString(), strProcessingYear.toString());
    %>
    I get this error when I try to run this JSP page using tomcat:
    C:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\em\jsp\Test_0005fSummarySBU_0005fscreen$jsp.java:77: Class org.apache.jsp.ListReturn not found.
    strQueryList=new ListReturn(strEssUser.toString(), strProcessingMonth.toString(), strProcessingYear.toString());
    I'm not sure if this problem is the way I am calling the Java class, or if I have a problem in the Java code itself. Can anyone help?

    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 use java class in jsp page of JSPProvider?

    Hello everybody.
    I created simple JSPProvider channel with portal amconsole and named it "jspprov1". Then I created "jspprov"1 directory under "/ets/opt/SUNWps/desktop/sampleportal". I put "index.jsp" in it. And it worked until I add this line into "index.jsp": <% @page import="jspprov1package.aclass1" %>. Then I created directory "jspprov1package" under "/ets/opt/SUNWps/desktop/classes" and put "aclass1.class" into it and into "/ets/opt/SUNWps/desktop/classes" itself. I created "aclass1.class" on the other machine (with no installed portal) in j2sdk1.4.1_02: "javac aclass1.java". The text of this class is simple:
    "package jspprov1package;
    public class aclass1{
    public int int_field = 10;
    But the page still don't work. It writes on the portal desktop "ERROR: Content is not available".
    Does anybody know why this happened?

    Sorry, there were mistakes in jsp page and java files.
    I maked the channel "show exceptions" and found them out.

  • Passing parameters from a Java class to Jsp page

    Hi everybody. I'm newbie in using Java class in conjunction with JSP pages. Infact I have a problem. How can I pass the parameters used in a Java class (as UserName, Password, and so on..) to a JSP page? What methods (and classes) I have to use?
    Thank you in advance
    Have a nice day

    It still doesn't work. I write the code
    //my java class
    package channel_service;
    import java.util.Vector;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public class CallMenu {
    private Vector parameters = new Vector();
    public void setParameters( String UserId ) {
    parameters.add(0, UserId);
    //parameters.add(2, Pin);
    //parameters.add(3, UserName);
    //parameters.add(4, Greeting);
    public Vector getParameters() {
    return parameters;
    //my jsp page
    <%@ page import="Channel_Service.src.channel_service.CallMenu" %>
    <%@ page import="java.util.Vector" %>
    <html>
    <head><title>User Menu Page</title></head>
    <body>
    <center><h1><i><b>This is your personal User Menu page</b></i></h1></center>
    <br>
    <br>
    <center><h2><i>In the list below you'll find all your personal information (as UserID, Password and so on...)
    and all the function you have the rights to use</i></h2></center>
    <br>
    <br>
    <table align=center>
    <tr>
    <%
    CallMenu cl = new CallMenu();
    cl.setParameters();
    Vector params = cl.getParameters();
    String UserId = (String)params.elementAt(0);
    String Pin = (String)params.elementAt(1);
    String UserName = (String)params.elementAt(2);
    String Greeting = (String)params.elementAt(3);
    %>
    <td><h2><b><i>User ID = <%= UserId %></td></tr>
    <tr><td><h2><b><i>PIN = <%= Pin %></td></tr>
    <tr><td><h2><b><i>User Name = <%= UserName %></td></tr>
    <tr><td><h2><b><i>The system says <%= Greeting %></td></tr>
    </table>
    </body>

  • Tag to take a java class in JSP page

    Hi,
    � need to get a tag to get a java class for example Test.java into a JSP page like MyJSP.jsp so that � can ,after doing this, call its methods, variables etc.
    Thank you !

    � know a way to do th�s us�ng JRun but the programme � have (NETBEANS IDE 3) does not accept �t.

  • Cant find bean class from jsp page using Tomcat 4

    Hi
    I have searched numerpus forums and seen many posts from people who seem to have the same problem however none of the solutions seem to work for me.
    I have a jsp page which is trying to call a bean method however I get an error
    saying that the class for the bean cannot be found. I have :
    1. put the class in a package called kolaBean under
    C:\Program Files\Apache Tomcat 4.0\webapps\ROOT\begjsp-ch01\WEB-INF\classes\kolaPackage
    2. included the package statement in the java file for the bean
    3. included an empty constructor in the java file for the bean
    4. I have declared the above constructor as public (is this necessary?)
    5. used the full package name:
    kolaPackage.kolaBean bakedBean = new kolaPackage.kolaBean();
    6. imported import java.beans.*; (is this necessary ?)
    7. still got the same error...
    Any pointers really really appreciated
    Thanks
    Kola

    in reply to David Rons email:
    Is this a fresh install of tomcat? If so, it could be a configuration
    problem.Yes it is
    Is the class public in the package (I forget that all the time)?Yes it is. I have also declared the constructor to be public is this
    necessary?
    What's the error message?here is the error message:
    An error occurred between lines: 11 and 14 in the jsp file:
    /begjsp-ch01/kolaBean.jsp
    Generated servlet error:
    C:\Program Files\Apache Tomcat
    4.0\work\localhost\_\begjsp-ch01\kolaBean$jsp.java:59: Class
    kolaPackage.kolaBean not found.
         kolaPackage.kolaBean bakedBean = new
    kolaPackage.kolaBean();
         ^
    2 errors
    Thanks in advance
    Kola

  • Import java-classes in JSP-page

    Hi,
    I'm starting with JSP and with trying one of the first examples in the book "beginning J2EE 1.4" from wrox, i got following problem.
    i'm trying to import a java-class in the package CH03 with
    <%@ page import="Ch03.FaqCategories" %>but he didn't find the package Ch03.
    I try already many things and i have no idea of the cause of the problem. So it's difficult to give information that leads to the solution.
    Maybe helpfull is the direcory-structure:
    jsp-page: /Ch03/welcome.jsp
    java-classe: /Ch03/WEB-INF/classes/Ch03/FaqCategories.class
    If you need source-codes or other information, just ask.
    Thanks,
    Dennis

    Thank you,
    Your help was one step into the good direction and that problem is solved.
    The application work now with studio one, but if i try it to work it with a stand-alone tomcat server it doesn't work anymore. I go first try to solve this problem by my self or at least try to describe the problem more exactly, before i ask for new help.
    but if you have any idea, that's always welcome...
    with regards,
    Dennis

  • Using java classes in jsp

    hi everybody
    I'm using Apache Tomcat 5.5.7 and I want to develop very very simple jsp-files.
    I have a java class file called MyClass.
    When I start the jsp file with the code line
    MyClass class = new MyClass();
    I get this error: MyClass cannot be resolved or is not a type
    As I know the hierachy must be the following:
    ProjectRoot/WEB-INF/classes/MyClass.class
    ProjectRoot/start.jsp
    In the java class the Constructor is empty... so I cannot see why this should make a problem. I also tried to put the class file into a package and import the package. I had the same error then.
    I read something about the web.xml file which should be in the WEB-INF directory.
    will this help me... and if yes, what do I need to write into it?
    If I did any mistake I would be happy if somebody could give me a hint.
    Cheers
    alex

    1 - The class needs to be in a package. eg com.mypackage.MyClass. This file lives in /WEB-INF/classes/com/mypackage/MyClass.class
    2 - in your jsp you include the line
    <%@ page import="com.mypackage.MyClass" %>
    <%
    MyClass myClass = new MyClass();
    %>
    3 - Also note that "class" is a reserved word in java, and can not be used as a variable identifier.
    4 - Yes you most probably should have a web.xml file in the WEB-INF directory.
    Look under the webbapps/ROOT/WEB-INF for a basic example.
    Cheers,
    evnafets

  • Scope of a java class in JSP page

    Hi
    If I use a java bean using the
    <jsp:useBean
    id="beanSomeName"
    scope="page|request|session|applicaton
    I can specify the scope of of the bean after which I can assume it is Garbage Collected.
    However if I just create a new Java Class in a jsp bean ( I inherited this code ) what will be scope of this java class. When will it be Garbage collected.
    Is it Page scope?
    Thanks
    bib/-

    If you do
    <% MyClass c = new MyClass(); %>
    and don't do anything else to store it in the request or session than it is like page scope.
    if you do
    <%! MyClass c = new MyClass(); %>
    it is more like application scope.

  • Ordinary java class and jsp page

    hi i want to use some java class(not javabean ) in my jsp . how do i import them and use them?

    You can just import the package into your JSP, and access it like any other class of the Standard Java API that you access.
    fun_one

  • Java class into jsp page

    hi i,m a beginnner
    how can i run my own java class into a JSP file?
    please help me!
    thanks

    If you understand the OO concepts and wrote the Java class right, then all you need to do is something like:YourJavaClass yourJavaClass = new YourJavaClass();
    yourJavaClass.doSomething();After all I rather recommend to use servlets for business logic instead of JSP (read: scriptlets).

  • Importing java classes into jsp page

    I'm trying to import java classes inside my jsp page, while doing that i am getting compilation error "package uma.natarajan.javaclasses" not found. I don't know where to copy the java files. i'm keeping my jsp files under public_html folder
              

    Hi uma,
              create uma\natarajan\javaclasses under weblogic_home\myserver and copy java
              classes(u want to import) to uma\natarajan\javaclasses and then u try.
              Concept is the java classes u import should be present in a classpath. Hope
              this may help u,
              Arun,
              [email protected]
              "uma natarajan" <[email protected]> wrote in message
              news:3a490bcb$[email protected]..
              > I'm trying to import java classes inside my jsp page, while doing that i
              am getting compilation error "package uma.natarajan.javaclasses" not found.
              I don't know where to copy the java files. i'm keeping my jsp files under
              public_html folder
              

  • Develpoing widgets using java in my jsp page

    hi all,,
    please help me how to delevop widget and embed in my jsp page,,
    and what are the tools needed to delelop widget,,,please help if you have any exaple,,

    thx skp,,
    i wants know more about widget,,what are those and how to develop and how to use them,,
    its urjent for me,,is there any link for that,,please help

Maybe you are looking for