开发者

Running Java through server

I have a website. I'd like to do the following:

Have an input box that the user can type a java program. Then, they can press "Run" and it spits out standard output. How can I achieve this?开发者_如何学Go

I tried thinking about using exec("javac $filename") in php and just compile and run the java program, but that doesn't seem to be working. Any ideas?

I am trying to make a "learn Java" site, and I need the user to be able to play with code by typing into spaces on my website. I just can't figure out how to go about running Java using php, html, or things like that.


Yes it could be done, along the lines of what you've described too. However this is a massive security risk. You don't want to allow unknown/untrusted people to be able to execute arbitrary code on your server. At the very least you'd want to be very careful with this idea, and possibly better still, modify the idea so that arbitrary code can not be entered, and executed.


  1. Do not do this! Get people to run an applet or something. In addition to the security implications, your server would also likely grind to a halt.
  2. If you ignore (1) just use a proper app server and get people to write their own jsps (make sure caching is turned off). It's a very easy bit of file IO.


You might look into Quercus. It's a java web server that runs PHP. You might be able to run the java code right in the web server then. http://www.caucho.com/resin-3.0/quercus/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜