Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to trap a button click?

Posted on 2006-04-03
8
Medium Priority
?
190 Views
Last Modified: 2010-04-01
Hello,

Here is the scenerio....

I have two buttons showing on browser. Both buttons are linked to the same Servlet.

How do I trap which one was clicked by the user WITHIN  THE doPost() method?

Thanks
prain
0
Comment
Question by:prain
  • 3
  • 3
  • 2
8 Comments
 
LVL 11

Expert Comment

by:fargo
ID: 16364466
Hi,

One way is to use a hidden parameter to see which button is click.

You can set the value of the hidden parameter depends upon which button is clicked.

fargo
0
 
LVL 29

Accepted Solution

by:
bloodredsun earned 400 total points
ID: 16364480
add a parameter to the link so that one button goes to "http://www.myhost.com/myservlet.do?src=button1" and the other goes to "http://www.myhost.com/myservlet.do?src=button2"

THen in the servlet code call this

if("button1".equals( request.getParameter("src") ){
//send by button1
}else{
//sent by button2
}
0
 
LVL 11

Expert Comment

by:fargo
ID: 16364494
Hi,

<script>
 
function update(valuetoset){
document.forms[0].hiddenparamname.value=valuetoset;
document.forms[0].submit();
}

</script>

<html:button.......onclick="update('button1value');"/>

<html:button.......onclick="update('button2value');"/>

fargo
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:prain
ID: 16364940
bloodredsun,

I like your method. But when I implemented that in my source, I am getting the famous HTTP error 404. It does not recognise the .do part?

Here is a portion of my code...

out.println("<form method=\"post\" action=\"/pSystem/PFolders.do?src=show\">");
.....
....
out.println("<form method=\"post\" action=\"/pSystem/PFolders.do?src=add\">");


and then in my doPost() I have a block like this....

if("show".equals( request.getParameter("show") ) ){
  System.out.println("coming from show");
}else{
System.out.println("coming from add");
}

And the error is
HTTP Status 404 - /pSystem/PFolders.do

--------------------------------------------------------------------------------

type Status report

message /pSystem/PFolders.do

description The requested resource (/pSystem/PFolders.do) is not available.


Note : I have a PFolders.class file in the appropriate folder in the WEB-INF and is a working Servlet and
I have been working with that for a while now. Only thing I added was the .do  as you have specified.

Any input will be appreciated.

Thanks
prain
0
 

Author Comment

by:prain
ID: 16365089
OK. Blood,

I think I fixed that problem.

But now I have another problem. When any of the two buttons is clicked,
it always goes to "Coming from add".

Trying to figure out.

-prain
0
 
LVL 11

Assisted Solution

by:fargo
fargo earned 100 total points
ID: 16365122
hi,

request.getParameter("show")  

should be

request.getParameter("src")

fargo
0
 

Author Comment

by:prain
ID: 16365191
Bloodredsun,

Thanks pretty clever.

I will split the points b/w blood and fargo, but majority goes to Blood.

Thanks fargo too.
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 16365262
cheers prain
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

810 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