Solved

JSP - How to identify the link I clicked?

Posted on 2004-03-30
3
401 Views
Last Modified: 2012-05-04
I've been doin programming using WebSphere (Struts, Bean). In the menu bar I've two links called A&B. My page mock-up is common for both A&B pages except in B I'm having two more buttons. So, I've want to have only one JSP page, but based on the link(A or B) clicked, I want to show show different thing. My question is how do I identify which link I clicked? Please advise. Thanks a lot.
0
Comment
Question by:Sekar1971
3 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 10723210
On click of each link, you can call a specific Java script function which will do your stuff. Something like:

onClick="javascript:clickA();" // -> for A

onClick="javascript:clickB();" // -> for B

You can do specific stuff in clickA () and clickB () functions.
0
 
LVL 2

Accepted Solution

by:
rqs earned 125 total points
ID: 10739334
I'm not sure if I understand the problem correctly but if,
what you want is a single JSP program that would behave
differently depending on the link clicked to get to that JSP page

here's what I suggest:

on the HTML menu bar you were referring,
<a href="nameofjsppage.jsp?Menu=A">Menu A</a>
<a href="nameofjsppage.jsp?Menu=B">Menu B</a>

and then on the JSP code, something like this

//request is HttpServletRequest variable

String menu = request.getParameter("param1");
String valueA = "A";
String valueB = "B";

if (menu.equals(valueA))
{
//do stuff that ought to be done when menu A is selected

}
else if (menu.equals(valueB))
{
//do stuff that ought to be done when menu B is selected
}

tell me if this helped
0
 

Author Comment

by:Sekar1971
ID: 10750609
Hi rqs, Thanks for the response. I did it in a different way. Decalred a hidden variable called linkType and passed linkType="A" and linkType="B" in the links. Using struts logic.equal syntax, based on the linkType I got my pages. Thanks.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question