Interfacing a Java Program with Forms on a Webpage

I am wondering if there is a way in Java to answer forms on a Webpage such as userid and password and then scrap the results of the webpage back into the Java Program?Thank You, I am not in the need of code or samples just can it be done?
[252 byte] By [thebrowns24a] at [2007-9-27 8:07:34]
# 1
Yeah, im sure it can be done
james007ga at 2007-7-8 15:34:04 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
Yes it can be done. Java Servlet can capture anything return from the browser.
danielyeapa at 2007-7-8 15:34:04 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3
Servlets and/or Jsp is the api to look at.
sanjeevdga at 2007-7-8 15:34:04 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4
What if it is a existing website that has a form entry but i want to write a standalone app not a servlet or jsp?
thebrowns24a at 2007-7-8 15:34:04 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 5

You could write a java application that acts like a simple web server (assuming there isnt one already running on that machine). In your code create a ServerSocket and have it wait at port 80, when incoming requests come in you have to parse the data and check whether is it is a POST or GET (those appear as is) then you need to figure out how to get the information out of the text sent it. Keep in mind that this is not a fully functional web server and will not serve files it only accepts requests. Also security maybe lacking , but its a start...of course I would recomend JSP and Servelts but if you really want it to be a java app this is one way...good luck

hattana at 2007-7-8 15:34:04 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 6

I think these are the steps to take, I have written a cpl of these stand alone programs when I was still in school. Don't have them here though.

1) Open a socket connection to the web server (port 80)

2) Send a HTTP Header and request.

3) Send the HTML answer. (filled in form with username and password)

4) Read the servers answer (if correct uid you'll get the next html page)

5) close the socket

6) parse the html page you just received.

Have a look at:

http://www.javaworld.com/javaworld/javatips/jw-javatip41.html?

Have fun

xica at 2007-7-8 15:34:04 > top of Java-index,Archived Forums,New To Java Technology Archive...