1 / 11

JSP Example and Best Practices

JSP Example and Best Practices. Minpo, Jung. Web Application Architecture. Patterns for Web Application Development. Servlet model. Moving to JSP Model 1. Moving to JSP Model 2. JSP Processing. Structure of a JSP Page. JSP page = directives + declarations + expressions + scriptlets.

deon
Download Presentation

JSP Example and Best Practices

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JSP Example and Best Practices Minpo, Jung

  2. Web Application Architecture

  3. Patterns for Web Application Development Servlet model

  4. Moving to JSP Model 1

  5. Moving to JSP Model 2

  6. JSP Processing

  7. Structure of a JSP Page • JSP page = directives + declarations + expressions + scriptlets

  8. Directives • An example of the page directive <%@ page import="java.util.Date, java.io.*“ extends="myJSPpage“ buffer="32k" autoflush="false" %> <jsp:directive.page import="java.util.Date, java.io.* " extends="myJSPpage" buffer="32k" autoflush="false" /> <%@ include file="/legal/disclaimer.html"> <jsp:directive.include file="/templates/footer.html" />

  9. Declarations <%! int balance = 0; %> <%! public int getAccountBalance() { return balance; } %> <jsp:declaration> int balance = 0; </jsp:declaration> <jsp:declaration> public int getAccountBalance() { return balance; } </jsp:declaration>

  10. Expressions • Hello, my name is <%= getName() %>. How are you? • out.println("Hello, my name is "+ getName() + ". How are you?"); • <% StringBuffer sb = new StringBuffer(); • sb.append("Hello, my name is ""); • sb.append(getName()); • sb.append(". How are you?); • out.println(sb.toString()); • %> <jsp:expression></jsp:expression>

  11. Scriptlets • <% for (int n=0; n<10; n++) { • out.println(n); • out.println("<br>"); // Line break • } • %> • <jsp:scriptlet> • for (int n=0; n<10; n++) { • out.println(n); • out.println("<br>"); // Line break • } • </jsp:scriptlet>

More Related