aspose file tools*
The moose likes Servlets and the fly likes Client/Server communication while JSP execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Client/Server communication while JSP execution" Watch "Client/Server communication while JSP execution" New topic
Author

Client/Server communication while JSP execution

Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi,
Wanted more insight on the subject.
Consider a situation, where you open a DB connection, in the JSP.
This JSP page also has code to destroy the connection instance that it creates.
The user has requested for this JSP page.Assume that the connection over the network is pretty slow.The user gets frustrated and hits the stop button.We see that the JSP page stops loading.What I am curious to know about is what happens to the Connection (and other objects!!) that we create/intialize in that page!!
It would be helpful, if you could answer my following queries:

  1. Does the jsp page (servlet) finish processing the _jspservice method?
  2. Does the compiled JSP/Servlet destroy itself or will the destroy() be called immediately?
  3. Is the memory used from the page released?
  4. Will the page halt like it does, when a <jsp:forward> tag is encountered?

  5. Thanks in advance,
    ------------------
    Sandeep Desai
    vgdesai@bom3.vsnl.net.in

    1. Sun Certified Java Programmer Scored 93 per cent
    2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
    3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
    4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
Remember that HTTP is a request/response protocol. The user (web browser) submits a request, and the server (JSP container) reads the request, calls a servlet (your compiled JSP) to handle the request, and pipes the output back to the client. Your JSP is unaware that the client has disconnected until it tries to write the response. Also recall that a servlet (or JSP) does not shut down after a request is processed; it remains in memory read to accept more requests. You need to handle the database connection yourself.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
Website: http://www.philhanna.com


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
In other words, if you close connections in the destroy() method of jsp, it wont be closed until the JSP is destroyed. ie the JSP will be in memory to service hundreds of hits and then when it finally gets destroyed by the server, the destroy() is called. Not after every request.
Laojar Chuger
Ranch Hand

Joined: Dec 20, 2000
Posts: 111
It really has nothing to do with JSP process. As long as a request is issued, the engine will start to process the request. What you hit on the stop button in browser just mean that the browser will not take the response from the server no matter if the response is issued or not. To the server once the request is received, no difference will make if the browser do not take the response.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
To add my little bit... the user pressing STOP on the client will break the HTTP connection. Your JSP will notice this when it is outputting HTML and the JspWriter object attempts to flush its buffer. An IOException will be thrown, and if you are not closing the connection in a finally clause, the connection will remain open until finalized (Bad Thing).
- Peter
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi all,
Thanks for the responses.
I guess, from your replies that the Container handles each client as a separate Thread (It may not be exactly like that, as it is going to depend on the implementation of the Servlet/JSP Container).
Considering that the threads are seperate for the client, another client would not suffer, if one of them hits the stop button, as destroying the Servlet/JSP is the responsibility of the container.
However, does this also mean, that such Connection Objects which the clients open (ofcourse, it is a very bad programming practice!!) would continue to hog the memory resources till the JSP is destroyed by the Container, incase there is no finally clause in my JSP client?
Also, may I request the group members to share their views on :

Will the page halt like it does, when a <jsp:forward> tag is encountered?
AND
Can we say that the JSP/Servlet would finish processing the _jspservice()/service() method, when the user clicks the stop button?

Thanks in advance.
Regards,


------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Desai Sandeep:
Hi all,
I guess, from your replies that the Container handles each client as a separate Thread (It may not be exactly like that, as it is going to depend on the implementation of the Servlet/JSP Container).

You can safely assume that.
However, does this also mean, that such Connection Objects which the clients open (ofcourse, it is a very bad programming practice!!) would continue to hog the memory resources till the JSP is destroyed by the Container, incase there is no finally clause in my JSP client?

Not sure what you mean - who is opening these Connection objects? The normal HTTP connection between client and server is managed by the servlet engine (or HTTP server) and will be cleaned up automatically. If you open your own connection in your JSP, and do not close it in a finally clause, you will have a potential resource leak.
Will the page halt like it does, when a <jsp:forward> tag is encountered?

As mentioned, an IOException will be thrown. Assuming that you don't explicitly handle this then, yes, the page will halt.
- Peter
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi Peter,
Thank you for your response.

Not sure what you mean - who is opening these Connection objects? The normal HTTP connection between client and server is
managed by the servlet engine (or HTTP server) and will be cleaned up automatically. If you open your own connection in your
JSP, and do not close it in a finally clause, you will have a potential resource leak.

Yes, I had a code which didnot use Connection Pooling and was banking on the fact of opening JDBC connection objects in the JSP.For what you have posted, I understand, if I donot have a finally clause, there could be some serious memory leaks, depending on the web traffic.
Thanks once again for your views.
Regards,

------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Client/Server communication while JSP execution