• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Getting "Unable to compile class for JSP" error

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to build a JSP page which uses a Java Class to set and get values. I am running default root application.I have put the JSP file (ShowCustName.jsp) under ROOT and the Java class(CustomerName.class) under ROOT\WEB-INF\classes. But when I call the page it gives me following error.Normal jsp which doesnot call any Java class works fine.

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 7 in the jsp file: /ShowCustName.jsp
Generated servlet error:
CustomerName cannot be resolved or is not a type

An error occurred at line: 7 in the jsp file: /ShowCustName.jsp
Generated servlet error:
CustomerName cannot be resolved or is not a type


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:389)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

----ShowCustName.jsp -----
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
Show Customer Name
</head>
<body>
<% CustomerName custname = new CustomerName();
custname.setFirstName("Nitin");
custname.setLastName("Kumar"); %>

First Name :<%= custname.getFirstName() %>
Last Name : <%= custname.getLastName() %>
</body>
</html>
--- CustomerName.java --
public class CustomerName {
private String firstName;
private String lastName;

public String getFirstName(){
return firstName;
}

public void setFirstName(String firstName){
this.firstName=firstName;
}

public String getLastName(){
return lastName;
}

public void setLastName(String lastName){
this.lastName=lastName;
}
}

I have tried setting the CLASSPATH to WEB-INF\classes but in vain.
Can any body help me out?
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Import your "Customer" class in the JSP and ensure the package structure is correct
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need to put your java class in a package and import it in your jsp file. Most probably the generated servlet will be of put in some package so it cannot access the java class which is in default package..
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic