File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes dynamic java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "dynamic java" Watch "dynamic java" New topic

dynamic java

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

Hi all,
what i'm trying to do is execute some simple java code dynamically from a jsp page and display output into this page.
I need to load a java program (this one should contain a main() method) and run this program. get output from this program.. and then display result to jsp page. for example :
public class Test{
public static void main(String[] arg){
now from a servlet /jsp page i should run which will display "hello" ...i.e "hello" should be displayed to the webbrowser in the jsp page. (should be done for any java program dynamically)

any Ideas on how to tackle this problem ?
thanking you.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

If you must call them via the OS, look at Runtime.exec:

Why wouldn't you want to just instanciate the objects and call their methods?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63839

Doesn't work that way. When you activate a separate Java program, it will send its output to System.out like any other Java program.

Since you're already in a JSP page, why the need for a separate program?

[Asking smart questions] [About Bear] [Books by Bear]
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

thanks for replying...
i'm developing a web application for online compilation and execution of java programs...user clicks a button and a java program should compile and execute...the problem is that my java progs sends output to System.out ..but i want to be able to get this output and display it into my web page...i suspect this involves using some technique to redirect output depending on which Thread is currently running.

I would appreciate any Help to solve this issue.

I agree. Here's the link:
subject: dynamic java
It's not a secret anymore!