You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nikola Milutinovic <Ni...@ev.co.yu> on 2003/06/03 14:49:36 UTC

JSTL and EL question

Hi all.

I'm using JSTL (Java Standard Tag Library), the EL (Expression Language) version. I have a DB where one particual query can return exactly one row (primary key). So, I use this:

<sql:setDataSource dataSource="jdbc/EVracunDS"/>
<sql:query var="userData">
  SELECT * FROM user_tab WHERE user_id = ?
  <sql:param value="${userID}"/>
</sql:query>

This works just fine and I can iterate over it using <c:forEach>.

<c:forEach items="${userData}" var="userRow">
...
</c:forEach>

I would like to be able to access the row directly, since I'm 100% sure there will be only one. Trying this, fails:

<c:out value="${suerData[0].user_id}"/>

or

<c:set var="userRow" value="${userData[0]}"/>

Can anyone advise?

JSTL implementation is Jakarta-Standard-1.0.3

Nix.

Re: is session id unique across webapps ?

Posted by Tim Funk <fu...@joedog.org>.
Tomcat creates its sessionids from a random number generator. The breadth of 
random numbers is very wide allowing for "virtually" no overlaps. But since 
they are random, dups may appear. Tomcat does have checks to make sure it 
doesn't give out an existing session id in a particular webapp.

That being said, I think it is possible that the same session_id may be used 
by two different users for two different webapps.

So if you really need a unique identifier, append session_id to context path.

There was a few discussions in developers list above session id uniqueness.

http://marc.theaimsgroup.com/?t=104072145900001&r=1&w=2
http://marc.theaimsgroup.com/?t=104207956000003&r=1&w=2


-Tim

siddharth wrote:
> Hi all,
> 
> I am tring to find out about *uniqueness* of *session ids*  which are 
> generated by tomcat.
> 
> are session ids are unique across webapps ???
> -----------------------------------------------
> 
> 
> 
> thanx.
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


is session id unique across webapps ?

Posted by siddharth <si...@fastmail.fm>.
Hi all,

I am tring to find out about *uniqueness* of *session ids*  which are 
generated by tomcat.

are session ids are unique across webapps ???
-----------------------------------------------



thanx.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: JSTL and EL question - SOLVED

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
> Oh boy, I get to contribute after asking a lot of questions!  ; )
> 
> Here's a query I am using in a current project:
> 
> <sql:query var='picks' maxRows='1'>
>    select * from contestant_picks where contestant='q' and week = ? 
> order by entered desc
>    <sql:param value='${thisWeek}'/>
> </sql:query>

It's good to know I'm not alone in using JSTL :-)

> I am using the maxRows option mainly because I don't need the db 
> returning all of the older data. Hmm, now that I think about it I can 
> probably add "and entered = max(entered)" or something like that. 
> Anyway, what I learned was that . and [] differed in an important way. 
> You can't evaluate a variable after the . but you can inside the []. As 
> a result my code worked out to:
> 
>    <c:set var='gameNum' value='game${game.game}'/>
>    <c:set var='thisPick' value='${picks.rows[0][gameNum]}'/>
> 
> The gameNum variable will contain a string like "game1", "game2', etc. 
> These are the names of the columns in the table. The second line 
> replaces the gameNum variable inside the [] so I get the equivalent of 
> "picks.rows[0].game1". One other piece you are missing is "rows" from 
> the value. As a result the following code should work for your 
> situation:
> 
> <c:out value='${superData.rows[0][user_id]}'/>

Yes, I noticed that in the afternoon - silly me!

> I would highly recommend the book "core JSTL Mastering the JSP Standard 
> Tab Library" by David M Geary from Sun. It got me up to speed on JSTL 
> in less than a week. Now I can't wait for Tomcat 5 to support JSP 2.0.

Thanks for the advice.

Nix.

Re: JSTL and EL question

Posted by Jeff Knox <jk...@lvcm.com>.
Oh boy, I get to contribute after asking a lot of questions!  ; )

Here's a query I am using in a current project:

<sql:query var='picks' maxRows='1'>
   select * from contestant_picks where contestant='q' and week = ? 
order by entered desc
   <sql:param value='${thisWeek}'/>
</sql:query>

I am using the maxRows option mainly because I don't need the db 
returning all of the older data. Hmm, now that I think about it I can 
probably add "and entered = max(entered)" or something like that. 
Anyway, what I learned was that . and [] differed in an important way. 
You can't evaluate a variable after the . but you can inside the []. As 
a result my code worked out to:

   <c:set var='gameNum' value='game${game.game}'/>
   <c:set var='thisPick' value='${picks.rows[0][gameNum]}'/>

The gameNum variable will contain a string like "game1", "game2', etc. 
These are the names of the columns in the table. The second line 
replaces the gameNum variable inside the [] so I get the equivalent of 
"picks.rows[0].game1". One other piece you are missing is "rows" from 
the value. As a result the following code should work for your 
situation:

<c:out value='${superData.rows[0][user_id]}'/>

I would highly recommend the book "core JSTL Mastering the JSP Standard 
Tab Library" by David M Geary from Sun. It got me up to speed on JSTL 
in less than a week. Now I can't wait for Tomcat 5 to support JSP 2.0.

Hope this helps,

Jeff


On Tuesday, June 3, 2003, at 05:49  AM, Nikola Milutinovic wrote:

> Hi all.
>
> I'm using JSTL (Java Standard Tag Library), the EL (Expression 
> Language) version. I have a DB where one particual query can return 
> exactly one row (primary key). So, I use this:
>
> <sql:setDataSource dataSource="jdbc/EVracunDS"/>
> <sql:query var="userData">
>   SELECT * FROM user_tab WHERE user_id = ?
>   <sql:param value="${userID}"/>
> </sql:query>
>
> This works just fine and I can iterate over it using <c:forEach>.
>
> <c:forEach items="${userData}" var="userRow">
> ...
> </c:forEach>
>
> I would like to be able to access the row directly, since I'm 100% 
> sure there will be only one. Trying this, fails:
>
> <c:out value="${suerData[0].user_id}"/>
>
> or
>
> <c:set var="userRow" value="${userData[0]}"/>
>
> Can anyone advise?
>
> JSTL implementation is Jakarta-Standard-1.0.3
>
> Nix.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org