Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help understanding how Java can interact with web pages  RSS feed

 
Colin A Thompson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for a tutorial or book that explains how to get my java programs to interact with web pages. So far I have been able to access webpages through httpurlconnection to get data on specific pages.

I would like to learn how to post to forms or click objects on a given web page and have the results return to my program for further analysis.

Any tips or guidance would be appreciated.
 
Donald Williams
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The primary means of interaction between web pages and Java code are via Servlets, Java Server Pages and Java Server Faces. In all cases, the web page is the driver or orchestrator. Servlet programming is the oldest of these technologies but may be the easiest to start with as the other two options build upon it. As for learning, I would simply do a Google search for "servlet tutorial". There are many fine examples online to get you started.
 
Janeice DelVecchio
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually just bought HeadFirst Servlets/JSP. I haven't read very much, but it came highly recommended

I love all the HeadFirst books.
 
Paul Clapham
Sheriff
Posts: 22489
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have been using HttpURLConnection, then you have been interacting with web sites, not with web pages. That might seem like a trivial distinction but it's an important conceptual difference.

For example, you don't "click an object". What you do instead is to send the request that would happen if a human clicked on the object when displayed in a browser. It might take some work to find out what that request is, but that's what you have to do.

As for POST requests, you can do those with HttpURLConnection too. But I find that learning the details of the HTTP protocol is too much trouble, so I downloaded Apache HttpClient. It has all those details built into it and you just call methods to (e.g.) create a POST request, add parameters to it, and submit it.
 
Campbell Ritchie
Marshal
Posts: 55715
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a candidate for transfer to the JSP forum.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I understand the question, you're looking for a way to access web sites programmatically. The best way to do that in Java, IMO, is the HtmlUnit library (and the jWebUnit library, which builds on top of it). Those work at a higher level than UrlConnection or HttpClient - HTML instead of HTTP.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!