I tried running this jsp program in tomcat5.5 in netbeans 6.1
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" session="true"%>
<%@ page import="com.hp.hpl.jena.rdf.model.*"%>
<%@ page import="com.hp.hpl.jena.query.*"%>
<%
try
{
String inputFile="C:\\Users\\Admin\\Documents\\NetBeansProjects\\finalview\\resumenew.rdf";
InputStream in = new BufferedInputStream(new FileInputStream(new File(inputFile)));
Model model = ModelFactory.createMemModelMaker().createModel("");
model.read(in,null) ;
String queryString =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX foaf: <http://www.xmlns.com/foaf/0.1> " +
"SELECT ?name ?phone WHERE { ?person foaf:name ?name . ?person foaf:phone ?phone }";
Query query1 = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query1,model);
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query1);
qe.close();
}catch(Exception e){}
%>
And I get the following exception when I run the program
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 6 in the jsp file: /test.jsp
Generated servlet error:
Model cannot be resolved to a type
An error occurred at line: 6 in the jsp file: /test.jsp
Generated servlet error:
ModelFactory cannot be resolved
An error occurred at line: 6 in the jsp file: /test.jsp
Generated servlet error:
Query cannot be resolved to a type
An error occurred at line: 6 in the jsp file: /test.jsp
Generated servlet error:
QueryFactory cannot be resolved
An error occurred at line: 6 in the jsp file: /test.jsp
Generated servlet error:
QueryExecution cannot be resolved to a type
An error occurred at line: 6 in the jsp file: /test.jsp
Generated servlet error:
QueryExecutionFactory cannot be resolved
An error occurred at line: 6 in the jsp file: /test.jsp
Generated servlet error:
ResultSet cannot be resolved to a type
An error occurred at line: 6 in the jsp file: /test.jsp
Generated servlet error:
ResultSetFormatter cannot be resolved
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)c
Can you tell me, where should I keep my jsp program and the file that is given as input to it.
How can I avoid this error ?
Your Jena libraries (and its dependencies) should be under WEB-INF/lib (case sensitive), the standard Java EE folder to put your application jar files. Make sure that your clases (Query, QueryFactory, ModelFactory, etc):
Try with this application structure:
By the way, your “Model 1 code” seems to be a good candidate to be moved to a servlet (Model 2), but that is only a design advice that has nothing to do with your JSP compiler error.