WItam mam problem z wychwyceniem zapytania o ilosc wpisow w danej kategorii wyglada to tak:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!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>
<h1>Forum</h1>
<table>
<tr>
<th>Temat</th>
<th>Datat</th>
<th>Autor</th>
</tr>
<c:forEach var="temat" items="${tematy}">
<tr>
<td>
<c:url var="url" scope="page" value="/temat">
<c:param name="id" value="${temat.id}"/>
</c:url>
<a href="${url}">${temat.tytul}</a>
</td>
<td><fmt:formatDate value="${temat.data}" dateStyle="short" timeStyle="short"/>
<td>${temat.uzytkownik.login}</td>
</tr>
</c:forEach>
</table>
<c:url value="/nowyTemat" var="urlNowyTemat" scope="page"/>
<form action="${urlNowyTemat}">
<input type="submit" value="Nowy temat"/>
</form>
<br/>
<a href="wyloguj">Wyloguj</a><br/><br/>
<c:forEach var="kategoria" items="${kategorie}">
<tr>
<td>
<input type="hidden" name="id" value="${kategoria.id}"/>
<c:url var="url" scope="page" value="/tematKategoria">
<c:param name="idd" value="${kategoria.id}"/>
</c:url>
<a href="${url}">${kategoria.nazwa}</a>--------------${tematyy}<br/><br/>
</td>
</tr>
</c:forEach>
</body>
</html>
jak widzicie zliczanie mialo by nastapic tutaj ${tematyy}
public List pobierzIloscTematowWKategori(String id){
List tematy = this.em.createQuery("SELECT count(t) from Temat t where t.kategoria ="+id).getResultList();
return tematy;
}
tak wyglada zapytanie o ilosc tematow wiem wyglada kiepsko ale nie o to tu chodzi bo pobiera dane i zlicza prawidlowo ;
@WebServlet("/index")
public class IndexSerwlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
TematyDAO dao = (TematyDAO) request.getAttribute("tematyDAO");
List<Temat> tematy = dao.pobierzTematy();
request.setAttribute("tematy", tematy);
KategoriaDAO dao1 = (KategoriaDAO) request.getAttribute("kategoriaDAO");
List<Kategoria> kategorie = dao1.pobierzKategorie();
request.setAttribute("kategorie", kategorie);
String id = request.getParameter("id");
List tematyy = dao.pobierzIloscTematowWKategori(id);
System.out.print(id);
System.out.print(tematyy);
request.setAttribute("tematyy", tematyy);
request.getRequestDispatcher("/WEB-INF/widok/index.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
powyzej jest servlet i jego zadaniem ma byc zliczenie czyli moje myslenie jest takie pobieram z ukrytego inputa co widzicie na JSP id kategori w postaci liczby ktora zostaje pobrana przes servlet skierowana do zapytania i pozniej otrzymuje wynik "request.setAttribute("tematyy", tematyy)" tylko jest problem z inputu nie pobiore wartosci poniewaz musial bym go wyslac za pomoca formularza a chce zeby robilo sie to dynamicznie przy otwarciu JSP i dynamicznie dla kazdej kategorii zliczanie tematow . Macie jakies pomysly ? Z góry dzieki