Link to home
Start Free TrialLog in
Avatar of myrizvi
myrizvi

asked on

JSP script giving blank output on HPUX

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.
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

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...
do you have the correct permissions and are you in the correct shell?
Avatar of myrizvi
myrizvi

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or, upgrading to java 1.4 will get you the "replaceAll" function ;-)
Avatar of myrizvi

ASKER

YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOO !!!!!!

Its done man :)

Many many thanks to TimYates.
Yay!

Good luck with it!!

Tim