?
Solved

JSP script giving blank output on HPUX

Posted on 2005-03-30
7
Medium Priority
?
245 Views
Last Modified: 2010-04-01
Hi experts,

The follow code is generating a blank page while running from hp-ux (tomcat installed) :

--------------------------------------- CODE START ---------------------------------------------------------------

<%@ page language="java" import="java.io.*, java.util.*, java.lang.*" %>
<p>Testing Page</p>

<%
StringBuffer sb = new StringBuffer();

try
{
  String cmd = "ls";

  System.out.println ("Starting the process");
  Runtime runTime = Runtime.getRuntime();
  Process process = runTime.exec(cmd);
  InputStream inputStream = process.getInputStream();
  InputStreamReader   inputStreamReader = new InputStreamReader (inputStream);
  BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
  String line = null;
  while ( (line = bufferedReader.readLine()) != null ){
        sb.append(line); sb.append("\n");
  }
  System.out.println("Output : " + sb.toString());
  int exitVal = process.waitFor();
  System.out.println ("Process exitValue:  " + exitVal );
}catch (Throwable t)
{
  t.printStackTrace();
}

%>

----------------------------------------------------- CODE END --------------------------------------------------

----------------------------------------------------- OUTPUT START --------------------------------------------

Testing Page

------------------------------------------------------ OUTPUT END -----------------------------------------------


Any help?

Thanks in advance.
0
Comment
Question by:myrizvi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 13662638
Is it printing the output into the log files?

You don't send anything to the screen...

    System.out.println("Output : " + sb.toString());

should probably be:

    out.println( "Output : " + sb.toString().replaceAll( "\\n", "<br>" ) );

That *might* work...

You might need to read the inputstream in a seperate thread...

Step 1:  Look in catalina.out for either output, or an exception...
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13662643
do you have the correct permissions and are you in the correct shell?
0
 

Author Comment

by:myrizvi
ID: 13662855
Hi TimYates,

Yes the output was going to  CATALINA.OUT  file.

After putting  this :

out.println( "Output : " + sb.toString() )  

Output is appearing on the webpage without newline, but with this :

out.println( "Output : " + sb.toString().replaceAll( "\\n", "<br>" ) )

Following ERROR appearing :

---------------------------------------------- ERROR OUTPUT START ------------------------------------------

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occured between lines: 4 and 31 in the jsp file: /test1.jsp

Generated servlet error:
/sasgsmapp/sasgsm/mds/sas/ui/work/localhost/sas5/test1$jsp.java:80: Method replaceAll(java.lang.String, java.lang.String) not found in class java.lang.String.
                  out.println( "Output : " + sb.toString().replaceAll("\n","<br>"));
                                                                     ^
1 error

----------------------------------------------------------- END -------------------------------------------------------------

Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Accepted Solution

by:
TimYates earned 1000 total points
ID: 13662891
right...so you are using java 1.3?

try this:

  System.out.println( "Output :<br><pre>\n" + sb.toString() + "</pre>" );
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13662897
Or, upgrading to java 1.4 will get you the "replaceAll" function ;-)
0
 

Author Comment

by:myrizvi
ID: 13662972
YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOO !!!!!!

Its done man :)

Many many thanks to TimYates.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13663038
Yay!

Good luck with it!!

Tim
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question