Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

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.
0
myrizvi
Asked:
myrizvi
  • 4
  • 2
1 Solution
 
TimYatesCommented:
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
 
bloodredsunCommented:
do you have the correct permissions and are you in the correct shell?
0
 
myrizviAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
TimYatesCommented:
right...so you are using java 1.3?

try this:

  System.out.println( "Output :<br><pre>\n" + sb.toString() + "</pre>" );
0
 
TimYatesCommented:
Or, upgrading to java 1.4 will get you the "replaceAll" function ;-)
0
 
myrizviAuthor Commented:
YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOO !!!!!!

Its done man :)

Many many thanks to TimYates.
0
 
TimYatesCommented:
Yay!

Good luck with it!!

Tim
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now