?
Solved

call java program from a servlet

Posted on 2003-11-14
6
Medium Priority
?
901 Views
Last Modified: 2013-11-24
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.
0
Comment
Question by:aauser
[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
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9752033
Same way you'd call another class from an application. Create an instance and call it's method.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9752066
If you've got read perms on the file, just open it from the servlet, iterate it, and look for the name
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9752085
If you've got read perms on the file, just open it from the servlet, iterate it, and look for the name
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!

 

Author Comment

by:aauser
ID: 9752213
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.

0
 
LVL 92

Expert Comment

by:objects
ID: 9752692
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");
0
 
LVL 1

Accepted Solution

by:
vishalbhando earned 500 total points
ID: 9753143
You can send out variable from your servlet / jsp to the Class as :
... class output1{
          public void output(){
                output(System.out);
          }
          public void output(PrintStream out){
                output(new PrintWriter(out));
          }
          public void output(PrintWriter out){
                 if(out==null) throw new IllegalArgumentException("out can't be null");
                 out.println(...);
          }

         p s v main(String args[]){
                output1 op=new output1();
                op.output();
         }
}

in servlet call as
output1 op=new output1();
op.output(response.getOutputStream());
0

Featured Post

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.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

650 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