GeeCON Prague 2014*
The moose likes JSP and the fly likes Getting Data from HTML Table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Getting Data from HTML Table" Watch "Getting Data from HTML Table" New topic
Author

Getting Data from HTML Table

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
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


Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

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.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brad Smiths
Greenhorn

Joined: Dec 10, 2004
Posts: 4
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 ]
Jason Kwok
Ranch Hand

Joined: Mar 31, 2005
Posts: 126
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

Joined: Jul 09, 2007
Posts: 426
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Data from HTML Table