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.


lesaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ravindra76Commented:

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  {

   callSingleStudent(type);
}
 

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

Eg:

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

 if( condition1)
   callMethod1();
else if (condition2)
  callMethod2();
else if ( condition3)
  callMethod3();
.......

else if ( conditionN)
  callMethodN();

All your code will ne in respective callMethods.

Try with this,

Best of luck.





0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ravindra76Commented:
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
0
lesaAuthor Commented:
I want to do it by object serialization. Can yu tell me in that way
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Ravindra76Commented:
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.





0
mbormannCommented:
>>>>>>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
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10199404 
for reference

as to the second one Use the Utility class HttpMessage by which u can POST over 1Mb of data ,download it at
http://www.servlets.com/resources/com.oreilly.servlet/index.html
it's documentation is at
http://www.servlets.com/resources/com.oreilly.servlet/HttpMessage.html

also dwonload the book's examples at
http://www.servlets.com/jsp/examples/index.html
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.
0
mbormannCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.