manipulating the website action through external java code - java

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

Related

Java - Dynamic dropdown to country/state

In my web-application I have a the following requirement.
I need to have a dropdown for country.
Based on the country selected I need to display the corresponding states.
I need to fetch both the country and state from database.
I cant use javascript since in production(live), javascript will be disabled.
I guess I have to use ajax to implement this?
Can anyone please tell if there is any better way to implement the above requirement?
I have seen the following link.
Populating cascading dropdown lists in JSP/Servlet
But I dont like to use javascript (since my client will disable javascript in Production environment)
I cant use javascript since in production(live), javascript will be disabled.
Can't use javascript than you would have to refresh the page i.e.:
Select Country from drop-down
Provide a link or button to submit this value (click on this)
Server call, which will retrieve the Country values and also the State values for the country selected
display the JSP with the values retrieved and make the Country which was submitted pre-selected in the drop-down.
I guess I have to use ajax to implement this?
Now my friend you are contradicting your own self, because ajax (I am sorry to say this) is nothing but javascript, it is not some different language than javascript.

prompt() in wicket components

I try to find pattern how to return 'prompt()' result in java like http://www.mysticcoders.com/blog/wicket-ajax-confirmation-modal-window/ (but in this case author using 'confirm' instead of 'prompt' and doesn't return anything from javascript). Now I am using hidden field in form and update this field before submit, but maybe you know how to solve this problem more elegant (for example using AJAX components in wicket). Thank you for your time.
If you just want so submit the prompted value within your form, your hidden field approach looks adequate to me. If you want to call some Wicket code on the server with the prompted value independently of the form submission, see How do I call Java code from JavaScript code in Wicket?

How to restrict double click on button in struts /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).

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.

Clear HTTP Session

I am trying to clear everything on my HTML form when I visit it from a hyperlink entry.
Any ideas? My development language is java.
are you using session-scoped data? if so, close your browser and open it again.
I'm not sure the application is, but one way to accomplish this would be to use JavaScript. For example, if it is acceptable to clear the form every time that page is visited you could write a quick function that clears the form when the page is loaded (i.e., using the onload event).
If you only want to clear the form when the page is hit from that link you could add a param to the URL (e.g., clearForm=true) and use JavaScript to pick up the query string and clear the form when that parameter is present.
This is, of course, a purely client-side solution. For a server-side solution it would be helpful to know what framework you are using.

Categories