Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to call a Java class from a JSP

    Hello every body

    I am learning JSP from a e-book "Teach Yourself JSP 2.0 with Apache Tomcat in 24 Hours (Sams, 2003)". here actually an example is given where we have to call a class from a JSP by importing it.

    here is the code
    ReloadTest.jsp
    <%@ page language="java" import="examples.*" %>
    <html>
    <body>
    The message is: <%= ReloadedClass.getMessage() %>
    </body>
    </html>

    ReloadedClass.java
    package examples;

    public class ReloadedClass
    {
    public static String getMessage()
    {
    return "This is the original message";
    }
    }

    Can some one please help me i actually dont know where to place the ReloadedClass.class file. And one more thing i have not actually used the package named 'examples'. i am using the Apache Tomcat Server so please guide me where should i place the .class file and under which folder.
    right now i am placing the class file under "\Tomcat\webapps\examples\WEB-INF\classes\" the default place for placing class files as that of servlets

  • #2
    Regular Coder
    Join Date
    Jan 2009
    Location
    india
    Posts
    145
    Thanks
    0
    Thanked 5 Times in 5 Posts
    It's okey to put the ReloadedClass class file in WEB-INF/classes folder.

    one more thing i have not actually used the package named 'examples'
    Then remove import="examples.*" you don't need it.

    Look at J2EE web application directory structure


  •  

    Posting Permissions

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