资源描述
Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,Application Architectures for Interactive Web Applications:Java JSP and Model/View/ControllerTechniques,Jeff Schmitt,November 16,2001,ABSTRACT,This talk is the report of my sabbatical leave during Spring 2001 in,which I explored some new techniques in using the Java language to,develop interactive web applications.,Java Server Pages technology(JSP)facilitates the development of,interactive websites with dynamically generated content.JSP programs,contain ordinary HTML tags mixed with Java code.Custom tag libraries,and Template processing are techniques which allow the Java code to be,isolated from the HTML.This application architecture is,based on the principles of Model/View/Controller.,Web Application Components,Client-typically a Web Browser,HTTP-request,response protocol between client and server,HTML files-static web content,Webserver-serves HTML files and,looks for certain request patterns,then forwards request to servlet engine,for example:,/servlet/*,Servlet Engine-supports execution of servlets,Servlet-handles request from client,generates response to client,JSP Engine-supports the compilation of files into Servlets,Web Application-a collection of HTML files,Servlets and JSP pages to implement an information system on the web.,Tiered Systems,Single Tier-Mainframe,LAN,Two Tier-Client-Server,INTERNET,Database,Server,Application,Server,Web,Server,N-Tier-Web Application,Servlet Lifecycle,init(),destroy(),service(),Servlet Sequence Diagram,Client,Webserver,Servlet,request(),init(),destroy(),service(),Process request,response,response,Servlet Multithreading,Client 1,Servlet,request,Client 2,request,response,response,ServletsAdvantagesDisadvantages,Scalable,Persistent,Simple,Flexible,Support,Stable API,Run in separate memory space from Server,Servlet mapping(servlet is not a web page),Hard for Web Designer to change the HTML part of the code,HTML(presentation)and Java code(business logic)mixed together,XML Notation,Begin and end within same tag:,Begin and end as two separate tags:,Document Type Definition,Deployment Descriptor:web.xml,SnoopServlet test.SnoopServlet -454677,SnoopServlet SnoopServlet,SnoopServlet /snoop/*,:/jakarta.apache.org/taglibs/dbtags/WEB-INF/dbtags.tld,JSP-Java Server Pages,Similar to servlets,but they resemble HTML pages,Placed in web folders mixed with HTML files,acts like an HTML file,Compiled automatically to a servlet when first referenced or when the file is changed by programmer.,Intended to help separate the presentation(HTML response)from the logic(processing logic).,Similar to Microsofts Application Server Pages(ASP),JSP Lifecycle,Client,Webserver,Servlet,request,service(),init(),Process request,response,response,JSP,request,JSP to Servlet,Compile Servlet,servlet,JSP scripting elements,JSP Comments,Declarations:placed in static part of servlet,Expressions:evaluate to a string,Scriptlets:any Java statements,Template Text:inserted into response,Name:,JSP Default Objects,Object,Class,Scope,Comments,request,HttpServletRequest,Request,The client request,response,HttpServletResponse,Page,The servlet response,out,JspWriter,page,An object for writing to the output stream,session,HttpSession,Session,Created to track same user as they visit and return to pages in web application,application,ServletContext,Application,Allows servlets to communicate with each other,JSP Object Scope,Scope,Meaning,Page,Available to the handling page only,Request,Available to the handling page and to any servlelt or JSP that control is forwarded to or included,Session,Available to any servlet or JSP within the same session(across repeat visits to web application),Application,Available to any servlet or JSP within the same web application,Custom JSP tags,Assemble reusable JSP code for easy use,An XML-like front end to access Java programming,Designed to bridge the intersection between java programmers and web designers,Tag library holds definitions of custom tags,Custom tags save in Tag Library File,.tld,Many useful Tag Libraries exist for the common tasks such as database access,email,file access,DBTags,From Apache Jakarta project,Allow use of JDBC with Java details hidden,Easy to use,Invisible exception handling,establish connection to server,jdbc:mysql:/localhost/test,org.gjt.mm.mysql.Driver,root,notVerySecure,Statement and Query,The escapeSql tag can be used inside a SQL query to SQL-escape your input values if they contain single quotes.,insert into test_books(id,name)values(3,),select id,name,description from test_books order by 1,no description,JSP Action Elements,Control Tags for request-time include,Optional parameters for Control tags,Allow JSP programs to implement the Controller aspect of the Model-View-Controller architecture,JSP Forward,Client,Webserver,Servlet 1,request,service(),Process,request,response,response,JSP,request,JSP to Servlet,Compile Servlet,servlet,Servlet 2,reque
展开阅读全文