?
Solved

call java program from a servlet

Posted on 2003-11-14
6
Medium Priority
?
900 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

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.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

777 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