aspose file tools*
The moose likes Beginning Java and the fly likes Prefill a web form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Prefill a web form" Watch "Prefill a web form" New topic

Prefill a web form

Joe Hertl

Joined: Aug 27, 2012
Posts: 2
Hi, I´m fairly new to Java and need help with a problem I´m unable to solve and so far all searches have turned up empty.
There is a webpage that contains a form. I have a java desktop application that stores a database with data I want to use to fill the form. The user scenario is as follows:
In the application:
1) The user opens the application and finds the desired row in database table.
2) The user clicks "open on website" button.
In the browser:
3) The webpage opens in a browser with the form already prefilled.
4) The user fills in captcha and clicks "submit" button on the webpage.
5) The result displays (just for the user to see, there is no parsing performed)

The problem is between steps 2 and 3. Is it even possible to open the website in a browser with the form already prefilled?

I have already tried htmlUnit, but failed, though that could be due to my inexperience. I cannot modify the webpage in question (it is run by state). Unfortunately, just submitting the form programatically and parsing the returned html page is not an option - the user always has to click "submit" button himself (in this case, actually, herself).

If it can help, this is the webpage in question:

Thanks in advance
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157

Hi Joe, before coming to your presentation, on button click call a servlet which will have table values in response and fill those values in corresponding fields.
1. dont come directly to html page
2. give a link like
3. make a servlet showForm and set Attribute in request
4. dispatch that request to html page
5. fill all values in html.

I hope this will help you.
Joe Hertl

Joined: Aug 27, 2012
Posts: 2
Thanks for your reply. There is a problem though - likely caused by my inexperience - perhaps I do not understand what you meant by step 2, but I think you want me to modify the webpage in question ( Unfortunately, I cannot do that, since I do not have the administrator rights for that webpage
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157

Hi Joe, step 2 means create a servlet and give it url as showForm.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42277
You *will* have to modify the page in question. You'll have to convert it from HTML to JSP in order to populate it dynamically. if you can't change the page, how do you propose to change the page? :-)

Ping & DNS - my free Android networking tools app
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

You can do this client-side, but not from a stand alone application. You would need to create a browser plug-in that does the work. The plugin would probably read the HTML that comes in, read the values from your database, match database fields to the form fields, and inserts javascript at the end of the page which pre-fills the appropriate form fields.

See RoboForm (a password manager) as an example that proves you can do this with any page, as long as you have a browser plug-in installed. You could probably do the browser part using greasemonkey scripts (or similar) as long as you can get those scripts to communicate with your application.

I agree. Here's the link:
subject: Prefill a web form