Results 1 to 5 of 5
Thread: Doubt in basics of Servlets
- 04-18-2008, 09:08 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 1
- Rep Power
- 0
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
- 04-21-2008, 06:54 AM #2
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.
It is not returning an object....it is returning an Object reference variable only.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?
JBoss, WEblogic, WebSphear...and many others just do googling.3. which other web servers apart from the apache tomcat does servlet support? Can servlets be run on iis, pws or any other server?
If any doubt please feel free to ask.
sanjeev
- 06-13-2008, 02:18 PM #3
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.
- 06-24-2008, 03:24 PM #4
Member
- Join Date
- Jun 2008
- Posts
- 3
- Rep Power
- 0
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.
- 06-24-2008, 06:32 PM #5
small footprint development server
I have a small footprint server running, it says:
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.Java Code:JSDK WebServer Version 2.1 Loaded configuration from file:C:\jsdk2.1/default.cfg endpoint created: :8080
RE:
Similar Threads
-
regading jsp basics
By lpwing in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 01-21-2008, 07:52 AM -
Session Beans (basics)
By Java Tip in forum Java TipReplies: 0Last Post: 12-28-2007, 10:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks