Accessing columns of table - Java server pages

Discussion in 'Java' started by Evrim, Aug 18, 2007.

  1. Evrim

    Evrim Guest

    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
     
    Evrim, Aug 18, 2007
    #1
    1. Advertising

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

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

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1
     
    Andrew Thompson, Aug 18, 2007
    #2
    1. Advertising

  3. Evrim

    Evrim Guest

    "Andrew Thompson" <u32984@uwe> wrote in message news:76dd6a85928af@uwe...

    > '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
     
    Evrim, Aug 18, 2007
    #3
  4. Evrim

    Lew Guest

    Evrim wrote:
    > "Andrew Thompson" <u32984@uwe> wrote in message news:76dd6a85928af@uwe...
    >
    >> '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...


    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}" />

    --
    Lew
     
    Lew, Aug 18, 2007
    #4
  5. Evrim

    Evrim Guest

    Thank you for your reply ... I will try implementing it the way you
    suggested.
     
    Evrim, Aug 18, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. helpful sql
    Replies:
    0
    Views:
    830
    helpful sql
    May 19, 2005
  2. Replies:
    5
    Views:
    610
  3. Replies:
    4
    Views:
    944
  4. Jacksm
    Replies:
    2
    Views:
    860
    Paul Chalekian
    Nov 21, 2006
  5. Denis
    Replies:
    0
    Views:
    310
    Denis
    Apr 25, 2007
Loading...

Share This Page