140 likes | 350 Views
Week 15 Servlets. MSIS 6 55 Advanced Business Applications Programming. 15 . 1. Servlet Overview and Architecture. Servlet Small portion of the content is static text or markup Do not produce content Perform a task on behalf of the client JavaServer Pages Extension of servlet technology
E N D
Week 15 Servlets MSIS 655Advanced Business Applications Programming 15.1
Servlet Overview and Architecture • Servlet • Small portion of the content is static text or markup • Do not produce content • Perform a task on behalf of the client • JavaServer Pages • Extension of servlet technology • Most of the content is static text or markup • Small portion of the content is generated dynamically • Servlet container (servlet engine) • Server that executes a servlet
What are Java Servlets? • Servlets are Java technology's answer to CGI programming. They are programs that run on a Web server and build Web pages. Building Web pages on the fly is useful (and commonly done) for a number of reasons: • The Web page is based on data submitted by the user. • The data changes frequently. • The Web page uses information from corporate databases or other such sources.
Servlets and JavaServer Pages (JSP) • Request-response model • Packages javax.servlet javax.servlet.http javax.servlet.jsp javax.servlet.tagext • Common implementation of request-response model • Web browsers and Web servers • Form the Web components of J2EE
JavaServer Pages • JavaServer Pages • Extension of Servlet technology • Separate the presentation from the business logic • Simplify the delivery of dynamic Web content • Reuse existing Java components • JavaBean • Custom-tag libraries • Encapsulate complex functionality • Classes and interfaces specific to JSP • Package javax.servlet.jsp • Package javax.servlet.jsp.tagext
JavaServer Pages Overview • JSPs • Look like standard XHTML or XML • Normally include XHTML or XML markup • Known as fixed-template data • Key components • Directives • Actions • Scripting elements • Tag libraries
First JSP Example • Simple JSP example (Fig. 27.1) • Demonstrates • Fixed-template data (XHTML markup) • Creating a Java object (java.util.Date) • Automatic conversion of JSP expression to a String • meta element to refresh Web page at specified interval
Scripting Components • JSP scripting components • Scriptlets (delimited by <% and %>) • Comments • JSP comments (delimited by <%-- and --%>) • XHTML comments (delimited by <!-- and -->) • Java’s comments (delimited by // and /* and */) • Expressions (delimited by <%= and %>) • Declarations (delimited by <%! and %>) • Escape sequences