Link to home
Start Free TrialLog in
Avatar of aauser
aauser

asked on

call java program from a servlet

Hi,
   I am trying to learn how to call a java program from a servlet.
I have a file in unix /tmp/names which contains all the name.


I have one html file which ask for a name as input  and then call the servlet.
The servlet basically has the name variable.  How can I call
another java class to check to see if this name is in the file /tmp/names?


thanks in advance.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Same way you'd call another class from an application. Create an instance and call it's method.
If you've got read perms on the file, just open it from the servlet, iterate it, and look for the name
If you've got read perms on the file, just open it from the servlet, iterate it, and look for the name
Avatar of aauser
aauser

ASKER

thanks.
says I have a class call output1:
public class output1 {
     public void output() {
         System.out.println ("The name is ");
}
}



In my servlet, I have line like this:
output1 out = new output1();
out.output();


and when I ran the servlet, I don't see anything on the browser.

stdout does not go to the browser.
You need to write to the output stream of the servlet response for it to be sent to the browser:

PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream()));
out.println("The name is");
ASKER CERTIFIED SOLUTION
Avatar of vishalbhando
vishalbhando

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