views:

58

answers:

2

Hi, I have a Java program that I'm trying to interact with over the web.

I need to gather form data from the user on a Drupal site that I don't have any control over, send it to the Java program, and send the output back to the user. The Java program needs to load a lot of libraries every time it's run, so it needs to be up waiting for data from the user.

It'd be best for me to just have an HTML form for the input. What's the simplest way to deal with HTML form data using Java?

Also, I'm trying to call the Java program from a shell script. I want the program running in the background though so the libraries are loaded in advance. So ideally, I could use the server I set up for both applications.

Thanks for any help.

A: 

It sounds like you really just want to write a servlet (or use a higher level web framework, but a servlet would work fine). That makes it very easy to get web form data - you just ask for values by name, basically.

You could then "script" the application using curl, wget or something similar to make requests to the servlet.

Apologies if this doesn't answer your question - I'm finding it slightly tricky to understand exactly what you're trying to do, particularly as there are multiple layers of web UI involved, as far as I can see.

Jon Skeet
Thanks for your response!I'm having some problems setting up the servlet and I'm not sure if it's because the server I'm on is so restricted. Specifically, can I just put a class file in my cgi-bin? I can't find a good tutorial. Could you give me a pointer?As for my second question: I want to call the Java program from within a Python program, but I don't want the Java program to have to load all the libraries every time it's called. So, I thought the solution would be to have the Java program running in the background.
No, you can't just put a class file in cgi-bin - or at least, not to get servlets running. Search for "servlet tutorial" and you'll find loads of them. If you use servlets, your Java code *will* be running "in the background" because it'll be part of the web server, effectively.
Jon Skeet
My problem has been that I can't install Tomcat or anything on the server I'm using. I wasn't sure if I could just hack it together. I guess I'll find another server.Thanks for your advice.
Yes, it sounds like you do need to change to a different server. While there would probably be ways of working around it, you'll have a smoother ride if you can use normal Java servlets.
Jon Skeet
A: 

The easiest way to make POST requests with java is to use the Apache HttpClient or the more recent HttpComponents libraries.

kgiannakakis