mentby.com
Blog | Jobs | Help | Signup | Login

(newbie question) missing classs file?



Hi,

I am new to tomcat and jsp.  I appologize in advance my lack of knowledge,
but I would appreciate some poninters.

I am running tomcat 6.0.14 on redhat linux.

After reading a few pages of documentation, I tried:  http://localhost:8080/sample

It rendered what's in $CATALINA_HOME/webapps/sample/index.html,
which included 2 hyperlinks: "JSP page" and "servlet".  Both
links worked fine.

Then I found a file $CATALINA_HOME/webapps/sample/WEB-INF/classes/mypackage/Hello.class.
I removed this class file and hit the same url as before ( http://localhost:8080/sample ),
and each of the "JSP page" and "servlet", expecting the error from tomcat.

To my amazement, they both worked.

Question number 1: Where is the executable class file?

Then I went on to modify hello.jsp in $CATALINA_HOME/webapps/sample directory.
I added extra string "Hello!" to what used to be:
<%= new String("Hello!") %>

Tomcat gave me what I expected: double Hello's.
I thought it might have generated a class file.  But there is no class file
anywhere under $CATALINA_HOME/webapps/sample directory?

Question number 2: Why does this work?

Thank you in advance.

Regards,

Tena Sakai
tsakai*******


Tena Sakai Tue, 18 Aug 2009 11:49:15 -0700

Are you reloading the pages from the server with the shift key?

The pages might be locally cached from your browser.

Dan


Daniele Development-ML Tue, 18 Aug 2009 11:51:45 -0700

Hi Dan,

Shift or no shift, it makes no difference.
I told my browser to dump the cache then hit pages again.
No difference.

I doubt this is a cache issue.  If that's the case, why does
it reflect my hack (double "Hello!") and no class file?

I am confused.

Tena


Tena Sakai Tue, 18 Aug 2009 12:04:39 -0700

Consider also that once the application is loaded is memory, even if you
cancel the classes, the application still works.
I doubt that the JVM maintains in memory all the classes, all the times, but
if your current usage of the heap is not ridiculous big, probably your class
remains loaded.

Dan


Daniele Development-ML Tue, 18 Aug 2009 12:14:22 -0700

Hi Dan,

It still doesn't explain why double "Hello!" works, though.

That aside, can you tell me how I can clear what's in the heap?

Tena


Tena Sakai Tue, 18 Aug 2009 12:31:46 -0700

I believe once a servlet is initialized in memory, it stays in and is
re-used over and over.  After removing the class, you'd have to reload
the webapp to make the change show.

--David


David Smith Tue, 18 Aug 2009 12:32:18 -0700

Hi David,

Would you mind telling me how I would do that?

I just restarted tomcat and hit the same pages.
No changes.  I mean it shows double "Hello!" and
I see no class file generated anywhere under
$CATALINA_HOME/webapps/sample directory.

Tena


Tena Sakai Tue, 18 Aug 2009 12:40:33 -0700

did you look at
$TOMCAT_HOME/work/Catalina/localhost/WEBAPPNAME/org/apache/jsp/
JSPNAME_jsp.java
JSPNAME_jsp.class

Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.


Martin Gainty Tue, 18 Aug 2009 13:04:52 -0700

Yeeeha!  That is it!

Thank you, Martin Gainty.

Being a newbie, I had no idea such "deep secret" existed.
Since the distribution contained a directory:
  $CATALINA_HOME/webapps/sample/WEB-INF/classes
with a class file, I was completely blinded to look elsewhere.

Regards,

Tena Sakai
tsakai*******


Tena Sakai Tue, 18 Aug 2009 13:20:20 -0700

It's not a deep secret.  Look at the JSP doc: http://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html

and at conf/web.xml for the JSP servlet parameters.  Note especially the dfault for the scratchdir parameter.

Note that that is mypackage.Hello, not anything associated with a JSP.  Lok in the servlet mappings in webapps/sample/WEB-INF/web.xml to see how to nvoke the mypackage.Hello servlet.

- Chuck

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MTERIAL and is thus for use only by the intended recipient. If you receivedthis in error, please contact the sender and delete the e-mail and its attchments from all computers.


Charles R Caldarale Tue, 18 Aug 2009 21:36:29 -0700

The Tomcat manager app is the easiest way.

When I delete the webapps/sample/WEB-INF/classes/mypackage/Hello.class fil and restart Tomcat, any attempt to reference the servlet example fails wih a 404 (as expected).

- Chuck

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MTERIAL and is thus for use only by the intended recipient. If you receivedthis in error, please contact the sender and delete the e-mail and its attchments from all computers.


Charles R Caldarale Tue, 18 Aug 2009 21:40:38 -0700

You can't, other than by restarting the JVM.  As long as there's a referene to an object, it will stay in the heap.  You can stop and undeploy the wbapp, which will remove all of Tomcat's references to the webapp classes.

- Chuck

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MTERIAL and is thus for use only by the intended recipient. If you receivedthis in error, please contact the sender and delete the e-mail and its attchments from all computers.


Charles R Caldarale Tue, 18 Aug 2009 21:47:26 -0700

Once referenced, a servlet, listener, filter, valve, or realm class will rmain loaded until the webapp is undeployed or Tomcat is restarted.  Any clsses referenced by those will also remain loaded.  The same is true for JS-generated classes, with the exception that they can be replaced on the fl by new versions.

- Chuck

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MTERIAL and is thus for use only by the intended recipient. If you receivedthis in error, please contact the sender and delete the e-mail and its attchments from all computers.


Charles R Caldarale Tue, 18 Aug 2009 21:51:34 -0700

Hi Chuck,

Thanks for your note, I think I understand.

I preface the remark below once again, with "being a newbie":

I hadn't gotten around to read everything I should have, but
I was getting confused by the fact that a class file was in
$CATALINA_HOME/webapps/sample/WEB-INF/classes directory and
after my removing it and modifying the source, it didn't
appear in the same directory (nor anywhere under $CATALINA_HOME/webapps)
and yet my modification was reflected in the output page.

What I understood empirically is that there is no need for
a class file in $CATALINA_HOME/webapps/sample/WEB-INF/classes
directory.  If so, why should the distribution come with it?
If it hadn't, it would've been less confusing and I would have
avoided my poor expression "deep secret."

Regards,

Tena Sakai


Tena Sakai Tue, 18 Aug 2009 22:37:59 -0700

Hi Chuck,

Perhaps, but that was beyond what a newbie meager brain could comprehend.

You know, that's what I expected as well, but it kept working.
That's why I asked the question to begin with.  A fascinating
truth is that I can execute the sample jsp (Hello.class), as
I just did again, and there is no file in webapps/sample/WEB-INF/classes/mypackage
directory.  None whatsoever.  There is, however, hello_jsp.class
in $CATALINA_HOME/work/Catalina/localhost/sample/org/apache/jsp,
as was pointed out by Mr Martin Gainty, with the correct timestamp.

That makes me think maybe what you are claiming is happening
with a different version of tomcat?  As I mentioned, mine is
6.0.14.  What's yours?

Regards,

Tena Sakai


Tena Sakai Tue, 18 Aug 2009 22:54:34 -0700

That class file is for the servlet side of the sample app.


Because your modification was to the JSP part, which is independent of theservlet part.

True for the JSP part of that sample webapp.

As previously stated, it's for the servlet part.

You should read the servlet spec to get an idea of the structure of a webap: http://jcp.org/aboutJava/communityprocess/mrel/jsr154/index2[..]

JSPs are an add-on to the servlet spec, and they're covered by their own sec: http://jcp.org/aboutJava/communityprocess/final/jsr245/index[..]

Since the above are specs, the topics are not included in the Tomcat doc.

- Chuck

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MTERIAL and is thus for use only by the intended recipient. If you receivedthis in error, please contact the sender and delete the e-mail and its attchments from all computers.


Charles R Caldarale Wed, 19 Aug 2009 05:54:52 -0700

Because the class had already been loaded into the JVM and you had not resarted Tomcat.

Nor should there be, since that directory is reserved for servlets and ther supporting classes and the spec requires that Tomcat treat it as read-ony.  Classes generated from JSPs cannot be written there.

I'm using 6.0.20 (no point in wasting time on a superseded version), but te level is not a factor here.

- Chuck

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MTERIAL and is thus for use only by the intended recipient. If you receivedthis in error, please contact the sender and delete the e-mail and its attchments from all computers.


Charles R Caldarale Wed, 19 Aug 2009 05:59:35 -0700



Post a Comment