Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

ServletConfig config object to Servlet's init() method

Thread view: 
crack_cs - 16 Mar 2006 10:53 GMT
Hi,
       I would like to know the use of the 'config' object passed to
the init() method of the Servlet.Can any one mail me the example that
signifies the importance of that 'config' object.
Further, If i'm not wrong the init() method is invoked by the servlet
container ..... can we have program in C/Java to intercept the calls
made by the container to invoke init() method so that I
can understand what object is passed to the init() method.

Thanks in advance
Thomas Fritsch - 16 Mar 2006 11:36 GMT
>         I would like to know the use of the 'config' object passed to
> the init() method of the Servlet.Can any one mail me the example that
> signifies the importance of that 'config' object.
It is described in the API doc of Servlet#init and of ServletConfig at
<http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/Servlet.html#init(ja
vax.servlet.ServletConfig
)>
<http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletConfig.html>

> Further, If i'm not wrong the init() method is invoked by the servlet
> container .....
Yes, you are right.

> can we have program in C/Java to intercept the calls
> made by the container to invoke init() method so that I
> can understand what object is passed to the init() method.
Yes, by implementing a method like the following in your servlet:
  public void init(ServletConfig config) {
    super.init(config);
    //... do anything you like, for example:
    System.out.println("init was called");
    config.getServletContext().log("init was called");
  }

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

crack_cs - 16 Mar 2006 11:59 GMT
1. The API doc ,I had read already
2. regarding the method by you ......  I had referred that one too
previously.

   but my question is I want to know  can we have program in C/JAVA
that intercepts the call made by the container to the init().... so
that I can get the structure of the object that is passed to the init()
method..... we cannot get it directly bcoz ServletConfig is an
interface and has only limited objects and methods.... did you get my
point ?

Thanks and Regards,
Dhairyashil Padalkar
Thomas Fritsch - 16 Mar 2006 13:29 GMT
> 2. regarding the method by you ......  I had referred that one too
> previously.
[quoted text clipped - 5 lines]
> interface and has only limited objects and methods.... did you get my
> point ?
Not yet. I have more questions than answers.

Do you want to intercept the calls made by the container
(1) to init() of *your* servlet only, or
(2) to init() of *all* servlets in the container?

If (1), the technique by overriding your Servlet#init method may
suffice. You can get all init parameters (key=value) with the methods
provided by ServletConfig. You can get further parameters via
getServletContext() and the ServletContext interface.
If (2), there may be some logging options to turn on in your container,
or there may be no way. You have to look up the docs of your special
container (Tomcat or whatever you have).
Or look into the container's source code. Consider running the container
in a debugger, set a breakpoint at init(), and look into the actual
ServletConfig object.

Why do you want to know the internal structure of the ServletConfig
object? What is the goal behind your question?
Your goal contradicts the design goals of the servlet API. ServletConfig
is an interface (i.e. with limited methods), just *because* all
implementation details of the servlet container are hidden behind that
interface.

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

crack_cs - 17 Mar 2006 05:48 GMT
Yes I want to about (2)... yes it surely violates the design goals of
the Servlet API but it's just for fun.I'm the kinda guy who want take a
deep dip understanding the overall working inside out..I know it's not
possible but trying to know as much as possible.

1. Is Tomcat Source code available for free ?
2. How to run the container in a debugger mode ..... I'm new to
JAVA/J2EE  .... I'll surely make an effort to know about it....
   but   if u could spare some time to tell me about that I'll be
grateful to u.

Thanks and Regards,
Dhairyashil  Padalkar
Thomas Fritsch - 17 Mar 2006 11:49 GMT
> Yes I want to about (2)... yes it surely violates the design goals of
> the Servlet API but it's just for fun.I'm the kinda guy who want take a
> deep dip understanding the overall working inside out..I know it's not
> possible but trying to know as much as possible.
>
> 1. Is Tomcat Source code available for free ?
Yes, Tomcat is open-source. You can download the sources from
http://tomcat.apache.org/

> 2. How to run the container in a debugger mode ..... I'm new to
> JAVA/J2EE  .... I'll surely make an effort to know about it....
>     but   if u could spare some time to tell me about that I'll be
> grateful to u.
I recommend you familiarize yourself with remote debugging.

You can start Tomcat (like any other Java application) with a bunch of
cryptic start options
   java -Xdebug -Xnoagent -Djava.compiler=NONE
      -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=12345 ...
so that it later will accept connections (on port 12345) from a Java
debugger. Look up the docu of the "java" and/or "jdb" executables.
Then you can attach a debugger to this already running Java process. All
modern IDE's support this 'remote debugging'. Just look up your IDE's
docu and start experimenting (may be first with a simpler application
instead of with Tomcat).
I'm sure you'll get much enlightening about what is going on under the hood.

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.