form options

hello again- I have a question that I've been unable to find an answer to, and any help would be appreciated (heck, that's why we post, no?)

I'm attempting to write data from a java program to a webpage. Specifically- on this page there is an HTML form, which performs a search. there is also a menu of different options. The form takes an entered sequence of DNA base pairs, and searches a genome for close matches. the menu selects which genome to search (human, mouse, etc.). I was wondering how to both enter text and select the option from the pull-down menu from the java program.

If it helps, I could put my code here, but seeing as that operation is pretty much the entire program, I don't have much that would be helpful. I am using a URLConnection

[781 byte] By [Bacter23a] at [2007-11-26 17:43:59]
# 1

So, you're saying that you're trying to write, in Java, a program that connects to a web server and submits data that normally comes from a web page?

If so...you don't have to emulate the page itself, just the way that the browser packages up the data and submits it to the server. Generally this means URL-encoding it, getting the number of bytes in the encoded string, setting some HTTP headers, and writing the data across the connection. Then presumably you'd be reading from the response to the connection.

Note that it can get arbitrarily complicated, depending on what the server is doing. For example if the server requires you to log in, you'll have to do that and also to maintain some state re: the login status.

paulcwa at 2007-7-9 0:12:11 > top of Java-index,Java Essentials,New To Java...
# 2
alright, thanks. I don't want to take up forum space asking how to do this- is there a good site for this stuff?
Bacter23a at 2007-7-9 0:12:11 > top of Java-index,Java Essentials,New To Java...
# 3
aaaand i found one of those too. nevermind, and thanks again
Bacter23a at 2007-7-9 0:12:11 > top of Java-index,Java Essentials,New To Java...
# 4

Offhand, I can't think of a tutorial or book that specifically says how to do this particular thing.But the Java tutorials are good place to look. Look at the networking tutorials.

http://java.sun.com/docs/books/tutorial/networking/index.html

Though you may know a lot of this already if you know you're using a URLConnection.

I suspect there's an article on, say, javaworld.com or the like, that might cover this exact thing.

Basically you're looking for instructions on writing a "web client" (aka "user agent" or just "browser"), in Java, and that can handle (as you've already noted) web data submissions.

Also if you're part of the organization that owns the site you're connecting to, or if they're just open to it, you might want to contact them to get details about the server that may be relevant to your situation. (For example, if their app uses javascript, that'll make your task a lot harder. Maybe they can warn you about potential problems and supply workarounds.)

Hope this helps.

paulcwa at 2007-7-9 0:12:11 > top of Java-index,Java Essentials,New To Java...
# 5
if anybody has experiance with HTML error codes- i'm getting an error code 500... googling this, some people say it's my fault, some people say it's the server's fault. what's the call?
Bacter23a at 2007-7-9 0:12:11 > top of Java-index,Java Essentials,New To Java...
# 6

Do you mean HTTP status codes?

500 means server error. Probably you sent it input that it couldn't deal with, and it didn't break gracefully. Or maybe something completely irrelevant to what you're doing happened.

I'm going to guess that you didn't encode the data correctly and the server didn't cope well. That's just a guess though.

paulcwa at 2007-7-9 0:12:11 > top of Java-index,Java Essentials,New To Java...