Accessing columns of table - Java server pages

E

Evrim

Hi

I have a JSP that builds a table and shows the values in fields according to
what has been passed to it through a request.setAttribute of a servlet.

For example the two dimensional array "test" has this data:

Col1 Col2 Col3
Row1 a b c
Row2 d e f



and JSP will read this from request variable and display it.

These values (a,d) are displayed as hyper links to a page testpage.jsp.

What I need to do is, when user clicks a , I need to set b and c in a
variable array and pass it to the next page , or when user clicks d I need
to pass e and f to next page.

1. Could you please tell me how to do that ?

2. Do I need Javascript ? or it can be done in Java? I prefer to have all
the code in Java.

3. How is it possible to access and change a request variable from
JavaScript ?


Appreciate your help in advance
Evrim
 
A

Andrew Thompson

Evrim wrote:
...
For example the two dimensional array "test" has this data:

Col1 Col2 Col3
Row1 a b c
Row2 d e f

and JSP will read this from request variable and display it.

These values (a,d) are displayed as hyper links to a page testpage.jsp.
...
'Row1, Col1'
<a href='thetarget.jsp?Col2=b&amp;Col3=c'>a</a>
....
'Row2, Col1'
What I need to do is, when user clicks a , I need to set b and c in a
variable array

'Variable array'? Why not simply include it as the
parameters of a (plain old) hyperlink?
...
2. Do I need Javascript ? or it can be done in Java? I prefer to have all
the code in Java.

Do it in HTML. Use whatever (server) side language you
like to generate the HTML, but leave JS out of it - it is an
unnecessary complication.
3. How is it possible to access and change a request variable from
JavaScript ?

Between pages? See above.
'In-place' in a single page - that would
require JavaScript.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1
 
E

Evrim

Andrew Thompson said:
'Row1, Col1'
<a href='thetarget.jsp?Col2=b&amp;Col3=c'>a</a>
...
'Row2, Col1'
<a href='thetarget.jsp?Col2=e&amp;Col3=f'>d</a>


First of all thank you very much for your reply ....

In this case , I should have a java code that builds query string based on a
loop that goes through the 2-D array , correct ?
Any tips or reading material is extremely apprecited...


Evrim
 
L

Lew

Evrim said:
First of all thank you very much for your reply ....

In this case , I should have a java code that builds query string based on a
loop that goes through the 2-D array , correct ?
Any tips or reading material is extremely apprecited...

JSTL (JSP Standard Tag Library) and JSF (Java Server Faces) to the rescue,
specifically, EL (expression language).

<c:forEach items="${outer}" var="${thing}" >
<a href="thetarget.jsp?Col2=${thing.b};Col3=${thing.c}">
<c:eek:ut value="${thing.a}" />
</a>
<br />
</c:forEach>

or some variation thereof. Nowadays, thanks to JSF, we'd prefer the enhanced
EL, that usually uses an octothorpe instead of a dollar sign to indicate an
expression:

<h:eek:utputText value="#{thing.a}" />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top