简体   繁体   English

每当尝试通过JSP查询RDF模型时都会发生错误?

[英]Error occurs whenever try to query RDF model through JSP?

I'm trying to query RDF (owl ontology) model using JSP form. 我正在尝试使用JSP表单查询RDF(猫头鹰本体)模型。 I am getting following error - "HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/jena/riot/RDFDataMgr" 我收到以下错误-“ HTTP状态500-javax.servlet.ServletException:java.lang.NoClassDefFoundError:org / apache / jena / riot / RDFDataMgr”

This is my code for JSP form- 这是我的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>

Following is the code for "disease-result.jsp" 以下是“ disease-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>

Following is the actual java code for class "PredictDisease"- 以下是“ PredictDisease”类的实际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();
        }

    }
}

This is a java problem. 这是一个Java问题。

java.lang.NoClassDefFoundError means the runtime classpath is wrong. java.lang.NoClassDefFoundError表示运行时类路径错误。

In this case, it's missing the jar "jena-arq-VERSION". 在这种情况下,它将丢失jar“ jena-arq-VERSION”。

Check the setup for the JSP server. 检查JSP服务器的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM