Monday 30 March 2015

OCEJWCD - 2. Introduction to Java Server Pages

OCEJWCD (SCWCD) - 1Z0-899 - Web Component Developer Certification

2.1. Describe why servlets are not the whole solution

Generate dynamic content with a sevlet class a first approach can be writing html in the output and be rendered in a browser. This can work but it is not the most convenient solution.

Example of HTML embedded in a java program:





This is not a good solution due to:
-difficult to read and maintain.
-ugly code and with compilation problems because of carriage returns, quotes...etc,all the characters that will need to be scaped.

Instead of applying HTML in java the solution is java in HTML --> JSP

JSP (Java Server Pages) is a technology to create dynamic web pages based in HTML, XML, using Java programming language.

2.2. Describe essentials of JSPs

JSP basic syntax:
  • Directives : 
    • <%@ page...
    • <%@ include...
    • <%@ taglib...
  • Scriplet:     
    • <% out.println("name");%>
  • Expression  
    • <%= Math.round(2.56324)%>
  • Declaration 
    • <%! int count=1;%>
JSP lifecycle process:
JSP is just a servlet. The container translates jsp and convert it into .java then the container calls the servlet service() method.
  1. The browser sends an HTTP request to the web server.
  2. The web server recognizes that the request is for a JSP page based on the URL and forwards it to the container.
  3. The container loads the JSP page and converts it into a servlet content. This conversion is very simple in which all template text is converted to println( ) statements and all JSP elements are converted to Java code that implements the corresponding dynamic behaviour of the page. MyJSP.jsp --> MyJSP_jsp.java
  4. The container compiles the servlet into an executable class. MyJSP_jsp.java -->MyJSP_jsp.class
  5. The container loads the Servlet class and instantiated it (jspInit())
  6. The container creates a new thread and and executes it( _jspService()). During execution, the servlet produces an output in HTML format, inside an HTTP response.
  7. The web server forwards the HTTP response to the browser.
  8. Finally web browser handles the dynamically generated HTML page inside the HTTP response exactly as if it were a static page.


2.3. Understand fundamentals and reasons for MVC architecture

The fundamentals to apply JavaEE patterns are:
-Performance
-Modularity
-Flexibility
-Maintainability
-Extensibility

Reasons for MVC architecture:
  • separation of concerns (every element model, view , controller can be changed independently, and minimizes the impact in other tiers of the application, at the same time ) 
  • loose couplings (model component hide internal details to  the view a controller components).
OCEJWCD (SCWCD) - 1Z0-899 - Web Component Developer Certification

No comments:

Post a Comment