?
Solved

Servlet Reloading in Java Web Server

Posted on 2000-01-28
5
Medium Priority
?
227 Views
Last Modified: 2013-11-24
Hi,

I am using Java Web Server - NT 4.0, i have placed my servlet under the
Web server root/classes directory, but when ever i do changes in my servlet, it is not reloading automatically, but if i try to stop and start the web server service, it is ok.

How do i achieve the servlet reloading without restarting the web server.
Any way ?, please help me!

Thanks,
G Ramesh
0
Comment
Question by:rameshg21
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2405101

Hi Ramesh,

 It is better to put servlets not reloadable.


Automatical reloading will cause some side effects in some cases.

Cureently what u are doing is correct.

BTW  can u grade my applet answer??
0
 
LVL 5

Accepted Solution

by:
mbormann earned 150 total points
ID: 2412701
>>>>>but when ever i do changes in my servlet, it is not reloading automatically, but if i try to stop and start the web server service, it is ok.

If you want the servlet to be reloaded every time you change the class files ,place it in

server_root/servlets directory.

What you r doing right now is highly desirable ,dont change the configuration when u r ready to deploy the servlet ,pasting from one of the PAQ's over here

'ClassCastException  in the servlet'
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10255641 

this problem has been detailed in the Jason Hunter's excellent book see Pgs
55 & Pgs 339

I will type some text from there.Pg 55

Servlet reloading may appear to be a simple feature ,but its actually quite a hack. ClassLoader objects are designed to load a class just once.

To get around this limitation and load servlets again & again ,servers use Custom class loaders that load servlets from the default servlets directory.
This explains why the servlet classes are found in the server_root/servlets ,even though that directory doesnt appear in the server's classpath.

Servlet reloading is NOT performed for classes found in the server's classpath(such as server_root/classes) coz those classes are loaded by the core,primordial class loader. These classes are loaded once and retained in memory even when their class files changes.

It is generally good to put servlet support classes soemwhere in classpath of web server where they dont get reloaded.More explanation .....

This moving of servlets to classpath improves performance a bit,since the server does not need to check the class files timestamp to decide whether to reload the class file.

Pg 339
A server uses a new ClassLoader each time it reloads a servlet. This has the interesting side effect that when the YourServlet class is reloaded ,it is actually a different version of YourServlet than the version used by other classes.Thus although the returned class type is YourServlet and it's being cast to YourServlet ,the cast is between differeing types(from 2 different classloader objects) and the cast HAS to throw the dreaded ClassCastException.

The same type mismatch can occur if the class performing the cast (that is the servlet performing the above code) is reloaded. Why? because the new ClassLoader wont find YourServlet using the primordial Class loader and will load it's own copy of YourServlet.
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2413181

Hi Amit:-


Is the book is in readable format on net like you are telling???

I found only the code part in net in www.servlets.com

I want the book on online like the real book.

Is it there ??
0
 
LVL 5

Expert Comment

by:mbormann
ID: 2413342
no it's not,I have the book here at our place ,and I read and typed the above thing myself.

:-)
0
 

Author Comment

by:rameshg21
ID: 2432701

Thanks, i really like the people who spends their time for me!

Thanks a lot to mbormann, and ravindra

Regards,
G Ramesh
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A solution for Fortify Path Manipulation.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month5 days, 12 hours left to enroll

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question