Coding Tips (JavaScript/CSS/VBA/Win32)

Useful code snippets, tips and some Windows applications

JSTL Tips

Access Query Results By Column Index

Suppose you store the database Result in the queryResults variable:

  <sql:query var="queryResults" >
 		select * from employees
  </sql:query>

To access query results by column index instead of column name you need to use the rowsByIndex property.

	 <c:forEach var="row" items="${queryResults.rowsByIndex}">
	        <c:out value="${row [0]}"/>
	        <c:out value="${row[1]}"/>
	 </c:forEach>

Declaring arrays in JSTL

You can't declare arrays directly in JSTL, as far as I know. However, you can declare an array inside scriptlets and store it in the page scope as a scripting variable.
Example:

String[] monthNames={"January", "February", "March"};
pageContext.setAttribute("months", monthNames);

You can access the arrays in JSTL as folows:

	<c:out value="${months[0]}"/>

Enumerate request parameters

 <c:forEach var='p' items='${paramValues}'>
       <c:out value='${p.key}'/>:
       <c:forEach var='value' items='${p.value}'>
      			 <c:out value='${value}'/>
       </c:forEach>
       <br >
   </c:forEach>

More Java Tips

Text File Splitter Class. Full code listed

Add single quotes around a String if it is not a number

A simple way to find data in an xml document with dom4j

Enumerate all keys of a Hashtable

Remove duplicates from ArrayList