Java 无法通过JSP中的列表获取结果
在JSP中打印列表时遇到问题。我使用文字和RDFNode,就像我使用RDF一样 我有课堂记录:Java 无法通过JSP中的列表获取结果,java,jsp,servlets,jena,Java,Jsp,Servlets,Jena,在JSP中打印列表时遇到问题。我使用文字和RDFNode,就像我使用RDF一样 我有课堂记录: @Table public class Receta implements Serializable{ @Id @Column private Literal nombreReceta; @Column private Literal cantidadIngredientes; @Column private RDFNode ingredientes; @Column private RDFNode
@Table
public class Receta implements Serializable{
@Id
@Column
private Literal nombreReceta;
@Column
private Literal cantidadIngredientes;
@Column
private RDFNode ingredientes;
@Column
private RDFNode modoPreparacion;
@Column
private Literal dificultad;
@Column
private Literal tiempo;
@Column
private Literal calorias;
public Receta(){}
public Receta(Literal nombreReceta, Literal catidadIngredientes, RDFNode ingredientes, RDFNode modoPreparacion, Literal dificultad, Literal tiempo, Literal calorias) {
this.nombreReceta = nombreReceta;
this.cantidadIngredientes = catidadIngredientes;
this.ingredientes = ingredientes;
this.modoPreparacion = modoPreparacion;
this.dificultad = dificultad;
this.tiempo = tiempo;
this.calorias = calorias;
}
public Literal getNombreReceta() {
return nombreReceta;
}
public void setNombreReceta(Literal nombreReceta) {
this.nombreReceta = nombreReceta;
}
等等,还有接球手和二传手
我也有这个方法:
public static List<Receta> getAllReceipes() {
List<Receta> list = new ArrayList<>();
String log4jConfPath = "C:/Users/Karen/workspace/Jena/src/Tutorial/log4j.properties";
PropertyConfigurator.configure(log4jConfPath);
try {
//opening owl file
Model model = ModelFactory.createDefaultModel();
model.read(new FileInputStream("C:/Users/Karen/Desktop/Proyecto/bbdd.owl"), null, "TTL");
//System.out.println(model);
//create a new query
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 rec:<http://www.receta.org#>"
+ " SELECT ?r ?cal ?tiempo ?dif (COUNT (distinct ?Ingrediente) as ?cantIng) (GROUP_CONCAT(DISTINCT ?modoPreparacion) as ?Preparacion) (GROUP_CONCAT(DISTINCT ?listaIngredientes) as ?listaIng) "
+ " WHERE { "
+ " ?x rdf:type rec:Receta."
+ " ?x rdfs:label ?r."
+ " ?x rec:Ingrediente ?Ingrediente."
+ " ?x rec:modoPreparacion ?modoPreparacion."
+ " ?x rec:listaIngredientes ?listaIngredientes."
+ " ?x rec:Calorias ?cal."
+ " ?x rec:tiempoPreparacion ?tiempo."
+ " ?x rec:dificultad ?dif."
+ " } "
+ " GROUP BY ?r ?cal ?tiempo ?dif";
com.hp.hpl.jena.query.Query q = QueryFactory.create(queryString);
//execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(q, model);
ResultSet results = qe.execSelect();
//print query results
while (results.hasNext()) {
QuerySolution qs = results.next();
Receta rec = new Receta();
rec.setNombreReceta(qs.getLiteral("r"));
rec.setCantidadIngredientes(qs.getLiteral("cantIng"));
rec.setIngredientes(qs.get("listaIng"));
rec.setModoPreparacion(qs.get("Preparacion"));
rec.setTiempo(qs.getLiteral("tiempo"));
rec.setCalorias(qs.getLiteral("cal"));
rec.setDificultad(qs.getLiteral("dif"));
list.add(rec);
System.out.print(rec.getNombreReceta());
}
} catch (java.lang.NullPointerException e) {
System.out.println(e);
} catch (Exception e) {
System.out.println("Query Failed !");
}
return list;
}
public静态列表getAllReceipes(){
列表=新的ArrayList();
字符串log4jConfPath=“C:/Users/Karen/workspace/Jena/src/Tutorial/log4j.properties”;
配置(log4jConfPath);
试一试{
//打开owl文件
模型模型=ModelFactory.createDefaultModel();
read(新文件输入流(“C:/Users/Karen/Desktop/Proyecto/bbdd.owl”),null,“TTL”);
//System.out.println(模型);
//创建新查询
字符串查询字符串
=“前缀rdf:”
+“前缀owl:”
+“前缀rdfs:”
+“前缀xsd:”
+“前缀rec:”
+“选择?r?cal?tiempo?dif(计数(不同的预测)作为预测)(分组预测(不同的预测)作为准备)(分组预测(不同的预测)作为预测)”
+“其中{”
+“?x rdf:类型记录:记录。”
+“x rdfs:标签?r。”
+“x记录:Ingrediente?Ingrediente。”
+“?x rec:modoPreparacion?modoPreparacion。”
+“x rec:listaIngredientes?listaIngredientes。”
+“x记录:卡路里?卡。”
+“?x记录:tiempo准备?tiempo。”
+“?x记录:困难?dif。”
+ " } "
+“按r?cal?tiempo?dif分组”;
com.hp.hpl.jena.query.query q=QueryFactory.create(queryString);
//执行查询并获得结果
QueryExecution qe=QueryExecutionFactory.create(q,model);
ResultSet results=qe.execSelect();
//打印查询结果
while(results.hasNext()){
QuerySolution qs=results.next();
Receta rec=新Receta();
rec.setNombreReceta(qs.getLiteral(“r”);
rec.setCantidadIngredientes(qs.getLiteral(“cantIng”));
记录设置凭证(qs.get(“列表”);
记录设置准备(qs.get(“准备”);
rec.setTiempo(qs.getLiteral(“tiempo”);
rec.setCalorias(qs.getLiteral(“cal”));
记录setDificultad(qs.getLiteral(“dif”);
列表。添加(rec);
System.out.print(rec.getNombreReceta());
}
}catch(java.lang.NullPointerException e){
系统输出打印ln(e);
}捕获(例外e){
System.out.println(“查询失败!”);
}
退货清单;
}
从数据库中获取我想要的信息并将其保存在列表中。
我还有JSP,我想在其中显示表中的所有值,所以我做了以下工作:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="./BuscarRecetaServlet" method="POST">
<table border="1">
<tr>
<th><FONT FACE="Times New Roman" SIZE=3> NombreReceta </th>
<th><FONT FACE= "Times New Roman" SIZE=3> CantidadIngredientes </th>
<th><FONT FACE= "Times New Roman" SIZE=3> Ingredientes </th>
<th><FONT FACE= "Times New Roman" SIZE=3> ModoPreparacion </th>
<th><FONT FACE= "Times New Roman" SIZE=3> Calorias </th>
<th><FONT FACE= "Times New Roman" SIZE=3> Tiempo </th>
<th><FONT FACE= "Times New Roman" SIZE=3> Dificultad </th>
</tr>
<c:forEach items="${AllReceipes}" var="receipt">
<tr>
<td>name: <c:out value=${receipt.nombreReceta}/></td>
<td>Cant: <c:out value=${receipt.catidadIngredientes}/></td>
<td>List: <c:out value=${receipt.ingredientes}/></td>
<td>Preparation: <c:out value=${receipt.modoPreparacion}/></td>
<td>Calories: <c:out value=${receipt.calorias}/></td>
<td>Time: <c:out value=${receipt.tiempo}/></td>
<td>Dificult: <c:o<ut value=${receipt.dificultad}/></td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>
JSP页面
诺姆布雷雷西塔
坎蒂达迪恩特斯酒店
英格里登特斯
模态分离
卡路里
蒂恩波
困难的
姓名:
铁路超高:
名单:
准备:
卡路里:
时间:
难点:代码中缺少的一些内容:
最重要的JSTL标记库:
Add <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> in your JSP.
<td>Cant: <c:out value=${receipt.catidadIngredientes}/></td>
isn't matching ur member variable cantidadIngredientes
@Column
private Literal cantidadIngredientes;
添加到JSP中。
成员变量拼写错误:
Add <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> in your JSP.
<td>Cant: <c:out value=${receipt.catidadIngredientes}/></td>
isn't matching ur member variable cantidadIngredientes
@Column
private Literal cantidadIngredientes;
铁路超高:
与您的成员变量cantidadingRedients不匹配
@纵队
私人文学康蒂达丁内斯;
您在代码中遗漏的几件事:
最重要的JSTL标记库:
Add <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> in your JSP.
<td>Cant: <c:out value=${receipt.catidadIngredientes}/></td>
isn't matching ur member variable cantidadIngredientes
@Column
private Literal cantidadIngredientes;
添加到JSP中。
成员变量拼写错误:
Add <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> in your JSP.
<td>Cant: <c:out value=${receipt.catidadIngredientes}/></td>
isn't matching ur member variable cantidadIngredientes
@Column
private Literal cantidadIngredientes;
铁路超高:
与您的成员变量cantidadingRedients不匹配
@纵队
私人文学康蒂达丁内斯;
您在代码中遗漏的几件事:
最重要的JSTL标记库:
Add <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> in your JSP.
<td>Cant: <c:out value=${receipt.catidadIngredientes}/></td>
isn't matching ur member variable cantidadIngredientes
@Column
private Literal cantidadIngredientes;
添加到JSP中。
成员变量拼写错误:
Add <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> in your JSP.
<td>Cant: <c:out value=${receipt.catidadIngredientes}/></td>
isn't matching ur member variable cantidadIngredientes
@Column
private Literal cantidadIngredientes;
铁路超高:
与您的成员变量cantidadingRedients不匹配
@纵队
私人文学康蒂达丁内斯;
您在代码中遗漏的几件事:
最重要的JSTL标记库:
Add <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> in your JSP.
<td>Cant: <c:out value=${receipt.catidadIngredientes}/></td>
isn't matching ur member variable cantidadIngredientes
@Column
private Literal cantidadIngredientes;
添加到JSP中。
成员变量拼写错误:
Add <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> in your JSP.
<td>Cant: <c:out value=${receipt.catidadIngredientes}/></td>
isn't matching ur member variable cantidadIngredientes
@Column
private Literal cantidadIngredientes;
铁路超高:
与您的成员变量cantidadingRedients不匹配
@纵队
私人文学康蒂达丁内斯;
你不需要使用像“不,我不需要”这样的引号吗。我只需要收据中的值。nombreReceta困难:谢谢你的提醒,我已经更改了它,但我仍然有空盒子。仍然没有收据中的值。Deficultad(或其他)也${receipt.catidadIngredientes}
与您的成员变量cantidadIngredientes
不匹配。您不需要使用类似“否”的引号,我不需要。我只需要收据中的值。nombreReceta困难:谢谢你的提醒,我已经更改了它,但我仍然有空盒子。仍然没有收据中的值。Deficultad(或其他)也${receipt.catidadIngredientes}
与您的成员变量cantidadIngredientes
不匹配。您不需要使用类似“否”的引号,我不需要。我只需要收据中的值。nombreReceta困难:谢谢你的提醒,我已经更改了它,但我仍然有空盒子。仍然没有收据中的值。Deficultad(或其他)也${receipt.catidadIngredientes}
与您的成员变量cantidadIngredientes
不匹配。您不需要使用类似“否”的引号,我不需要。我只需要收据里面的值