Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Accessing columns of table - Java server pages

Thread view: 
Evrim - 18 Aug 2007 06:25 GMT
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
Andrew Thompson - 18 Aug 2007 06:55 GMT
...
>For example the two dimensional array "test" has this data:
>
[quoted text clipped - 5 lines]
>
>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'
<a href='thetarget.jsp?Col2=e&amp;Col3=f'>d</a>

>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.

Signature

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

Evrim - 18 Aug 2007 08:56 GMT
> '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
Lew - 18 Aug 2007 14:40 GMT
>> 'Row1, Col1'
>> <a href='thetarget.jsp?Col2=b&amp;Col3=c'>a</a>
[quoted text clipped - 7 lines]
> 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:out 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:outputText value="#{thing.a}" />

Signature

Lew

Evrim - 18 Aug 2007 17:36 GMT
Thank you for your reply ... I will try implementing it the way you
suggested.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.