Frankly i did not like the way authors explained the examples provided.Adding to that when we download examples no libraries were available and it took a long pain for me to achieve that.
And finally i think this book is for starters who want to understand java web development.
Below are the points i wanted to share with readers from this book.
1) Sun Microsystems introduced JSP in 1999.
2) The following steps explain how the web server creates the web page:
a) As with a normal page, your browser sends an HTTP request to the web server. This doesn’t change with JSP, although the URL probably ends in .jsp instead of .html.
b). The web server is not a normal server, but rather a Java server, with the extensions necessary to identify and handle Java servlets. The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP engine.
c). The JSP engine loads the JSP page from disk and converts it into a Java servlet. From this point on, this servlet is indistinguishable from any other servlet developed directly in Java rather than JSP, although the automatically generated Java code of a JSP servlet is difficult to read, and you should never modify it by hand.
d). The JSP engine compiles the servlet into an executable class and forwards the original request to a servlet engine. Note that the JSP engine only converts the JSP page to Java and recompiles the servlet if it finds that the JSP page has changed since the last request. This makes the process more efficient than with other scripting languages (such as PHP) and therefore faster.
e). A part of the web server called the servlet engine loads the Servlet class and executes it. During execution, the servlet produces an output in HTML format, which the servlet engine passes to the web server inside an HTTP response.
f). The web server forwards the HTTP response to your browser.
g). Your web browser handles the dynamically generated HTML page inside the HTTP response exactly as if it were a static page. In fact, static and dynamic web pages are in the same format.
3) One new thing i learned after 4 1/2 yrs of web development is when using RequestDispatcher.
If no particular resource is mentioned in the parameter of getRequestDispatcher method it goes straight to index.jsp.
For Example when this code is run from a servlet it tries to go to index.jsp if found in the application.
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher("/");
rd.forward(req, res);
4) When set set variables in ServletContext scope we can retrieve the same values in jsp using application implicit object.
Example
Sample Servlet Code
ServletContext context = config.getServletContext();
context.setAttribute("base", "Dummy");
In jsp we can retrieve like
<%
String base = (String)application.getAttribute("base");
%>
5) When applying .css class for any HTML element we can apply more than one element by providing all elements with a space.
For Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Styled paragraphs</title>
<style type="text/css">
p {font-size: 130%}
p.bold {font-weight: bold}
p.italic {font-style: italic}
p.p123 {font-size: 100%; font-weight: normal; font-style: normal}
</style>
</head>
<body>
<p>This is a default paragraph</p>
<p class="bold">This is a bold paragraph</p>
<p class="bold italic">This is a bold italic paragraph</p>
<p class="bold p123 italic">This is a normal paragraph</p>
</body>
</html>
6) JSF transparently saves state information of the UI components and repopulates forms when they redisplay.This is possible because the states of the components live beyond the life span of HTTP requests. JSF operates by providing a servlet and a component model that includes event handling, server-side validation, data conversion, and component rendering.Not surprisingly, JSF doesn’t change the basic page life cycle that you already know from JSP: the client makes an HTTP request, and the server replies with a dynamically generated
HTML page.
7) Life Cycle of JSF Components
a) Restore View: The JSF servlet builds the view of the requested page as a component tree that contains the information associated with all components. It also saves the view in a FacesContext instance, thereby making it possible to repopulate the page if necessary—for example, when the user doesn’t fill out a form as required. If the same page was displayed before and component states were saved, that information would also be taken into account. In this phase, JSF wires event handlers and validators (if any) to the components.
b). Apply Request Values: The JSF servlet goes through the component tree and executes each component’s decode method, which extracts values from the request parameters and stores them locally in the component. It also automatically converts the parameters that are associated with object properties of non-string types. Conversion errors cause error messages to be queued to the FacesContext object. In some cases, typically when the user clicks on controls, the servlet also generates request events and queues them to FacesContext.
c). Process Request Events: The servlet calls the processEvent method for each component with one or more queued events. Each component decides to handle the events or delegate their handling to event handlers. In any case, the servlet proceeds with the next phase if all executed processEvent methods return false. Otherwise, it jumps directly to the Render Response phase.
d). Process Validation: The servlet invokes the validate methods of the validators that had been registered during the Restore View phase. For each validate method that returns false, the servlet queues an error message to the FacesContext.
e) Process Events: If validation or conversion errors are generated during the Process Validation phase, control jumps directly to the Render Response phase.
f). Update Model Values: Each UI component can be linked to a field in a Java object called the model object. During this phase, the values of the linked components are copied to the corresponding fields of the model object by executing the component method updateModel, which also does type conversions when necessary. Conversion errors cause error messages to be queued to FacesContext.
g). Process Events: If it turns out that conversion errors were generated during phase 6,control jumps directly to the Render Response phase.
h). Invoke Application: During this phase, the servlet processes the application-level events by executing the corresponding handlers. When the user submits a form or clicks on a link of a JSF application, the JSF servlet generates a corresponding application-level event. One of the tasks you have to do when developing a JSF application is to assign a handler (e.g., a JSP page) to each one of the possible application events.
i). Render Response: The servlet creates a response component tree and delegates the rendering of the page to Tomcat. Each component renders itself as Tomcat goes through the corresponding JSF tags. At the end of this phase, the state of the response is saved so that the servlet can access it during the Restore View phase of subsequent requests to the same page.
Hope you enjoy reading this book
About the Authors
Giulio Zambon
Giulio Zambon is head of technology and operations at World Television. He also belongs to the Society of Scientific Exploration. He is a practicing Java web application developer using the latest JSF, JSP, and Tomcat standards as well as Struts standards.
Michael Sekler
Michael Sekler is an independent IT consultant for large and small companies. In the last few years, he has worked with open source systems, gaining experience with Linux, and Java technologies. In his spare time Michael enjoys good music and walks in the countryside
1 comment:
HI,
I've read the book, but when I download source code of the book and test the eShop app, it's not running.
I've installed on of them (follow installing anything - App.A) but the eshop app still show nothing.
Do you test this app? Pls share me some tip that make that shop running well, OK? or can you guide me to set it up?
Sorry about my English. Pls send me a mess to thonvyvn@yahoo.com if you solved the problem!
Thanks a lot!
Post a Comment