How to URL encode a URL in JSP / JSTL?

Since you are using JSP, I would stick to JSTL and not use scriptlets. You could use the JSTL tag <c:url /> in combination with <c:param />: <c:url value=”/yourClient” var=”url”> <c:param name=”yourParamName” value=”http://google.com/index.html” /> </c:url> <a href=”https://stackoverflow.com/questions/15923062/${url}”>Link to your client</a> This will result in: <a href=”https://stackoverflow.com/yourClient?yourParamName=http%3a%2f%2fgoogle.com%2findex.html”>Link to your client</a>

How to print current date in JSP?

Use jsp:useBean to construct a java.util.Date instance and use JSTL fmt:formatDate to format it into a human readable string using a SimpleDateFormat pattern. <%@ taglib uri=”http://java.sun.com/jsp/jstl/fmt” prefix=”fmt” %> <jsp:useBean id=”date” class=”java.util.Date” /> Current year is: <fmt:formatDate value=”${date}” pattern=”yyyy” /> The old fashioned scriptlet way would be: <%= new java.text.SimpleDateFormat(“yyyy”).format(new java.util.Date()) %> Note that you need … Read more

How do I execute a MS SQL Server stored procedure in java/jsp, returning table data?

Our server calls stored procs from Java like so – works on both SQL Server 2000 & 2008: String SPsql = “EXEC <sp_name> ?,?”; // for stored proc taking 2 parameters Connection con = SmartPoolFactory.getConnection(); // java.sql.Connection PreparedStatement ps = con.prepareStatement(SPsql); ps.setEscapeProcessing(true); ps.setQueryTimeout(<timeout value>); ps.setString(1, <param1>); ps.setString(2, <param2>); ResultSet rs = ps.executeQuery();

JSTL iterate over list of objects

There is a mistake. See this line <c:forEach items=”${myList}” var=”element”>. ${} around ‘myList’ was missing. <c:forEach items=”${myList}” var=”element”> <tr> <td>${element.status}</td> <td>${element.requestType}</td> <td>${element.requestedFor}</td> <td>${element.timeSubmitted}</td> </tr> </c:forEach>

Using for loop inside of a JSP

You concrete problem is caused because you’re mixing discouraged and old school scriptlets <% %> with its successor EL ${}. They do not share the same variable scope. The allFestivals is not available in scriptlet scope and the i is not available in EL scope. You should install JSTL (<– click the link for instructions) … Read more