Shammer's Philosophy

My private adversaria

JSTL helps us but... not clear for me...

I used JSTL SQL tag, it is very useful to implement web application to access the Database!
I used JSTL SQL tag like below in this article, but I faced with some problems.

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:set var="userid" scope="request" value="${param.userid}" />
<sql:query var="rs" dataSource="jdbc/MyDB">
select * from user where ID = ?;
  <sql:param value="${userid}" />
</sql:query>

And the code using this ResultSet would be like below.

<c:forEach var="row" items="${rs.rows}">
	<c:out value="${row.id}"></c:out>
	<c:out value="${row.name}"></c:out>
</c:forEach>

Problem 1

I'm not sure how to access "userid" defined with c:set.

Problem 2

This is related with Problem 1, I can't use the value of ${row.id} and ${row.name} in script-let section, between <% and %>. I'm not sure how to write script-let to use those value, compare with other strings for example.

Problem 3

JSTL core doesn't provide the function if-else-if, just only provided if. Using c:when tag, we can write if section like below.

if( value == 1000 ){
  // Do something
}

But, we can't write if elseif with JSTL straightly.

if( value < 1000 ){
  // Do something
} else if (1000 <= value && value < 10000 ){
  // Do something
} else {
  // Do something
}

Using JSTL c:otherwise, we can write similar code like above, but I don't think it is not beautiful.

I'm think that using JSTL and script-let at the same time is going to resolve these problems. Especially, how to access the value defined by c:set is important. I'm looking for this answer now.