2016-12-24 41 views
0

我想用JSP的形式查詢RDF(貓頭鷹本體)模型。我收到以下錯誤 - 「HTTP狀態500 - javax.servlet.ServletException:java.lang.NoClassDefFoundError:組織/阿帕奇/耶拿/防暴/ RDFDataMgr」每當嘗試通過JSP查詢RDF模型時都會發生錯誤?

這是我的JSP代碼形式 -

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<!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=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<form action="disease-result.jsp" method="post"> 
<p align="center"> 
Select affected part: 
<input type="radio" name="part" value="Boll" /> Boll 
<input type="radio" name="part" value="Leaves" /> Leaves 
<input type="radio" name="part" value="Stem" /> Stem 
<input type="radio" name="part" value="Root" /> Root 
<br/><br/> 
Select symptom: 
<select name="symptom"> 
<option>Brown_to_black_color_lesions</option> 
<option>Spots_on_cotyledons_and_seedlings</option> 
<option>Drooping_of_bolls</option> 
<option>Water_soaked_spots</option> 
<option>Small_and_round_spots_on_bolls</option> 
</select> 
<br/><br/> 
<input type="submit" value="Submit" /> 
</p> 
</form> 
</body> 
</html> 

以下爲 「病result.jsp中」

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ page import="com.doitgeek.MyProject.PredictDisease"%> 
<!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=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<% 
    PredictDisease pd = new PredictDisease(); 
    String affectedPart = request.getParameter("part"); 
    String symptom = request.getParameter("symptom"); 
%> 
Affected Part = <%= affectedPart %> 
<br/><br/> 
Symptom = <%= symptom %> 
<br/><br/> 
Output = <%= pd.diseasePrediction(affectedPart, symptom) %> 
</body> 
</html> 

以下代碼類實際的Java代碼 「PredictDisease」 -

package com.doitgeek.MyProject; 

import org.apache.jena.query.Query; 
import org.apache.jena.query.QueryExecution; 
import org.apache.jena.query.QueryExecutionFactory; 
import org.apache.jena.query.QueryFactory; 
import org.apache.jena.query.QuerySolution; 
import org.apache.jena.query.ResultSet; 
import org.apache.jena.rdf.model.Model; 
import org.apache.jena.rdf.model.RDFNode; 
import org.apache.jena.riot.RDFDataMgr; 

public class PredictDisease { 

    public String diseasePrediction(String ap, String s) { 
     Model model = RDFDataMgr.loadModel("CottonOntology.owl"); 
     String queryString = 
       "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+ 
       "PREFIX owl: <http://www.w3.org/2002/07/owl#> "+ 
       "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+ 
       "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "+ 
       "PREFIX co: <http://www.semanticweb.org/sainath/ontologies/2016/11/CottonOntology#> "+ 
       "select ?Diseases ?Prevention where{?Diseases co:isControlledBy ?Prevention. "+ 
       "?Diseases co:affectsPart co:"+ap+". "+ 
       "?Diseases co:hasSymptom co:"+s+".}"; 

     Query query = QueryFactory.create(queryString); 
     QueryExecution qexec = QueryExecutionFactory.create(query, model); 
     try { 
      ResultSet results = qexec.execSelect(); 
      QuerySolution soln = results.nextSolution(); 
      RDFNode disease = soln.get("Diseases"); 
      String d = disease.asNode().getLocalName(); 
      String p = soln.get("Prevention").toString(); 
      return d; 
     } finally { 
      qexec.close(); 
     } 

    } 
} 

回答

1

這是一個java問題。

java.lang.NoClassDefFoundError表示運行時類路徑錯誤。

在這種情況下,它缺少jar「jena-arq-VERSION」。

檢查JSP服務器的設置。

+0

在http://stackoverflow.com/questions/10177100/jena-noclassdeffounderror-with-maven中回答 – berezovskyi

相關問題