我试图使用JSP表单查询RDF(owl本体)模型。我收到以下错误 - " HTTP状态500 - javax.servlet.ServletException:java.lang.NoClassDefFoundError:org / apache / jena / riot / RDFDataMgr"
这是我的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>
以下是&#34; disease-result.jsp&#34;
的代码<%@ 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>
以下是类&#34; PredictDisease&#34; -
的实际java代码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();
}
}
}
答案 0 :(得分:1)
这是一个java问题。
java.lang.NoClassDefFoundError
表示运行时类路径错误。
在这种情况下,它错过了jar&#34; jena-arq-VERSION&#34;。
检查JSP服务器的设置。