• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting Data from HTML Table

 
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a HTML table that displays employeeID, FirstName and LastName only. I made the employeeID field in each row as document link to a URL so that when the employeeID field was click, it will forward the browser to a next JSP that will completely display the Person Information (e.g. Age, Birthday etc..)



Is there a way that I could retrieve what row was click in an HTML table so that I could use the details of the row and use it as an attribute in my JSP.


<jsp:useBean id="personUserName" class="com.bdo.User" scope="request" />
<jsp:setProperty name="personUserName" property="employeeID " param="myTable"/>

Your user Name is: ${personUserName.employeeID}

The param="myTable" refers to the table name. It could have been easier if I let the user enter the employeeID in a text box and use the param attribute="textboxname".

I dont know if i'm doing things right. Please help. I am trying to learn JSP thru web tutorials. Thanks
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello mark reyes,

Welcome to JavaRanch.

Yes, you can very well do it. You can append the employeeId to the request scope before submitting in the first page and retrieve the same in the next jsp where you forwarded.

Make use of this retrieved employeeId to fetch the other details of the employee and display it.
 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sir,

Thanks for replying. A fragment of my code looks like the one below. I hard code my name inside it but I usually got the data from my Employees Table and store it in an arraylist then scan the list to display it to my table row.

I'm having a problem submitting to my url "/showUserData.do" on how I could get a reference on the click row and save the click employee id.

I just would like to ask on how I could store the attribute employeeID in the request scope before submitting to my next JSP so that I could use it.

Please pardon me, if my question might be too simple.



[BSouther: Added UBB CODE tags]
[ July 11, 2007: Message edited by: Ben Souther ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't want to try to be reading the information from the HTML table after the fact. That would require a tremendous amount of fragile JavaScript. Rather, when you are constructing the page in your JSP, add a parameter to the the link of your <a> tag that identifies the row when the link is clicked.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mark reyes:
...

I'm having a problem submitting to my url "/showUserData.do" on how I could get a reference on the click row and save the click employee id.

I just would like to ask on how I could store the attribute employeeID in the request scope before submitting to my next JSP so that I could use it.
...



Hi Mark

Along with what Bear said, how do you get "Mark Reyes" into the table? I think you said you hard code, but I may have misunderstood you.
Could you post that code?

Thanks,
Brad

[ July 10, 2007: Message edited by: Brad Smiths ]

[ July 10, 2007: Message edited by: Brad Smiths ]
[ July 10, 2007: Message edited by: Brad Smiths ]
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

Referring to what Bear had said, you would do something like this:

<a href="<%= request.getContextPath() %>/showUserData.do?employeeID=${personUserName.employeeID}" >

This will send a parameter called employeeID along with the request, which can then be retrieved by your Servlet to find your employee account information.
 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sir Jason,

Thank you very much for the code that you had given. I finally got things going in my code and it now displays the complete employee information when i click the link.



In the JSP that I will be forwarding this request. I just extracted the added parameter ID.

For a while I was thinking of letting javascript handle the clicking action but as pointed out by Sir Bear it might take so much of an overhead.
I'm happy to have learned this stuff.

Again, thanks to everyone that responded in my post.
[ July 10, 2007: Message edited by: Bear Bibeault ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic