Results 1 to 3 of 3
  1. #1
    adammyth is offline Member
    Join Date
    Dec 2009
    Rep Power

    Exclamation JSP with user-defined java classes

    I have a very simple web application which contains only one JSP file.
    In this JSP file i want to use a java class (Calculate.class) that is written by myself.

    My class is not in a package. So i simply put it into WEB-INF/classes directory.
    But when i run my application i get an error which points a compilation error in JSP page because Calculate.class cannot be find.

    Where should i put this class file?
    How should i import this class file inside the JSP?
    Where should i put the source code for this Calculate class so that it can be recompiled?

    PS: I am using Eclipse and Tomcat

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Rep Power


    One thing u can do ...but its not a good idea

    u can embed the class inside the static block and call

    example : test.jsp

    <%= new Hello().hai()%>

    <%!class Hello
    public String hai()
    return "Hi!!";

  3. #3
    NoGrief is offline Member
    Join Date
    Mar 2010
    Rep Power


    import your package and class in jsp file...
    Java Code:
    <%@page import=""%>
    in eclipse,open your jsp,and type your class for this:
    Java Code:
    <% new Hello();%>
    in the end of the "Hello",type alt+? then eclipse may assist you...
    then in the list,you can select your class and click enter,eclipse may automatic import your class package..
    Last edited by NoGrief; 03-05-2010 at 06:19 PM.

Similar Threads

  1. Replies: 4
    Last Post: 01-05-2011, 03:00 PM
  2. Accessing class defined within a constructor
    By kwaspl in forum New To Java
    Replies: 4
    Last Post: 12-21-2009, 02:35 PM
  3. RegardingSgould Enter in user defined inbox
    By Prashant.surwade in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-23-2009, 01:21 PM
  4. How to call defined java class in Jsp
    By asheeshiit in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-04-2009, 04:21 AM
  5. Replies: 0
    Last Post: 07-16-2007, 08:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts