Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-18-2008, 10:08 PM
Member
 
Join Date: Apr 2008
Posts: 1
pooja.gupta84 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-21-2008, 07:54 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
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.



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

Quote:
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-13-2008, 03:18 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 145
Nicholas Jordan is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-24-2008, 04:24 PM
Member
 
Join Date: Jun 2008
Posts: 3
chilljava is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-24-2008, 07:32 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 145
Nicholas Jordan is on a distinguished road
small footprint development server
I have a small footprint server running, it says:
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Design Patterns - Basics (II) JavaForums Java Blogs 0 02-09-2008 11:26 PM
Design Patterns - Basics (I) JavaForums Java Blogs 0 02-09-2008 11:26 PM
regading jsp basics lpwing JavaServer Pages (JSP) and JSTL 0 01-21-2008 08:52 AM
Session Beans (basics) Java Tip Java Tips 0 12-28-2007 11:43 AM
Multithreading (basics) JavaForums Java Blogs 0 12-17-2007 01:21 PM


All times are GMT +3. The time now is 07:51 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org