Populating JavaScript Array from JSP List

var countries = new Array(); <c:forEach items=”${countryList}” var=”country” varStatus=”status”> countryDetails = new Object(); countryDetails.country = ${country.name}; var provinces = new Array(); <c:forEach items=”${country.provinces}” var=”province” varStatus=”provinceStatus”> provinces.push(${province.name}); </c:forEach> countryDetails.provinces = provinces; countries.push(countryDetails); </c:forEach> now what you have is something like this in javascript var countries = [ {country:”USA”, provinces: [ “Ohio”, “New York”, “California” ]}, {country:”Canada”, … Read more

How to use with an tag?

<spring:url value=”/something” var=”url” htmlEscape=”true”/> <a href=”https://stackoverflow.com/questions/5007210/${url}”>…</a> But you an also use c:url <c:url value=”/something” var=”url”/> <a href=”https://stackoverflow.com/questions/5007210/<c:out value=”https://stackoverflow.com/questions/5007210/${url}”/>”>…</a> The one important difference between c:url and spring:url is, that c:url does not html encode the created url. But for a valid url the & between the url parameters must be a &amp;. So you need the … Read more

How do I make a Java ResultSet available in my jsp? [duplicate]

Model (Row): public class Row { private String name; // Add/generate constructor(s), getters and setters. } DAO: public List<Row> list() throws SQLException { Connection connection = null; Statement statement = null; ResultSet resultSet = null; List<Row> rows = new ArrayList<Row>(); try { connection = database.getConnection(); statement = connection.createStatement(); resultSet = statement.executeQuery(SQL_LIST); while (resultSet.next()) { Row … Read more

Iterating through a List Object in JSP

Before teaching yourself Spring and Struts, you should probably dive a little deeper into the Java language. Output like this org.classes.database.Employee@d9b02 is the result of the Object#toString() method which all objects inherit from the Object class, the superclass of all classes in Java. The List sub classes implement this by iterating over all the elements … Read more

JSP : JSTL’s tag

c:out escapes HTML characters so that you can avoid cross-site scripting. if person.name = <script>alert(“Yo”)</script> the script will be executed in the second case, but not when using c:out

How can I print error stack trace in JSP page?

get the parameter from request that is set internally and use it to print and deal with other information like cause, message <c:set var=”exception” value=”${requestScope[‘javax.servlet.error.exception’]}”/> and to print stacktrace <!– Stack trace –> <jsp:scriptlet> exception.printStackTrace(new java.io.PrintWriter(out)); </jsp:scriptlet> See Also JSPIntro4 – Handling Errors

I can pass a variable from a JSP scriptlet to JSTL but not from JSTL to a JSP scriptlet without an error

Scripts are raw java embedded in the page code, and if you declare variables in your scripts, then they become local variables embedded in the page. In contrast, JSTL works entirely with scoped attributes, either at page, request or session scope. You need to rework your scriptlet to fish test out as an attribute: <c:set … Read more