PDA

View Full Version : How to call a Java class from a JSP


jayeshhalarnkar
02-16-2009, 09:07 PM
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

servlet
02-17-2009, 06:06 AM
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 (http://www.jsptube.com/servlet-tutorials/web-application-directory-structure.html)