How to restrict double click on button in struts /Java? - java

I have created a web form. On Click of button, database query would be fired. The Problem is that when user clicks on button twice, query would be fired 2 times. I want to prevent that. Any help?

Take a look here
Struts2 has a built in mechanism for stopping double form submission that works on the server side instead of the client. You may need to add the TokenInterceptor if its not on the defaultStack you're using.
Here is a quick tutorial

If you are happy to use jQuery you could consider using
http://jquery.malsup.com/block/
onclick or onsubmit call $.blockUI();
Some Demos for your reference
http://jquery.malsup.com/block/#demos

The belt and braces approach is to set a JavaScript flag variable when the button is clicked and block subsequent submits "onclick". Then, on the server, implement the "synchronizer token pattern" (you can just Google that term to find out about it).

Related

what is the simplest way to call a java method on a button click in jsp page

I have some Java classes that have methods in them and when I click some of my buttons in jsp page a method should be called in order to do some operations. I tried servlets, I tried making an object and I don't know what to do anymore...Nothing works. Please help me !! Thank you !
There are two ways to do this.
Either submit form to make synchronous request to server to perform the action you want
Or you can invoke an ajax call for asynchronous call.

How to run task in the background in web application?

I have a submit button in a JSP. This button calls 2 functions: function A(…) and function B(…). The latter sends emails to many users, maybe 1000 users or 2000. When I click on the submit button, the page keeps loading until the emails have been sent to all of the users. This takes too much time.
Is there any way to make the page load just until function A has finished and then run function B in the background? or does anyone have any other suggestion to solve this problem?
Make it work by AJAX calling two servlets or JSPs. When you click the button it does an AJAX call to servlet_A, and when you get the response back from there and put the output in a DIV or something, then make an AJAX call to servlet_B and let it take however long it will.
Contrary to what was said in a comment above, AJAX would be good for this because it runs asynchronously. You send off the request and whenever the response comes back, you do something with it or don't.

manipulating the website action through external java code

There is a website,and it has a button on click checks for the value in the textbox and searches for it and displays the result.
How can i with my java code,prove the input and display the appropriate result on my java code.
On seeing the source of the website,i get to know the methods that gets called on the button click.But what and how to further trigger the event and pass the value to textbox and obtain the resut !!
Use a programmatic web browser like HtmlUnit.
I'm not 100% clear on what you're asking for, but it sounds to me like you're trying to get some sort of client-interaction emulation/automation.
Check out Selenium's Java API

How to get a live search feature using Jquery, AJAX, and Servlets?

I have been following this guide: http://veerasundar.com/blog/2008/12/implementing-ajax-in-java-web-application-using-jquery/
When a user types a keyword in the search and presses the search button, I am able to get results back. Now, how do I make it so when the user starts typing any character, there is a post request. Right now, it uses the click function. I want to be able to get rid of the search button and let the post request occur whenever the user starts to type in a letter in the search bar.
Thanks.
One that uses jQuery
http://docs.jquery.com/Plugins/autocomplete
Plain js
http://www.brandspankingnew.net/archive/2006/08/ajax_auto-suggest_auto-complete.html
http://articles.sitepoint.com/article/life-autocomplete-textboxes
You can use much of the same code. Just replace
$("#getWeatherReport").click(function(){
by
$("#cityName").keyup(function(){
To learn more about jQuery, I'd warmly recommend their own tutorials.

AJAX implementation with drop down

HI
Currently into my application I perform a normal action for every drop down. For instance I have a page which has 5 drop down so it takes time for every consecutive action. So I am thinking to incorporate AJAX methodology for achieving it. Pls help me in doing so with an example.
Regards
Rj`
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/CascadingDropDown/CascadingDropDown.aspx
Here's an example using jQuery:
http://jsfiddle.net/sje397/sadtA/
This fills in the second drop-down with data from the server based on the selection in the first drop-down. There are comments to explain some of the jsFiddle specifics.

Categories