Advertisement
Guest User

Untitled

a guest
Apr 21st, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.96 KB | None | 0 0
  1. <%--
  2.     Document   : pocetak
  3.     Created on : Apr 21, 2016, 12:03:09 PM
  4.     Author     : Admin
  5. --%>
  6.  
  7. <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
  8. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  9.  
  10. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  11. <!DOCTYPE html>
  12. <html>
  13.     <head>
  14.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  15.         <title>JSP Page</title>
  16.     </head>
  17.     <body>
  18.         <sql:setDataSource var="snapshot" driver="org.h2.Driver"
  19.                        url="jdbc:h2:tcp://localhost/~/test"
  20.                        user="sa"
  21.                        password=""/>
  22.        
  23.         <form name="upis" method="POST">
  24.             <input type="number" name="idZupanije"/>
  25.             <input type="submit" value="Dohvati" />
  26.         </form>
  27.         <br>
  28.         <c:choose>
  29.             <c:when test="${(param.idZupanije < 1) || (param.idZupanije > 21)}">
  30.                 <br>
  31.                 Unesite broj između 1 i 21
  32.             </c:when>
  33.                
  34.             <c:otherwise>
  35.                 <c:catch var="catchException">
  36.                     <sql:query dataSource="${snapshot}" var="result">
  37.                         select ZUPANIJE.IDZUPANIJE, ZUPANIJE.NAZIVZUPANIJE, count(MJESTA.IDZUPANIJE) AS "broj" from ZUPANIJE
  38.                         join MJESTA on ZUPANIJE.IDZUPANIJE = MJESTA.IDZUPANIJE
  39.                         where ZUPANIJE.IDZUPANIJE=?
  40.                         group by MJESTA.IDZUPANIJE
  41.                         <sql:param value="${param.idZupanije}"/>
  42.                     </sql:query>
  43.                 </c:catch>
  44.                
  45.                 <c:choose>
  46.                     <c:when test="${catchException != null}">
  47.                         Exception: ${catchException} <br>
  48.                         Message: ${catchException.message}
  49.                     </c:when>
  50.                
  51.                        
  52.                     <c:otherwise>
  53.                         <table border="1" width="50%">
  54.                                 <tr>
  55.                                     <th>Id</th>
  56.                                     <th>Županija</th>
  57.                                     <th>Broj mjesta u županiji</th>
  58.                                 </tr>
  59.                         <c:forEach var="row" items="${result.rows}">
  60.                             <tr>
  61.                                 <td><c:out value="${row.IDZUPANIJE}"/></td>
  62.                                 <td><c:out value="${row.NAZIVZUPANIJE}"/></td>
  63.                                 <td><c:out value="${row.broj}"/></td>
  64.                             </tr>
  65.  
  66.                         </c:forEach>  
  67.                             </table>
  68.                     </c:otherwise>
  69.                 </c:choose>
  70.             </c:otherwise>
  71.         </c:choose>
  72.        
  73.        
  74.            
  75.        
  76.            
  77.            
  78.            
  79.            
  80.        
  81.        
  82.            
  83.   <br />
  84.     </body>
  85. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement