You should take a look at HTMLUnit, it'll be much simpler than using the above. The following page and code should guide you:
Lee mas