Please have a look at the info
• Objective: To run a JSP page which calls a java class, both residing on tomcat server
•Environment
Server environment: Linux
Server: Tomcat7.0.27
IDE: none
•JSP (all it does is display a string)
<%@page import="HelloWorld.HelloWorld" %>
<HTML>
<HEAD>
<TITLE>Hello World/TITLE>
</HEAD>
<BODY>
<H1>Hello World</H1>
String is: <%= HelloWorld.HelloWorld.display() %>
</BODY>
</HTML>
•JSP location:TOMCAT/webapps/hello/hello.jsp
•Java class(all it does is return a string)
package HelloWorld;
public class HelloWorld {
public static String display() {
return "Hello World!"; // Display the string.
}
}
•Java class location: TOMCAT/webapps/hello/WEB-INF/classes/HelloWorld/HelloWorld.class •Java class compile action: javac -classpath TOMCAT/lib/servlet-api.jar:. -d /home/user/ HelloWorld.java
•WEB.XML
<?xml version="1.0" encoding="Cp1252"?>
<!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>
<display-name>hello</display-name>
<description>no description</description>
<servlet>
<servlet-name>hello</servlet-name>
<display-name>hello</display-name>
<description>no description</description>
<jsp-file>/hello.jsp</jsp-file>
</servlet>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
•Actions: o Copy java class to directory o Clean TOMCAT/work directory o Shutdown TOMCAT o Startup TOMCAT o Open server:8080/hello/hello.jsp
•Issue:
HTTP Status 500
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 14 in the generated java file The import HelloWorld cannot be resolved An error occurred at line: 8 in the jsp file: /hello.jsp HelloWorld cannot be resolved 5: </HEAD> 6: <BODY> 7: <H1>Hello World</H1> 8: String is : <%= HelloWorld.HelloWorld.display() %> 9: </BODY> 10: </HTML>
Stacktrace:org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
There is no syntax error in calling PackageName.ClassName.StringReturningMethod() in JSP The class is in package folder.
What is causing it?
Thanks,