opike
opike

Reputation: 7595

Getting error message "Only a type can be imported..." when trying to execute jsp page

I have a jsp page that is trying to reference some user defined classes. These classes were compiled with the line:

package pikefin;

and place in the directory:

/var/lib/tomcat6/webapps/examples/jsp/JSPEssbase2/WebContent/WEB-INF/classes/pikefin

Here is my jsp code:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="pikefin.PopulateSpreadsheet" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% 
out.println(" Hello Oracle World5");
PopulateSpreadsheet tmp = new PopulateSpreadsheet();

out.println(" Hello Oracle World4"); %> 
</body>
</html>

This is the full error message:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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

An error occurred at line: 6 in the generated java file
Only a type can be imported. pikefin.PopulateSpreadsheet resolves to a package

An error occurred at line: 13 in the jsp file: /jsp/JSPEssbase2/essbasedatasource.jsp
PopulateSpreadsheet cannot be resolved to a type

Update 1:

So I changed the import statement to this:

<%@ page import="pikefin.*" %>

And created a new directory structure that looks like this:

[ollie@devdataload jsp]$ ls -Rp JSPEssbase3/
JSPEssbase3/:
essbasedatasource.jsp  META-INF/  WEB-INF/

JSPEssbase3/META-INF:
MANIFEST.MF

JSPEssbase3/WEB-INF:
classes/  lib/

JSPEssbase3/WEB-INF/classes:
pikefin/

JSPEssbase3/WEB-INF/classes/pikefin:
BatchSample$CellAddress.class  Logs.class
BatchSample.class              PopulateSpreadsheet.class
CustomBufferedWriter.class     SkipLoadException.class
DBFunctions.class              TestException.class
EssbaseConnect.class           UtilityFunctions.class

JSPEssbase3/WEB-INF/lib:

And now I get this error message:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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

An error occurred at line: 13 in the jsp file: /jsp/JSPEssbase3/essbasedatasource.jsp
PopulateSpreadsheet cannot be resolved to a type
10: <body>
11: <% 
12: out.println(" Hello Oracle World5");
13: PopulateSpreadsheet tmp = new PopulateSpreadsheet();
14: 
15: out.println(" Hello Oracle World4"); %> 
16: </body>

Upvotes: 1

Views: 20112

Answers (4)

sethi.anuj
sethi.anuj

Reputation: 39

I was using eclipse for my project and faced the same issue. I solved this problem by changing the output folder for my java code to "...\WEB-INF\classes".

Upvotes: 0

theshadow
theshadow

Reputation: 161

As an additional note, some classes are packaged in jar files that act as zip files, and thus must be extracted or they will not be found. It happened to me with chemistry-opencmis-osgi-client-0.7.0.jar. In this case, the jsp could not locate the necessary imports, and it was because inside the jar file there was in turn a subdirectory called lib that contained the actual jars that I required. IMO it should have been better if these were packaged as zip or tar.gz instead of jar causing my confusion.

The rest is correct, as long as these jar files are put in WEB-INF/lib inside they will be imported without trouble.

Upvotes: 1

josh.trow
josh.trow

Reputation: 4901

You need to set it as pikefin.PopulateSpreadsheet.* or similar, as you have it the error is correct.

Only a type can be imported. pikefin.PopulateSpreadsheet resolves to a package

Upvotes: 0

BalusC
BalusC

Reputation: 1109695

The path

/var/lib/tomcat6/webapps/examples/jsp/JSPEssbase2/WebContent/WEB-INF/classes/pikefin

should have been

/var/lib/tomcat6/webapps/examples/WEB-INF/classes/pikefin

The WEB-INF has to go directly in the webapp project folder.

Upvotes: 3

Related Questions