aspose file tools*
The moose likes Servlets and the fly likes Understanding on web app deployment and working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Understanding on web app deployment and working" Watch "Understanding on web app deployment and working" New topic
Author

Understanding on web app deployment and working

Sawan Mishra
Ranch Hand

Joined: Oct 24, 2013
Posts: 44
Hi everyone,
I have pursued my OCPJP certification with 90%.
BUT I'm very new to JSP and Servlet

I will tell my basic understanding on web application deployment and working.

please rectify if necessary

whenever client clicks on URL a HTTP request is made to web server like Apache and if the request is for dynamic
web page then request is passed to Tomcat(Servlet and jsp engine/web container) and that checks the deployment descriptor mapping
and passes the request to concerned Servletfor processing the request (instantiates the concerned servlet and invokes doGet() or doPost() based on HTTP request)
and this servlet will render a HTML page to web server and
that HTML page will be wrapped to HTTP response and will be returned to client browser


please do read and check above quote and let me know if i'm correct or wrong???


thanks in advance
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Sawan Mishra wrote:
and this servlet will render a HTML page to web server and
that HTML page will be wrapped to HTTP response and will be returned to client browser

Well servlet does not render HTML page, it is actually meant for control, but lets say for now it can produce some sort of response.
This response is passed to the container which in turn passes it to the application server then to web server and finally the client.
The client is responsible for handling the response which could be HTML, image, PDF,etc.

For more information on this, please take a look at this page.


SCJP, SCWCD.
|Asking Good Questions|
Sawan Mishra
Ranch Hand

Joined: Oct 24, 2013
Posts: 44
hi
but murach's servlet book says:
when a web server receives the request for dynamic web page the server passes the request to web application
then application receives the request and generates a response usually a html page and web server wraps this response
html document in an http response and sends it back to the browser


Anyways if I'm using tomcat then its not application server as it has not implemented all j2ee features so
whatever you said regarding application server may not be applicable here.


please rectify me if necessary

thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61064
    
  66

The term "application server" has no set definition. Whether Tomcat is an application server or not depends upon your definition of the term.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sawan Mishra
Ranch Hand

Joined: Oct 24, 2013
Posts: 44
Hi Amit

Well servlet does not render HTML page, it is actually meant for control, but lets say for now it can produce some sort of response.


But in the servlet we are having all
out.println() statements so it renders a html document to servlet engine(Tomcat) and then html document is sent to web server that wraps it to HTTP response
and sends back this html document to browser.

please rectify me if necessary.

thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61064
    
  66

Sure, a servlet can emit anything it wants to as the response, including HTML. But that's not considered the best practice. The servlet should performa any processing that needs to get done in order to prepare the page for display, and then forward to a JSP to actually render the HTML.
Sawan Mishra
Ranch Hand

Joined: Oct 24, 2013
Posts: 44
Hi Bear,
Sure, a servlet can emit anything it wants to as the response, including HTML.
But that's not considered the best practice. The servlet should performa any processing
that needs to get done in order to prepare the page for display, and then forward to a JSP
to actually render the HTML.




thanks Bear for replying. But even if request is forwarded to jsp the jsp itself gets translated to
servlet and compiled and gets loaded to servlet engine and servlet engine runs this servlet so
ultimately whatever we are writing in jsp page must be becoming
out.println("content of jsp page") so servlet renders html code to web server which is sent back to browser
as HTTP response.

I'm not saying that servlet won't do processing but after processing it has to return some html code which will be
sent back to client as HTTP response.

thanks Bear
with regards
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yeah, but that's just hand-waving. It may be the case that a JSP is compiled into a servlet, but you didn't write that servlet. It's also true that the servlet is compiled into byte code, but nobody bothers to say that it's actually the byte code which is generating the HTML. That's because it's irrelevant. Ultimately the byte code is executed by the JVM and converted into machine instructions which are executed by a CPU, but nobody cares that it's the CPU which is really generating the HTML.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61064
    
  66

Sawan Mishra wrote:But even if request is forwarded to jsp the jsp itself gets translated to
servlet and compiled and gets loaded to servlet engine and servlet engine runs this servlet so
ultimately whatever we are writing in jsp page must be becoming

As Paul said, that is an irrelevant implementation detail that has no effect (or shouldn't) on how you write servlets and JSPs.
 
jQuery in Action, 2nd edition
 
subject: Understanding on web app deployment and working