This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes JSP invoked java and java did its part. But no output from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JSP invoked java and java did its part. But no output from JSP" Watch "JSP invoked java and java did its part. But no output from JSP" New topic
Author

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

ravi san
Greenhorn

Joined: Jul 27, 2012
Posts: 5


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

Joined: Mar 28, 2012
Posts: 860

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

Joined: Jul 27, 2012
Posts: 5

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

Joined: Jan 28, 2003
Posts: 4165
    
  21

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.


Steve
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP invoked java and java did its part. But no output from JSP
 
Similar Threads
String Tokenizer
java io question, conceptual query
IO Question from javacaps
Problem while Reading File
Runtime.exec() doubt, please help me...........