473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

filling a web page form by java

hsn
237 100+
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 20615
BigDaddyLH
1,216 Expert 1GB
It sounds like you are trying to programmatically POST. The Jakarta Commons HTTPClient can help.
Aug 25 '08 #2
hsn
237 100+
It sounds like you are trying to programmatically 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 100+
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 Expert 512MB
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+makro+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
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...
1
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...
2
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...
1
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...
0
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...
3
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...
0
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...
1
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...
1
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
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.