• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP invoked java and java did its part. But no output from JSP

 
ravi san
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


this is my code in jsp. This invoked java and java got the results. how ever it is not displayed on jsp. Please help me in this regard



String s = "";
Runtime rt = Runtime.getRuntime();
Process prcs = rt.exec("D:\\java\\jre6\\bin\\java -jar D:\\webhome\\sites\\epsdev4\\webapps\\DB2\\db2live\\AdminJob.jar "+imsssid);
prcs.waitFor();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(prcs.getInputStream()));
while ((s=stdInput.readLine()) != null) {
//processed it here
}
prcs.destroy();

Thank you
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you ever create or write a response ??

The output from the java being invoked will not magically appear in the browser.

JSPs are not stand-alone operations, like the command line ones are.



WP
 
ravi san
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My java code has lines like System.out.println and System.err.println. I am new to this java as well as jsp. Just trying to get the results back. If you want I can post the java code. Please

reply.

Thank you
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravi san wrote:
My java code has lines like System.out.println and System.err.println. I am new to this java as well as jsp. Just trying to get the results back. If you want I can post the java code. Please

reply.

Thank you


System.out.print statements don't print to the HTML displayed page, they print to the Java console - for a Servlet Container this output can either be ignored or printed to a special output text / log file. The JSP will provide a specific output stream you need to write to in order to display to the user. All of this is a really bad idea, though. You should not have code like that in your JSP, at worst it should be in a normal Servlet (which can collect the output into variables, store those variables into a sufficiently small scope, and then forward control to the JSP for display).

The basic concept is your JSP should be display only. There is the ability to write Java code in JSP, but it is usually a bad idea. You use Servlets for control - servlets are like normal Java objects with methods for getting requests from web clients. The servlet can better handle the type of Java code you have (and error reporting), then when it is done call a JSP for displaying results. Even better than that might be a plain old java object (sometimes called POJO) which handles all the work, the Servlet creates it and passes into the JSP (assuming it would have 'get' methods for the parts that need to display in JSP). The benefit of this is you could test it in a local environment where error reporting is easier to understand than a web application. You can then use it in the JEE environment when you know it works. It also makes your JSP much simpler and easier to read (and better able to take advantage of JSTL tags and EL which you should eventually read about).

I suggest doing a lot more reading. Start here: The Java EE Tutorial but getting a book on Java EE and reading it thoroughly is another good idea.
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think the problem is in the JSP - it's in the way you call your command. You should definitely read When Runtime.exec() won't. That call to waitFor() is probably hanging because the process' output buffer is full.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic