Using normal classes in a JSP

I have written a library of classes for use in a standard application. In a completely separate project I need to use these classes in a JSP page. Under %tomcat/webapps/myproject is the JSP file. Where do I place the "normal" class files and how do I reference them in the JSP page? Do I need to import them or add them to the classpath and should they be pre-compiled ?
All help most appreciated
Thanks
Bob

Where do I place the "normal" class files and how do
I reference them in the JSP page?Just like you use any other class in a JSP.
Do I need to import them or add them to the classpath and should they be pre-compiled ?Yes, yes and yes. The first thing is something you need to do for your stuff to compile (technically, you don't need to do it, but it's better than always using the fully qualified class names in the code). The second is something the servlet container will do for you when you deploy your WAR. The this is something you need to do with classes anyway. You don't need to do it for JSPs because the container will do it later, but that's all the difference there is.

Similar Messages

  • Please help to use my class in a JSP

    Hi
    Please could someone help me i've started a new job and need to create like a "Add to shortlist" functionality to their website.
    I have created a class to create a cookie using the offerid specific to that page which is done in the doGet() method.
    Now, the problem is that i don't know how to basically make the cookie be created when the button is pressed.
    I have thought of using <jsp:useBean> and putting my class in there but don't know how to call the doGet() method, if you know what i mean.
    Otherwise i've thought of doing the cookie creating in the JSP but then also i don't know how to make by the click of a button, it creates a cookie with that offerid.
    PLEASE help!? If you need more info pls let me know,
    Btw i am new to this so sorry if this sounds stupid, but thanks in advance for ANY help!

    There is only one thing to do in your case: hit the books and learn how to properly program servlets and JSPs - until you know at least the very basics (clicking a button and "doing something" falls in that category), it will be impossible to guide you to anything productive. I've seen it happen before many times; an answer is given, the answer is not understood and then the demand for "sample code" pops up, after which it all goes downhill fast.
    I always recommend this free online book, because it is quite good:
    [http://pdf.coreservlets.com/|http://pdf.coreservlets.com/]
    If you buckle down, you should be able to get things up and running in a few days. Good luck!

  • Using normal class file in the servlet

    Hello Friends;
    Now my problem is ;
    I generated a java file ;
    import drasys.or.mp.*;
    import drasys.or.mp.lp.*;
    public class optimize
        public static void main(String[] args)
        try
            int r=1;
            int s=0;
    .This file works perfect. It calls an API and there is no problem. But when I take this code into my servlet, then problem starts. First it says;
    "java.lang.NoClassDefFoundError: drasys/or/mp/ScaleException"
    but I know it is there. And I mounted the jar file.
    Do you think there is a problem with my codes, because it works when it is outside of the servlet.
    My servlet code is as follows;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import java.net.*;
    import drasys.or.mp.*;
    import drasys.or.mp.lp.*;
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
             try
            int r=1;
            int s=0;
            int n = 3;
            int t,w,u,v,f;
            f = 1;
            int z=0;
            int y = 1;
            int l = 1;
            double [][][][] C = new double [1][1][n-1][n];
            double [][][][] D = new double [1][1][n-1][n];
            C[0][0][0][1]=2.5-0.92*r;
            C[0][0][0][2]=1.43-0.37*r;
            C[0][0][1][2]=1.14-0.48*r;
            D[0][0][0][1]=0.65*r+0.94;
            D[0][0][0][2]=0.31*r+0.75;
            D[0][0][1][2]=0.27*r+0.40;
         SizableProblemI prob = new Problem(n*(n-1)+1,n);
            prob.getMetadata().put("lp.isMaximize", "true");
            prob.newVariable("Lambda").setObjectiveCoefficient(1.0);
            for (t=0;t<=(n-1);t++)
                prob.newVariable("W"+t).setObjectiveCoefficient(0);
            final byte LTE = Constraint.LESS;
            final byte EQU = Constraint.EQUAL;
            for (v = 1;v <= n*(n-1);v++)
                   prob.newConstraint("constr"+v).setType(LTE).setRightHandSide(y);
                prob.newConstraint("constr"+(n*(n-1)+1)).setType(EQU).setRightHandSide(1);
                // here, we are creating coefficients for lambda.
            for (u = 1; u <= n*(n-1); u++)
                    prob.setCoefficientAt("constr"+u,"Lambda",y);
    // here, we are creating coefficients for W�s.
            for(t = 0 ; t <= (n-2); t++)
                for (w = 1; w <= (n-1); w++)
                     if (t<w)
                         prob.setCoefficientAt("constr"+l, "W"+t, 1);
                         prob.setCoefficientAt("constr"+l,"W"+w, (-C[s][z][t][w]));
                         l = l + 1;
                         prob.setCoefficientAt("constr"+l, "W"+t, -1.0);
                         prob.setCoefficientAt("constr"+l, "W"+w, D[s][z][t][w]);
                         l = l + 1;
    /* here , we are creating coefficients for the last formula which is w1+w2+w3+....Wn = 1 */
                for (f=0; f <= (n-1); f++)
                prob.setCoefficientAt("constr"+(n*(n-1)+1), "W"+f, 1);
    /* API finds the solution below.*/
         LinearProgrammingI lp = new DenseSimplex(prob);
            double ans = lp.solve();
            System.out.println("Solution"+r+"="+ans);
            System.out.println(lp.getSolution());
            catch (drasys.or.mp.DuplicateException first)
             first.getMessage();
            catch (drasys.or.mp.NotFoundException second)
            catch (drasys.or.mp.InvalidException third)
            catch (drasys.or.mp.NoSolutionException fourth)
            catch (drasys.or.mp.UnboundedException fifth)
            catch (drasys.or.mp.InfeasibleException sixth)
            catch (drasys.or.mp.ConvergenceException seventh)
            catch (drasys.or.mp.ScaleException eigth)
               eigth.toString();
       

    Thanks a lot for the reply.
    Forgive me, I have no object oriented background,
    even programming. I am just in the learning phase.This is a pretty advanced problem to tackle for your first programming task.
    That's why it doesn't follow OO concepts. This part
    will be connected to user input part, that I've
    completed .Hmmm.
    Successful programming depends on one idea: "divide and conquer". You take a big problem and solve it by dividing it into smaller chunks that you CAN handle. You get the solution you want by bringing the smaller chunks together.
    In your case I'd recommend that you get the optimization code into a single object that you can test off-line, without Tomcat. It looks like you started to do that with your optimize class, but the mistake you made is to put so much code into the main() method. You can only call that on the command line. Better to encapsulate the rest of it into small methods that will let you instantiate an instance of optimize and call its methods. Once you have that working you can wrap it in a servlet if you want to use it in a Web app.
    Separate how your optimizer gets its data from how it processes it. On a desktop app, it might be convenient to read input from a file on disk. A Web app might be better served by an XML stream.
    Why I said "I know it is there" because it doesn't
    give any other error message than that one, if it
    couldn't see the jar file, wouldn't it give me lots
    of error messages? Don't assume anything. It only needs one error, which is the one you get when it can't find a class. How many more do you need? The class loader couldn't find that class, so it printed the message and stopped.
    "I mounted" the jar file means I'm using Netbeans, I
    mounted it to that environment as suggested by
    Netbeans, If you don't know Java or programming well, I'm guessing that you also don't know NetBeans. I'd recommend that you figure out how to make all this work without NetBeans before you add another complication to your life.
    If you don't use NetBeans, all you have to do is add the JAR to your CLASSPATH using the -classpath option on javac.exe when you compile and java.exe when you execute.
    Tomcat assumes that all the JAR files in your Web app's WEB-INF/lib are in the CLASSPATH. If you put it in there, Tomcat will find it.
    you're right, I'm using Tomcat 5.0,
    everything is working fine, user input servlets,
    mysql connection etc. Only this part is causing the
    problem now.If you've already got a Web app deployed and connected to MySQL, you're not doing too badly. Kudos to you - that's not too bad for someone who claims to be a programming novice.
    I'll put that jar file into lib folder as you suggested thanks.I think that might be all you'll need. Try it and see.
    Actually I saw an example it was using "throws
    exception" , I couldn't figure out where to put it,
    and I decided to get rid of the compiling errors just
    putting bunch of catch statements.If you're saying that your code is throwing a lot of checked exceptions, and you added these extra catch blocks to get rid of them, another way to do it would be to simply have a single catch block, like this:
    try
        // your code in here
    catch (Exception e)
        e.printStackTrace();
    }Polymorphism says that this catch block will handle all checked exceptions.
    >
    Looks like I don't know anything but I'm trying to
    handle a big thing :))).Indeed you are. Anyone who can write a Web app and connect it to a relational database on their first try is hardly helpless. We're all ignorant, just about different things. Keep digging - you'll make this work.
    But thank you soooo much for your detailed answer, and happy new year.
    Shamil.And the same to you, Shamil. Good luck, and let me know how you make out.
    %

  • Using java class files in JSP

    hi everyone,
    i am trying to import a java file in a JSP page..
    how do i do this???

    hi,
    <%@page import="yourpackagename.*" %>
    or
    <%@page import="yourpackagename.classname" %>

  • Need help with tomcat 5.5 and using java classes

    hey there,
    i am trying to set up tomcat 5.5 on my computer at home and have sucessfully done so. i have been trying to use Java classes inside my JSP files however tomcat thows an internal servlet error as follows:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 144 in the jsp file: /order.jsp
    Generated servlet error:
    ProductList cannot be resolved to a type
    An error occurred at line: 144 in the jsp file: /order.jsp
    Generated servlet error:
    ProductList cannot be resolved to a type
    An error occurred at line: 144 in the jsp file: /order.jsp
    Generated servlet error:
    Product cannot be resolved to a type
    i have the classes located as the setup tutorial recommends (root/WEB-INF/classes/) and still nothing works. i would appreciate any help anyone can give.
    thanks,

    Which tutorial are you following?
    As of java1.4, all classes must be in packages for them to work in Tomcat. This means your beans and servlets too.
    Put your beans in a package, and then recompile them, and put them in the right place.
    eg
    package com.mypackage
    public class MyClass ...
    once compiled would go into WEB-INF/classes/com/mypackage/MyClass.class
    Are you using Product and ProductList classes in scriptlet code?
    Have you imported them with a page directive
    <%@ page import="com.mypackage.Product, com.mypackage.ProductList" %> ?

  • Using a class in a web module

    I'm using netbeans and the web module template.
    I'm pretty new to jsp, so please bare with me. I just want to be able to use a class in my jsp page.
    I have 2 files:
    WEB-INF/classes/Customer
    index.jsp
    in the Customer Class, i declare the package at the top:
    package com.mycompany.data
    public Class Customer {
    in index.jsp, I want to use the Customer Class. I try like this:
    <%@ page import="com.mycompany.data.*" %>
    <%
    Customer cust = new Customer();
    %>
    I keep getting an error in index.jsp on both the page directive and on the line where I declare and instantiate the Customer object.
    Can someone inform me or point me to the right place to understand how to use a class in a .jsp?
    Thanks

    If the class Customer is in package com.mycompany.data
    Then Customer.class should be a file in
    web-inf/classes/com/mycompany/data/Customer.class
    Apart from that it looks ok.
    You might consider using a <jsp:useBean> tag instead of declaring customer in a scriptlet.
    I'm very much a fan of minimum scriptlet code on a page.
    Cheers,
    evnafets

  • How to use .class files from jsp

    hi i want to use .class files in my jsp program can any one help me

    so if you are using pacakges here is normal example...
    say you .java code is something like...
    package com.util;
    public Class BeanUtility{
    }place the .class file at WEB-INF/classes/com/util folder if those folders are missing create it and place the .class file there. or pacakage it as a jar file & put it into WEB-INF/lib folder
    Now in jsp you can either use jsp:Usebean tag or use normal scriplets to create an instance of the nessary class...
    here is an example for you
    <%@ page language="java" import="com.util.BeanUtility" %>
    <%
    BeanUtility bn = new BeanUtility();
    %>however,i'd suggest you to make use of JSTL / Inbuilt tag libraries /MVC 2.0 approach for better maintainance & readablity.
    Hope this might help
    REGARDS,
    RaHuL

  • Problem while trying to execute Java class in JSP using  RunTime Class

    Hi,
    I want to execute a JAVA class through a JSP. For this I am using following code ....
    JSP (AAA.jsp) CODE ............
    try
    String[] cmd = new String[3];
    cmd[0] = "cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[2] = "java -DPeBS_CONFIG_HOME=D:/CASLIntegration/PeBS/srcvob/PeBS/config Service_Statement_Application 22/May/2001 22/May/2003";
    Runtime rt = Runtime.getRuntime();
    System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]);
    Process proc = rt.exec(cmd);
    // any error message?
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
    // any output?
    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    // any error???
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
    catch (Throwable t)
    t.printStackTrace();
    StreamGobbler THread class Code ..........
    import java.util.*;
    import java.io.*;
    public class StreamGobbler extends Thread
    InputStream is;
    String type;
    StreamGobbler(InputStream is, String type)
    this.is = is;
    this.type = type;
    public void run()
    try
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line=null;
    while ( (line = br.readLine()) != null)
    System.out.println(type + ">" + line);
    } catch (IOException ioe)
    ioe.printStackTrace();
    I have successfully compiled and placed the class file for the above class in JSP's servlet engine. However, when I execute the JSP through explorer Web Browser, I get following compile time error:
    An error occurred between lines: 36 and 86 in the jsp file: /casl/LocalApp/VehicleServiceStmt/AAA.jsp
    Generated servlet error:
    D:\Tomcat\work\localhost\_\casl\LocalApp\VehicleServiceStmt\AAA$jsp.java:118: No constructor matching StreamGobbler(java.io.InputStream, java.lang.String) found in class StreamGobbler.
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
    ^
    An error occurred between lines: 36 and 86 in the jsp file: /casl/LocalApp/VehicleServiceStmt/AAA.jsp
    Generated servlet error:
    D:\Tomcat\work\localhost\_\casl\LocalApp\VehicleServiceStmt\AAA$jsp.java:121: No constructor matching StreamGobbler(java.io.InputStream, java.lang.String) found in class StreamGobbler.
    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
    I am unable to determine the reason of why the constructor which exists in the StreamGobbler Class is not recevied in JSP. If I try to write the same code in JSP as a JAVA class, keeping StreamGobler class same, the programme executes successfully.
    Please help me find solution to this at the earliest. Thanks in advance,
    Prachi

    Thanks,
    I got it working by making the constructor Public.
    -Prachi

  • How to use cusom classes in jsp

    Dear all,
    Would anyone teach me how to import and use my custom classes
    in my jsp? I've been unable to import the classes that reside in the same
    directory as the jsp file. Some detailed explanation with sample folder structure
    will be much appreciated.

    Thanks for the response.
    First, I've not yet touched Java beans. Don't yet know how to create them.
    Hence what I'm trying to do now is write an ordinary Java class and import it into
    the jsp via page directive.
    After your suggestion, I created the following folder structure in Tomcat5.
    webapps/mainalee_jsp/WEB-INF/
    WEB-INF/classes
    WEB-INF/lib
    WEB-INF/web.xml
    I've a JSP file, jsp1.jsp in the path: webapps/mainalee_jsp
    I've a java class, testclass.class, in the path: webapps/mainalee_jsp/WEB-INF/classes
    The codes are as follows:
    testclass.java:
    package mainalee_jsp;
    class testclass {
         int age;
         String name;
    public void testclass (int x, String y){
         age =x;     name=y;
    public String getName(){
         return name;
    public int getAge(){
         return age;
    jsp1.jsp:
    <%@ page import="mainalee_jsp.*" %>
    <%
    testclass tc = new testclass(27,"XYZ");
    out.println(tc.age);
    out.println("<br>");
    out.println(tc.name);
    %>
    web.xml:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    </web-app>
    When the jsp is called, Tomcat says that package mainalee_jsp doesn't exist.
    How can I make this program work? Thanks for the help to JSP newbie.

  • How to use Classes stored in "Classes" folder in JSP with tomcat ?

    Hello friends
    im using tomcat as server and MySQL as a Backend. now i am using the date calculation in Diff.class files which i have stored in catalina_home/webapps/prj_dev/Prj_files/classes/diff/DIff.class.
    now i am getting error that :
    Generated servlet error:
    Only a type can be imported. diff.Diff resolves to a package
    wht i have to do ?

    I don't include the "classes" word in my import anymore.. Waa.. I'm going nuts.. T.T
    Now, I'm trying to use the class through useBean..
    this is how my application looks like:
    /webapps
    -----/hangman-jsp
    ------------index.jsp
    ------------/WEB-INF
    -------------------web.xml
    -------------------MysteryPhrase.java
    -------------------/classes
    ---------------------------/beans
    ----------------------------------MysteryPhrase.class
    -----------/images
    -------------------hangman.gif
    This is what is in my MysteryPhrase:
    package beans;
    import java.lang.String;
    import java.lang.StringBuffer;
    public class MysteryPhrase {
         private String answer;
         private StringBuffer mysteryPhrase;
         private int guesses;
         private char[] alphabet;
         public MysteryPhrase () {
         this.alphabet = new char[26];
    public void setMysteryPhrase (String mysteryPhrase) {
         this.answer = mysteryPhrase;
         this.mysteryPhrase = new StringBuffer(mysteryPhrase.length());
         for (int i = 0; i < mysteryPhrase.length(); i++) {
              this.mysteryPhrase.setCharAt(i, '_');
    public void setGuess (char guess) {
         for (int i = 0; i < answer.length(); i++) {
              if (answer.charAt(i) == guess) {
                   mysteryPhrase.setCharAt(i, guess);
         guesses++;
    public String getMysteryPhrase () {
         return mysteryPhrase.toString();
    public String getAnswer () {
         return answer;
    public int getGuesses () {
         return guesses;
    This is what is in my index.jsp (It is not yet finished..I just started..)
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <jsp:useBean id="phrase" class="beans.MysteryPhrase"/>
    <jsp:setProperty name="phrase" property="MysteryPhrase" value="Hello!"/>
    <html>
         <head>
              <title>JSP/JSTL Implementation of Hangman</title>
              <style type="text/css">
                   div {
                        color: white;
                        background-color: gray;
                        position: absolute;
                        border-style: solid;
                        border-width: thin;
                        width: 20%;
                        height: 30%;
                        text-align: center;
                   #guessBoard {
                        top: 28%;
                        left: 42%
                   #mysteryPhraseBoard {
                        top: 50%;
                        left: 25%;
                        z-index: 2;
                   #statisticsBoard {
                        top: 57%;
                        left: 58%;
                        z-index: 2;
                   #categoryBoard {
                        top: 23%;
                        left: 10%
                   #hangman {
                        top: 7%;
                        left: 70%;
                   #char {
                        width: 20px;
                   body {
                        background-color: black;
              </style>
         </head>
         <body>
              <div id="categoryBoard">
                   <form method="post">
                        Please choose a category:
                        <select name="category">
                             <option>Category 1</option>
                             <option>Category 2</option>
                             <option>Category 3</option>
                             <option>Category 4</option>
                             <option>Category 5</option>
                             <option>Category 6</option>
                             <option>Category 7</option>
                             <option>Category 8</option>
                        </select>
                        <input type="submit" value="Change"/>
                   </form>
              </div>
              <div id="mysteryPhraseBoard">
                   The mystery phrase is
              </div>
              <div id="guessBoard">
                   <form method="post">
                        Enter a letter: <input id="char" type="text" name="letter"/>
                        or
                        Enter a word: <input type="text" name="word"/>
                        <input type="submit" value="Guess"/>
                   </form>
              </div>
              <div id="statisticsBoard">
                   Guesses: 0
                   Remaining Letters: 8
              </div>
              <div id="hangman">
                   <img src="images/hangman.gif"/>
              </div>
         </body>
    </html>

  • How use class file in jsp(very urgent)

    i have class file called birds (birds is actually a xslt file transformed to java class file) now this class file i have to use in my jsp file. how can i use them. if possible can any one give me sample code please very urgent
    can any one help me

    java files
    import org.w3c.dom.*;
    import javax.servlet.http.*;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.*;
    import java.io.*;
    public class XmlParser
         public String XmlParser()
              try
    String strXML= "employee.xml";
                   String xslFile = "employeeId.xsl";
                   TransformerFactory tFactory = TransformerFactory.newInstance();
                   StreamResult theTransformationResult = new StreamResult( new ByteArrayOutputStream() );
                   Transformer transformer = tFactory.newTransformer(new StreamSource(xslFile));
                   transformer.transform(new StreamSource(new StringReader(strXML)), theTransformationResult);
                   String output = theTransformationResult.getOutputStream().toString()
              catch(Exception e)
                   System.out.println(" ***** XmlParser.XmlParser ERROR ***** " + e);
    return output;
    using class files in jsp
    <%@ page import="com.qqqq.aaaa.XmlParser"%>
    <%
         XmlParser xmlParser          =     new XmlParser();
    out.println(xmlParser.XmlParser());
    %>
    i think it will help you.

  • Importing class in a jsp using Tomcat

    Hello All,
    Using Tomcat:
    I have class here:
    examples/WEB-INF/classes/ package/myclass.class
    I have a .jsp here:
    examples/JSPFolder/myjspfile.jsp
    I want to import the class into the jsp.
    I have tried the following combinations of importy lines based on previous posts on these boards and each have failed with same error:
    Unable to load class for JSP
    <%@ page import="myclass" %>
    <%@ page import="myclass.*" %>
    <%@ page import="package.myclass" %>
    <%@ page import="package.myclass.*" %>
    <%@ page import="WEB-INF/classes/package/myclass%>
    I have seen a number of posts for this same problem, and have tried those solutions as well, but none work. I am sure that this is simply a problem of finding the right directory, as I can successfully run the .jsp file iwhen I remove the import line.
    Can someone please help?

    There is a folder for shared packages
    tomcat_root\lib; or
    tomcat_root\common
    also most versions have a lib or common folder for each webapp for packages that are not to be shared.
    tomcat_root\webapps\appname\web-inf\lib
    Agreed that it is strange to allow servlets to import from the classes foler but not JSPs. It should make no difference but it is convension to place single classes in the same folder as the app's directory and packages (especially jar's) in the lib directory.

  • 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

  • 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

  • Using other classes in jsp

    hi all.
    in my jsp i would like to use another class which i created.
    here's what im trying to do:MyUtils.getValue(request.getParameter("id"));i'm getting: MyUtils cannot be resolved
    in MyUtils the method getValue is static.
    where should i put this class in order for my jsp to know it?
    thanks.

    Did you include a page directive with an import for the package? You need something like:
    <%@ page  import="MyUtilsPackage.*" %>The package containing the class should be placed in the WEB-INF\classes directory. For example if the package name is MyUtilsPackage, you'll need a MyUtilsPackage directory under classes and then put the class into the MyUtilsPackage directory.

Maybe you are looking for