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:
-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 is just a servlet. The container translates jsp and convert it into .java then the container calls the servlet service() method.
- The browser sends an HTTP request to the web server.
- The web server recognizes that the request is for a JSP page based on the URL and forwards it to the container.
- 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
- The container compiles the servlet into an executable class. MyJSP_jsp.java -->MyJSP_jsp.class
- The container loads the Servlet class and instantiated it (jspInit())
- 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.
- The web server forwards the HTTP response to the browser.
- 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