Invoking a servlet function through an applet

I am calling servlet in an applet. My servlet has several functions like getallstudents which returns vector of stundent objects and getstudent which returns detailed information of specific student. I am doing this with object serialization.

My doubt is is there any way in which I call the specific function in a servlet using HTTP with out using RMI or CORBA.

I am handing the request through dopost method if the servelt performs a single task I know I can handle it right away. But I want to know whether I have to write two servlets or I can make use of the same servlet with different functions to do the job.

Lot of thanks well in advance.

Who is Participating?
Ravindra76Connect With a Mentor Commented:

Hi lesa,

   You can do indirectly.

  Now You are calling from applet to servlet.

 Make use of parameters.

Eg:1. All students. type=all
    2.Specific student type=sno (i.e some number )

If you are using get method,

you have to do like that

URLConnection conn = new URL("http://yoursrver:yourport/servlet/yourservlet?type=All").openConnection();

The service method will contain following in your servlet code.

 String type = req.getParameter('type");

if ( type.equalsIgnoreCase("all")) {

  callAllStudentsMethod();//Your actual method

} else  {


Generally, in this type of cases, service won't contain any code except polling.


 String type = req.getParameter("type");

 if( condition1)
else if (condition2)
else if ( condition3)

else if ( conditionN)

All your code will ne in respective callMethods.

Try with this,

Best of luck.

Hi lesa,

 In case of post methods, use this tag.

Eg: 1.<input type=hidden name=type value=all>

     2.<input type=hidden name=type value=one>

 This will be fine for calling from HTML forms. Previous method will also fine,

 In case of applets, it is better to append this type because it is not a security threat.

Best of luck
lesaAuthor Commented:
I want to do it by object serialization. Can yu tell me in that way
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Hi lesa,

 Currently how are you communicating with server from applets?
With objets or without objects?.

If You are passing objects from applet to servlet, simply add a field type in that object.

I think you know applet to server communication through objects as you stated in your question.

Orially series covered passage of objects from applet to server and vice versa. I never practised with objets. I just used parameters.

>>>>>>is there any way in which I call the specific function in a servlet               using HTTP with out using RMI or CORBA.

then a little later

>>>>> i want to do it by object serialization. Can yu tell me in that way

Note u can have both in one servlet.

the thing is that ravindra76 has told it correctly if u want to use it using Pure HTTP,but a little caution is in order as some Web Servers limit the Request URL to 256 bytes only and u will have to manually encode  the characters
' '(space), '#' (hash) ,'%'(per cent)etc ...
please see 
for reference

as to the second one Use the Utility class HttpMessage by which u can POST over 1Mb of data ,download it at
it's documentation is at

also dwonload the book's examples at
search for jservlet.jar

hope this helps u .
Remember that the Object based communication is present in JDK1.1.* and up,so u detect 'java-version' of ur browser and accordingly do the communication.
for pure HTTP i tested the request URL String for 2KB of data but it's not good to rely on that else the web server will throw a status code with something like Request too long
All Courses

From novice to tech pro — start learning today.