473,672 Members | 3,354 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

filling a web page form by java

hsn
237 New Member
hello everyone.
i am trying to write a program which will open a url connection to a website and to its form and fill it up with dat and then submitting this form.
when i run the program i know the fields name and what they are called in the scrip. know that it doesn't matter which scriptting language the webpage is using. But, if you needed to know it is javascript.
my question is if someone could help me a little here. i am reading some books here and there what i need is some tips or advice from those who wrote a similer program.

regarding
hsn
Aug 25 '08 #1
4 20817
BigDaddyLH
1,216 Recognized Expert Top Contributor
It sounds like you are trying to programmaticall y POST. The Jakarta Commons HTTPClient can help.
Aug 25 '08 #2
hsn
237 New Member
It sounds like you are trying to programmaticall y POST. The Jakarta Commons HTTPClient can help.
thanks i forgot to include that it will be done by using the POST command not by the GET command
regards
hsn
Aug 25 '08 #3
hsn
237 New Member
someone please give me some hints or ideas.
i want my java code to act like any user when the user fill up a form on an html page.
i don't want it to use a POST or GET commands, i don't want it to pass the values through the URL.
I want my program to act like a user , i want it to open a form, fill it up, and then press the submit button.
if anyone has any ideas i would be really greatful/

Regards
hsn
Aug 31 '08 #4
chaarmann
785 Recognized Expert Contributor
someone please give me some hints or ideas.
...
i don't want it to use a POST or GET commands, i don't want it to pass the values through the URL.
I want my program to act like a user , i want it to open a form, fill it up, and then press the submit button.

Regards
hsn
Please note: If a user presses the submit-button then exactly that happens: the system sends a POST or GET request. (I know that here are also some other exotic ways and browsers, but I speak of the common case). So your question is like saying I want to make a fried egg, but I don't want to use a raw egg and I don't want to use a pan for that which would be the simplest way. So literally speaking, your only option then is to get a cook that does it for you.

How to get a cook:
Just use a Windows macro recorder (like Easy Macro Recorder or so) and start it. Then open your explorer, go to the page, fill out the values, press submit and then stop the recorder. It produces a file which you can then easily execute in your java program with Runtime.exec().

But if you want to fry your eggs yourself, which I would prefer, here is the source code of a program that sends a POST-request and gets the response page back (the HTML source code is contained in the return string). Then you can parse that string for any result you are interested in. It is quite old and uses a non-blocking HTTPClient.jar-file for the request, but you can also do it in a similar way with the java.net.URL class which are include in the newer java versions.

For example you are on google-site, enter "easy makro recorder" and press "submit". Then the browser send a request like that:
"http://www.google.com/search?q=easy+m akro+recorder".

Now the java program that does it for you:
Expand|Select|Wrap|Line Numbers
  1.  import HTTPClient.HTTPConnection;
  2.  import HTTPClient.HTTPResponse;
  3.  import HTTPClient.CookieModule;
  4.  
  5. String urlWithValues = "search?q="+ URLEncoder.encode("easy makro recorder");
  6. String host = "64.233.167.99"; // = google.com. You can also use InetAddress.getByName("google.com") instead.
  7. String port = "80";
  8. HTTPConnection connection = new HTTPConnection(host, port);
  9. HTTPResponse response = connection.Post(urlWithValues);
  10.  
  11. InputStream input = response.getInputStream();
  12. BufferedReader dataInput = new BufferedReader(new InputStreamReader(input));
  13. String searchResults = "";
  14. while (true)
  15. {
  16.     String line = dataInput.readLine();
  17.     if (line == null)  break;// end of response
  18.     searchResults += line;
  19. }
  20.  
  21. System.out.println("google found following results:" + searchResults); 
Sep 2 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3984
by: sentinel | last post by:
Hi, Wonder if anyone can help with this problem: I am using an app with several pages, using a session to track vars between the pages, and using an image map to re-direct back and forwards between the pages. The way I redirect is when the image map is clicked on, it posts to a page called 'control.php' which passes the POST vars to the
1
1457
by: mmac | last post by:
I have been investigating how to create a multi page form in Frontpage that eventually will allow an emailed result. I can write the asp to "post" from one page to the next easily enough but when it comes to the last page, I can't figure out how to email the results. the syntax "response.write" will write to a web page but it won't fill in the content of am email. I thought of putting the "response.write" inside the body of a CDO.message...
2
1619
by: Jishnu | last post by:
HI All, I am writing a multi page form. I am using hidden input statements to pass my variables between different pages. Now I want to provide a page whereusers can update the previous entered data. The form at this point is populated through the hidden variables. But as I submit after making any changes. the hidden values instad of updating get an extra value. Is there any way to get around it. Thanks
1
2583
by: Adam Smith | last post by:
Have a lot of data to collect / choices presented, producing a large form. I am desirous of breaking it up into multiple pages to avoid detracting users. Could some one say how best to create such a multi-page form. Submitted either individually or as a single integral unit? Since it would be necessary to identify each page as originating from the same user without having them enter their ID information redundantly on each page. ...
0
1258
by: Wim Verhavert | last post by:
Hi all, I'm having this little problem here. I want to build a database which contains a list of books I want to read. What I want to do is, to make MS-Access get all relevant information from the library's online database (for example if they have the book and so on). So what I thought doing is making a form with a hidden webbrowser control. For every record in my table the webbrowser control is triggered and the html page is send back...
3
1158
by: Bill | last post by:
Is there a way for a web form to submit to another web form and still use the form elements like text box's etc..? It appears that the second page would not know what form elements were on the first form. How should this be handled? I know you can do it using the request object but I rather use the form elements if possible. I need to do this because my application is a multiple page form, where the next form is dynamic and depends on...
0
1614
by: Tim_Mac | last post by:
i say "bug" in quotes because i can't really blame microsoft for a feature not working in a non-microsoft browser. However, i would have preferred if they did some better browser testing! if i press return or enter inside a multiline textbox in firefox, with Page.Form.DefaultButton set, the form is submitted. validation will usually prevent an incomplete form being submitted anyway, but the user may intend to fill in optional fields,...
1
2442
by: anilbhu | last post by:
Hi, Is it possible to set default home page using java technology. By using this.setHomePage() of javascript we can achieve this but, it works only for IE and not for any other browser. Can anyone share any idea regarding this.. Thanks ! Anil
1
1809
by: iamvani | last post by:
hi , i am creating a sign in page but it is not completed .can u help me create a signin page using java(swing).or jsp
1
2491
by: Amanda Semijalac | last post by:
I am making a two-page form that will be used to have a classroom of people submit their information by passing around an iPad. I have 'form1.php', where a leader types their name and a class they are teaching. There are two input text boxes on this form: leader name and class name. After filling the two fields, they hit 'continue' to go onto the next form page. The 'continue' button goes to 'form2.php', where a person in the class types...
0
8945
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6255
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4242
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2837
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1837
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.