Question on how to capture a clicked item on a table and pass to a Servlet?

Hello,

How do I capure an item clicked on a table and send it to a Servelt? For example Say I have a table like this...

   item1      item2        item3
   item4      item5        item6
   ------       ------        ------

Say I click on item5. I need to pick this item and call a Servlet so that I pass the value 'item5' to the
servlet.

Thanks
prain
prainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fargoCommented:
Hi,

There are two options

1) When you click on a particular item, have a onclick event , set the hidden parameter in the form with this particular value and then submit the complete form (This means refresh complete page) and the action of the form should be the servlet.

2) Use AJAX and have an action make a java call (with servlet)

fargo
0
prainAuthor Commented:
So do I have to attach an onClick event for each item in the table?
0
el_diosCommented:
Yes, how are you getting the items in thetable? You could use a scriptlet for doing this.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

prainAuthor Commented:
Within my servlet that prepares the table, I am having a variable. So the items that you see in the table are NOT
hard coded they are genrated dynamically. This is the line that I create each cell . the

displayName

is a java String variable.


out.println("<td>" + displayName + "</td> ");

So what I need is to pickup the value presented by t he displayName (visible in the table) and then
pass that value to a Servlet.

Thx.
0
prainAuthor Commented:
Hello,
I am increasing the points to 125.

I am getting the whole table messed up when I attach onClick or any other in each cell.

Again, here is what I want.

My table is generated by a Servlet. The Servlet has a loop within which I have this code.

out.println("<td>" + displayName + "</td> ");

where displayName is a java String variable. So when the table is created, item visible on each cell is created dynamically.

So I will have a table like this....

  item1      item2        item3
  item4      item5        item6
  ------       ------        ------

This works nice and the table is generated nicely. Now I want add some spice to that. I want to make each item a selectable item and then when selected I want to call a Servelt and I want to pass that selected item to teh servlet. Any help?
0
fargoCommented:
>> I want to make each item a selectable item
ok. What do u mean by selectable item?

Do you wish it to be a link?
Do you wish to add a checkbox to each item?

What exactly?

fargo
0
prainAuthor Commented:
Actually it sould go to a Servlet. We we can say it s a link.
0
fargoCommented:
well,

if it is a link, it makes the job quite easy.

<a href="/to/your/servlet?param1=itemValue">item1</a>

you click on this link in your table and you go to a servlet. Will this be of help?

fargo

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prainAuthor Commented:
fargo,

Goodie!. I got it. Thanks for all hints. a+

prain
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.