Adding basic web front-end to Java app

G

gigajosh

Can anyone tell me how to add a really basic web front-end to my
bog-standard Java app. I just want to run the plain old main() method by
passing the arguments in via a web page.
Do I have to create a form plus a simple applet/servlet or something,
then just call my program from the applet/servlet?
Any tips on templates I could use for the form and the applet/servlet?

Many thanks,
 
M

Michiel Konstapel

gigajosh said:
Can anyone tell me how to add a really basic web front-end to my
bog-standard Java app. I just want to run the plain old main() method by
passing the arguments in via a web page.
Do I have to create a form plus a simple applet/servlet or something,
then just call my program from the applet/servlet?
Any tips on templates I could use for the form and the applet/servlet?

Really basic? Create a form with text fields for each of the parameters
you want to pass to the app in question. Submit that form to a servlet.
Then, you have two options:
- make the servlet call com.foobar.YourApp.main(String[] args) directly
- use Runtime.exec() to execute "java com.foobar.YourApp args"

The first runs the app in-process, which is nice 'n' fast but won't work
if your app calls System.exit() - that would shut down the whole servlet
container. The second is less efficient since it needs to fire up a new
process and JVM each time, but it does isolate your servlet container
from the application. It also makes it easier to capture the app's
output (Process.getOutputStream()). I'd go for option two.

Then, just capture the output and send that back as an HTML page and
voilà, a web frontend :)

HTH,
Michiel
 
J

Josh Downes

Thank you both for your help. It's plenty to get me started :))


Can anyone tell me how to add a really basic web front-end to my
bog-standard Java app. I just want to run the plain old main() method by
passing the arguments in via a web page.
Do I have to create a form plus a simple applet/servlet or something,
then just call my program from the applet/servlet?
Any tips on templates I could use for the form and the applet/servlet?

Many thanks,

--
De informatie in deze e-mail (inclusief bijlagen) is vertrouwelijk en
uitsluitend bestemd voor de geadresseerde.
Indien u dit bericht onterecht ontvangt, wordt u verzocht de inhoud niet te
gebruiken en de afzender direct te
informeren door het bericht te retourneren en van uw computer te
verwijderen. NV Casema is niet
verantwoordelijk en wijst iedere aansprakelijkheid af voor en / of in
verband met alle gevolgen en / of schade van
de verzending, ontvangst en /of inhoud van deze e-mail. Casema is niet
aansprakelijk voor computervirussen die
veroorzaakt zijn door deze e-mail.

The information in this e-mail is confidential and intended solely for the
person to whom it is addressed. Should
you receive this message unintentionally, please do not use the contents
herein and notify the sender immediately
by return e-mail and then delete the message from your computer. NV Casema
cannot be held responsible or
liable in any way whatsoever for and/or in connection with any consequences
and/or damage resulting from the
dispatch and receipt of this e-mail and the content of this e-mail. Casema
takes no responsibility for any computer
virus that might be transferred by way of this email.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top