开发者

How to avoid exception in running jsp in tomcat server?

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 开发者_如何学JAVAresolved 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):

  1. Exist in any of the jar files you put under WEB-INF/lib.
  2. Belong to com.hp.hpl.jena.rdf.model.* or com.hp.hpl.jena.query.*

Try with this application structure:

tomcat/webapps/ROOT
 - test.jsp
 - WEB-INF
    - lib
        - your .jar files

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.


Honestly, I feel like this using scriptlet tags in JSPs is a horrible practice.

You should never use scriptlet tags. JSPs are mean't to be used as a view layer, and any business logic needs to be moved into a controller, and separate your business logic from your view logic.


Allow your IDE to help you as much as it can. In this specific case define a library in Netbeans for Jena - be sure to at least add the binary jar and the docs, that way Netbeans will be able to show the Javadoc when requested during edit. Add that library to your project.

Once you have done that Netbeans will automatically deploy the Jena jars to the right place and it will package them with the project.

I also encourage you to visit the Netbeans tutorial collection, it's really helpful and will get you up to speed quickly.

Last but not least, your Netbeans is horribly old, version 7.0.1 has been released a couple of weeks ago. You might want to upgrade - upgrading Netbeans is a simple process, all your settings are automtically configured in the newly installed version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜