jQuery in Action, 3rd edition
The moose likes JSP and the fly likes Unable to compile class for JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Unable to compile class for JSP" Watch "Unable to compile class for JSP" New topic

Unable to compile class for JSP

John Hood

Joined: Aug 06, 2006
Posts: 6
Hello,everyone.I met a problem when I try to run my jsp.
I have written a class called bookdetail in my exe package(i am using eclipse)and when i have imported in the jsp page and try to write this:
bookdetail mybd=new bookdetail();
well,eclipse told me that "booktail can not be resolve to a type"
and if I compile the project ,tomcat told me

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

An error occurred at line: 35 in the jsp file: /booklist.jsp
Generated servlet error:
bookdetail mybd=new bookdetail();

An error occurred at line: 35 in the jsp file: /booklist.jsp
Generated servlet error:

Here's my code bookstore.jsp

<%@ page pageEncoding="gb2312"%>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page language="java" import="java.util.*" %>
<%@ page language="java" import="exe.bookdetail.*" %>

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<jsp:useBean id="mybs" class="exe.bookstore" scope="session"/>

<base href="<%=basePath%>">

<title>My JSP 'booklist.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link rel="stylesheet" type="text/css" href="styles.css">


for(int i=1;i<=mybs.getrecordscount();i++)
bookdetail mybd=new bookdetail();


and bookdetail.java
package exe;

import java.sql.*;

public class bookdetail {
private String bookId=null;
private String title=null;
private String name=null;
private float price =0.0F;
private boolean onSale=false;
private int year=0;
private String description =null;
private int inventory=0;

public bookdetail(ResultSet rs)
}catch(Exception ex){}

public String getBookId() {
return bookId;

public void setBookId(String bookId) {
this.bookId = bookId;

public String getDescription() {
return description;

public void setDescription(String description) {
this.description = description;

public int getInventory() {
return inventory;

public void setInventory(int inventory) {
this.inventory = inventory;

public String getName() {
return name;

public void setName(String name) {
this.name = name;

public boolean isOnSale() {
return onSale;

public void setOnSale(boolean onSale) {
this.onSale = onSale;

public float getPrice() {
return price;

public void setPrice(float price) {
this.price = price;

public String getTitle() {
return title;

public void setTitle(String title) {
this.title = title;

public int getYear() {
return year;

public void setYear(int year) {
this.year = year;


Many thanks to anyone who can helps.
John Hood.
John Hood

Joined: Aug 06, 2006
Posts: 6
hey,the problem was solved.
I made a mistake in importing packages.
the right statement shall be
<%@ page language="java" import="exe.*" %>
<%@ page language="java" import="exe.bookdetail.*" %>

and why cannot compile??!!
The disk space is full,After the disk was cleaned,it runs well.
It is sorta covered in the JavaRanch Style Guide.
subject: Unable to compile class for JSP
It's not a secret anymore!