Results 1 to 5 of 5
  1. #1
    pooja.gupta84 is offline Member
    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0

    Post Doubt in basics of Servlets

    Hello all,

    I am new to servlets but have good knowledge of the basics of Java.
    I have a couple of questions..

    1. the service() method of the GenericServlet class accepts 2 parameters...one is of the ServletRequest and the other is of the type ServletResponse. My question is that ServletRequest and ServletResponse are interfaces in the javax.servlet package. How can you create an object of its type? Interfaces cant have objects...only classes can..right?

    2. can a method return an object of type interface?
    A method of the Servlet interface - getServletConfig returns an object of type interface :
    ServletConfig getServletConfig()
    How is this possible?

    3. which other web servers apart from the apache tomcat does servlet support? Can servlets be run on iis, pws or any other server?


    Thanks in advance to anyone who answers

    Regards
    Pooja Gupta

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Quote Originally Posted by pooja.gupta84 View Post
    1. the service() method of the GenericServlet class accepts 2 parameters...one is of the ServletRequest and the other is of the type ServletResponse. My question is that ServletRequest and ServletResponse are interfaces in the javax.servlet package. How can you create an object of its type? Interfaces cant have objects...only classes can..right?
    In This case there is no creation of objects, just creating the reference variable of interface type. In Java we use "new" operator to create objects. ServletRequest request; is only creating reference variable. and it can be done with no problem. You can do it at your own classes.

    And one more thing : Why you can not create objects of Interface : Because interfaces are public abstract by default and you can not instantiate an abstract thing in Java. But you can make an Reference variable of abstract thing.

    Reference Variable and Making Object are two different thing in Java.

    for e.g.

    TestClass tc; // Creating Reference Variable that stores the reference only

    tc = new TestClass(); // Creating objects.



    2. can a method return an object of type interface?
    A method of the Servlet interface - getServletConfig returns an object of type interface :
    ServletConfig getServletConfig()
    How is this possible?
    It is not returning an object....it is returning an Object reference variable only.

    3. which other web servers apart from the apache tomcat does servlet support? Can servlets be run on iis, pws or any other server?
    JBoss, WEblogic, WebSphear...and many others just do googling.

    If any doubt please feel free to ask.


    sanjeev

  3. #3
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    As sanjeevtarar directs. In the ServletResponse / ServletRequest method, we just code as though we were in a class. How we can code List l = new ArrayList(); and have an interface hold the return from new is something I have not figured out. Code an interface that has a method, write a class that implements that method and assign the return from new to the interface you wrote yourself.

    See what happens. I may do the same myself.

  4. #4
    chilljava is offline Member
    Join Date
    Jun 2008
    Posts
    3
    Rep Power
    0

    Default

    HttpServletRequest myServletReq = new myHttpServletRequest();
    create a class with name myHttpServletRequest implements HttpServletRequest, and implement its methods.

    yes there are many other softwares where you can run servlet, there are few light weight containers which will just run your servlet. try jetty server, or winstone server.

  5. #5
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default small footprint development server

    I have a small footprint server running, it says:
    Java Code:
    JSDK WebServer Version 2.1
    Loaded configuration from file:C:\jsdk2.1/default.cfg
    endpoint created: :8080
    I got it somewhere on the Sun server digging around in Servlets looking for a small footprint development server. I forgot where I put it, it is so unobtrusive.

    RE:

    Quote Originally Posted by chilljava View Post
    (...snip...)yes there are many other softwares where you can run servlet, there are few light weight containers which will just run your servlet. try jetty server, or winstone server.

Similar Threads

  1. regading jsp basics
    By lpwing in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-21-2008, 08:52 AM
  2. Session Beans (basics)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-28-2007, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •