Solved

Calling java servlet

Posted on 2001-08-15
8
258 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
Stressed Out?

Watch some penguins on the livecam!

 
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 100 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

728 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