Download presentation
Presentation is loading. Please wait.
1
CSE 190: Internet E-Commerce Lecture 7
2
HTML Templates Designed to separate server side logic from HTML presentation Key features –Escapes from HTML into template language –Page compositing –Variable substitution –Executing server side code
3
HTML Template languages JSP (Java Server Pages) ASP (Active Server Pages) –Javascript, VBScript Text::Template (Perl module) PHP (PHP Hypertext Processor) Roll your own implementation
4
Template systems: CGI differences CGI One process per request Request data given by environment variable or via stdin Most template systems Are processed within a thread of the server process –Faster performance Input passed by a reference to a standard “request” variable
5
JSP: Start with HTML (Source for hello.jsp) Hello World Hello World
6
JSP: Variable substitution <% String titleString = “Hello World”; %>
7
JSP: Page Composition Hello World
8
JSP: Page composition : Also evaluates any JSP tags within the included document (allows nesting) To avoid nested evaluation, use
9
JSP: Server side code The primes to 10: The primes to 20: <%-- Separate primes from non primes and generate a table This time as an expression tag defining a function. --%> <%! private String getPrimes(int max) { StringBuffer sb = new StringBuffer(); // Table headers sb.append(" "); sb.append(" number"); sb.append(" "); sb.append(" prime"); sb.append(" ");
10
JSP: Server side (cot’d) // Check for primes for(int i=2; i<=max; i++) { boolean found = false; for(int j=2; j<=Math.sqrt(i); j++) { if(i%j == 0) { found=true; break; } // Table body sb.append(" "); sb.append(" "+i); sb.append(" "); if (found) { sb.append(" no"); } else { sb.append(" yes"); } sb.append(" "); } // End of the table sb.append(" "); return sb.toString(); } %>
11
JSP: Object scope Three major scopes –Request –Session –Application Detail: JSP supports “page” scope What happens to “session” variable if JSP server stops running?
12
Session scope: Cookies Cookies: Allow HTTP server to recognize when the same browser makes a new follow up request Two types of cookies: session, persistent HTTP header syntax –Request Cookie: NAME1=OPAQUE_STRING1; NAME2=OPAQUE_STRING2... –Response Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure Specification: http://www.netscape.com/newsref/std/cookie_spec.html
13
JSP: Implementation import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType( "text/html"); PrintWriter out = res.getWriter(); out.println(" "); out.println(" Hello World "); out.println(" "); out.println(" Hello World "); out.println(" "); }
14
ASP (Active Server Pages) Examples Variable substitution … …. Page composition Server side code The result of the calculation is: Reference: http://www.w3schools.com/asp/asp_intro.asp
15
PHP Examples Variable substitution: Page composition Server side code "; } ?> Reference: http://www.php.net/manual/en/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.