?
Solved

Calling java servlet

Posted on 2001-08-15
8
Medium Priority
?
263 Views
Last Modified: 2013-11-24
Hi,

   Could you please tell me  is there any way to call java servlet from a non-browser (without http protocol) client ??

I mean without using web browser,is there anyway to call java servlet ?

Baskar
0
Comment
Question by:abas
[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
8 Comments
 
LVL 15

Expert Comment

by:a.marsh
ID: 6387814
Yes - servletrunner - it comes with the JSDK - you can run it from your local machine.

Check out:

http://www.devdaily.com/java/edu/pj/pj010025/

http://rts.ncst.ernet.in/resources/java/tutorial/servlets/servletrunner/

:o)

Ant
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6387817
Sorry - I misread your question - I thought you were referring to a server not browser. :oP

It is possible to "run" a servlet from the command line - you just use the main method as you would a normal java program, and then do whatever you need to do to test the servlet.

Ant
0
 
LVL 6

Expert Comment

by:kotan
ID: 6388168
You can add this to your main program to test servlet.

URL url = new URL("http://servlet");
URLConnection urlConn = url.openConnection();

0
Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

 
LVL 1

Expert Comment

by:biged040597
ID: 6388972
you can telnet to port 80 ,
assuming your webserver is running on myhost.mydomain.com:80
and your servlet is /servlet/HelloWorld

then try

telnet myhost.mydomain.com 80
GET /servlet/HelloWorld HTTP/1.1
[ENTER]
[ENTER]

0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6391638
As for telnet, don't get confused when you type you don't see anything, because the webserver doesn't do character echo. Just type blindly the command "GET /servlet/HelloWorld HTTP/1.1" and hit enter
twice. Then telnet shows you the response in raw data.
0
 

Accepted Solution

by:
harshita earned 200 total points
ID: 6420262
Hi please llook at my code. It tells you how to call servlet without using browser.

import java.net.*;
import java.util.*;
import java.io.*;

public class Hello {
    public static void main(String args[]) {

        ObjectInputStream is;
        URL url;
        String  uri =
          "http://3.131.202.109/servlet/HelloServlet";
        HashMap hash = new HashMap();    
        try {
            //calling the servlet by passing params
            url = new URL("http://3.131.202.109/provence/servlet/HelloServlet?name=MyName&age=25");
           
            // open input stream and read the hashmap
            // returned by the servlet
           
            is = new ObjectInputStream(url.openStream());
            hash = (HashMap) is.readObject();
           
            // print it out
            System.out.println(hash);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }
}

Hope this answers your question.


Thanks & Regards,
Murthy
A.Murthy@gecapital.com
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6421045
From my book "core Servlets and JavaServer Pages" the author presented a web client to test servlets and JSPs without using a browser.

Just go to the link and look for "WebClient.java". This class needs some more helper classes.

WebClient opens a window, lets you submit a request with all headers and shows you the response with all headers. Very impressive!

http://archive.coreservlets.com/Chapter2.html

There is the contrary example, too: The EchoServer. This is a small utility to test what gets sended to a server when you submit a form or the like.

Cheers!
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6512054
Why did you give harshita a low grade C? This is not fair.
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month13 days, 3 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