




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、Chapter 9: Application Design and Development Chapter 9: Application Design and Development Application Programs and User InterfacesWeb FundamentalsServlets and JSPApplication ArchitecturesRapid Application DevelopmentApplication PerformanceApplication SecurityEncryption and Its ApplicationsApplicat
2、ion Programs and User InterfacesMost database users do not use a query language like SQLAn application program acts as the intermediary between users and the databaseApplications split intofront-endmiddle layerbackendFront-end: user interfaceFormsGraphical user interfacesMany interfaces are Web-base
3、dApplication Architecture EvolutionThree distinct eras of application architecturemainframe (1960s and 70s)personal computer era (1980s)We era (1990s onwards)Web InterfaceWeb browsers have become the de-facto standard user interface to databasesEnable large numbers of users to access databases from
4、anywhereAvoid the need for downloading/installing specialized code, while providing a good graphical user interfaceJavascript, Flash and other scripting languages run in browser, but are downloaded transparentlyExamples: banks, airline and rental car reservations, university course registration and
5、grading, an so on.The World Wide WebThe Web is a distributed information system based on hypertext.Most Web documents are hypertext documents formatted via the HyperText Markup Language (HTML)HTML documents containtext along with font specifications, and other formatting instructionshypertext links
6、to other documents, which can be associated with regions of the text.forms, enabling users to enter data which can then be sent back to the Web serverUniform Resources LocatorsIn the Web, functionality of pointers is provided by Uniform Resource Locators (URLs).URL example: http:/sigmod The first pa
7、rt indicates how the document is to be accessed“http” indicates that the document is to be accessed using the Hyper Text Transfer Protocol.The second part gives the unique name of a machine on the Internet.The rest of the URL identifies the document within the machine.The local identification can be
8、:The path name of a file on the machine, orAn identifier (path name) of a program, plus arguments to be passed to the programE.g., http:/search?q=silberschatzHTML and HTTPHTML provides formatting, hypertext link, and image display featuresincluding tables, stylesheets (to alter default formatting),
9、etc.HTML also provides input featuresSelect from a set of optionsPop-up menus, radio buttons, check listsEnter valuesText boxesFilled in input sent back to the server, to be acted upon by an executable at the serverHyperText Transfer Protocol (HTTP) used for communication with the Web serverSample H
10、TML Source Text ID Name Department 00128 Zhang Comp. Sci. . Search for: Student Instructor Name: Display of Sample HTML SourceWeb ServersA Web server can easily serve as a front end to a variety of information services.The document name in a URL may identify an executable program, that, when run, ge
11、nerates a HTML document.When an HTTP server receives a request for such a document, it executes the program, and sends back the HTML document that is generated.The Web client can pass extra arguments with the name of the document.To install a new service on the Web, one simply needs to create and in
12、stall an executable that provides that service.The Web browser provides a graphical user interface to the information service.Common Gateway Interface (CGI): a standard interface between web and application serverThree-Layer Web ArchitectureTwo-Layer Web ArchitectureMultiple levels of indirection ha
13、ve overheadsAlternative: two-layer architectureHTTP and SessionsThe HTTP protocol is connectionlessThat is, once the server replies to a request, the server closes the connection with the client, and forgets all about the requestIn contrast, Unix logins, and JDBC/ODBC connections stay connected unti
14、l the client disconnects retaining user authentication and other informationMotivation: reduces load on server operating systems have tight limits on number of open connections on a machineInformation services need session informationE.g., user authentication should be done only once per sessionSolu
15、tion: use a cookieSessions and CookiesA cookie is a small piece of text containing identifying informationSent by server to browser Sent on first interaction, to identify sessionSent by browser to the server that created the cookie on further interactionspart of the HTTP protocolServer saves informa
16、tion about cookies it issued, and can use it when serving a requestE.g., authentication information, and user preferencesCookies can be stored permanently or for a limited timeServletsJava Servlet specification defines an API for communication between the Web/application server and application progr
17、am running in the serverE.g., methods to get parameter values from Web forms, and to send HTML text back to clientApplication program (also called a servlet) is loaded into the serverEach request spawns a new thread in the server thread is closed once the request is servicedExample Servlet Codeimpor
18、t java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class PersonQueryServlet extends HttpServlet public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException response.setContentType(text/html); PrintWriter out = response.getWrite
19、r(); out.println( Query Result); out.println(); . BODY OF SERVLET (next slide) out.println(); out.close(); Example Servlet CodeString persontype = request.getParameter(persontype);String number = request.getParameter(name);if(persontype.equals(student) . code to find students with the specified name
20、 . . using JDBC to communicate with the database . out.println(); out.println( ID Name: + Department ); for(. each result .) . retrieve ID, name and dept name . into variables ID, name and deptname out.println( + ID + + + name + + + deptname + ); ; out.println();else . as above, but for instructors
21、.Servlet SessionsServlet API supports handling of sessionsSets a cookie on first interaction with browser, and uses it to identify session on further interactionsTo check if session is already active:if (request.getSession(false) = true). then existing sessionelse . redirect to authentication pageau
22、thentication pagecheck login/passwordrequest.getSession(true): creates new sessionStore/retrieve attribute value pairs for a particular sessionsession.setAttribute(“userid”, userid)session.getAttribute(“userid”)Servlet SupportServlets run inside application servers such as Apache Tomcat, Glassfish,
23、JBossBEA Weblogic, IBM WebSphere and Oracle Application ServersApplication servers support deployment and monitoring of servletsJava 2 Enterprise Edition (J2EE) platform supporting objects, parallel processing across multiple application servers, etcServer-Side ScriptingServer-side scripting simplif
24、ies the task of connecting a database to the WebDefine an HTML document with embedded executable code/SQL queries.Input values from HTML forms can be used directly in the embedded code/SQL queries.When the document is requested, the Web server executes the embedded code/SQL queries to generate the a
25、ctual HTML document.Numerous server-side scripting languagesJSP, PHPGeneral purpose scripting languages: VBScript, Perl, PythonJava Server Pages (JSP)A JSP page with embedded Java code Hello JSP is compiled into Java + ServletsJSP allows new tags to be defined, in tag librariessuch tags are like lib
26、rary functions, can are used for example to build rich user interfaces such as paginated display of large datasetsPHPPHP is widely used for Web server scriptingExtensive libaries including for database access using ODBC Hello Client Side ScriptingBrowsers can fetch certain scripts (client-side scrip
27、ts) or programs along with documents, and execute them in “safe mode” at the client siteJavascriptMacromedia Flash and Shockwave for animation/gamesVRMLAppletsClient-side scripts/programs allow documents to be activeE.g., animation by executing programs at the local siteE.g., ensure that values ente
28、red by users satisfy some correctness checksPermit flexible interaction with the user.Executing programs at the client site speeds up interaction by avoiding many round trips to serverClient Side Scripting and SecuritySecurity mechanisms needed to ensure that malicious scripts do not cause damage to
29、 the client machineEasy for limited capability scripting languages, harder for general purpose programming languages like JavaE.g., Javas security system ensures that the Java applet code does not make any system calls directlyDisallows dangerous actions such as file writesNotifies the user about po
30、tentially dangerous actions, and allows the option to abort the program or to continue execution.JavascriptJavascript very widely usedforms basis of new generation of Web applications (called Web 2.0 applications) offering rich user interfacesJavascript functions cancheck input for validitymodify th
31、e displayed Web page, by altering the underling document object model (DOM) tree representation of the displayed HTML textcommunicate with a Web server to fetch data and modify the current page using fetched data, without needing to reload/refresh the pageforms basis of AJAX technology used widely i
32、n Web 2.0 applicationsE.g. on selecting a country in a drop-down menu, the list of states in that country is automatically populated in a linked drop-down menuJavascriptExample of Javascript used to validate form input function validate() var credits=document.getElementById(credits).value; if (isNaN
33、(credits)| credits=16) alert(Credits must be a number greater than 0 and less than 16); return false Title: Credits: Application ArchitecturesApplication ArchitecturesApplication layersPresentation or user interfacemodel-view-controller (MVC) architecturemodel: business logicview: presentation of da
34、ta, depends on display devicecontroller: receives events, executes actions, and returns a view to the userbusiness-logic layer provides high level view of data and actions on dataoften using an object data modelhides details of data storage schemadata access layerinterfaces between business logic la
35、yer and the underlying databaseprovides mapping from object model of business layer to relational model of databaseApplication ArchitectureBusiness Logic LayerProvides abstractions of entitiese.g. students, instructors, courses, etcEnforces business rules for carrying out actionsE.g. student can enr
36、oll in a class only if she has completed prerequsites, and has paid her tuition feesSupports workflows which define how a task involving multiple participants is to be carried outE.g. how to process application by a student applying to a universitySequence of steps to carry out taskError handling e.
37、g. what to do if recommendation letters not received on timeWorkflows discussed in Section 26.2Object-Relational MappingAllows application code to be written on top of object-oriented data model, while storing data in a traditional relational databasealternative: implement object-oriented or object-
38、relational database to store object modelhas not been commercially successfulSchema designer has to provide a mapping between object data and relational schemae.g. Java class Student mapped to relation student, with corresponding mapping of attributesAn object can map to multiple tuples in multiple
39、relationsApplication opens a session, which connects to the databaseObjects can be created and saved to the database using session.save(object)mapping used to create appropriate tuples in the databaseQuery can be run to retrieve objects satisfying specified predicatesObject-Relational Mapping and Hi
40、bernate (Cont.)The Hibernate object-relational mapping system is widely usedpublic domain system, runs on a variety of database systemssupports a query language that can express complex queries involving joinstranslates queries into SQL queriesallows relationships to be mapped to sets associated wit
41、h objectse.g. courses taken by a student can be a set in Student objectSee book for Hibernate code exampleThe Entity Data Model developed by Microsoftprovides an entity-relationship model directly to applicationmaps data between entity data model and underlying storage, which can be relationalEntity
42、 SQL language operates directly on Entity Data ModelWeb ServicesAllow data on Web to be accessed using remote procedure call mechanismTwo approaches are widely usedRepresentation State Transfer (REST): allows use of standard HTTP request to a URL to execute a request and return datareturned data is
43、encoded either in XML, or in JavaScript Object Notation (JSON) Big Web Services: uses XML representation for sending request data, as well as for returning resultsstandard protocol layer built on top of HTTPSee Section 23.7.3Disconnected OperationsTools for applications to use the Web when connected
44、, but operate locally when disconnected from the WebE.g. Google Gears browser pluginProvide a local database, a local Web server and support for execution of JavaScript at the clientJavaScript code using Gears can function identically on any OS/browser platformAdobe AIR software provides similar fun
45、ctionality outside of Web browserRapid Application DevelopmentA lot of effort is required to develop Web application interfacesmore so, to support rich interaction functionality associated with Web 2.0 applicationsSeveral approaches to speed up application developmentFunction library to generate use
46、r-interface elementsDrag-and-drop features in an IDE to create user-interface elementsAutomatically generate code for user interface from a declarative specificationAbove features have been in used as part of rapid application development (RAD) tools even before advent of WebWeb application developm
47、ent frameworksJava Server Faces (JSF) includes JSP tag libraryRuby on RailsAllows easy creation of simple CRUD (create, read, update and delete) interfaces by code generation from database schema or object modelASP.NET and Visual StudioASP.NET provides a variety of controls that are interpreted at s
48、erver, and generate HTML codeVisual Studio provides drag-and-drop development using these controlsE.g. menus and list boxes can be associated with DataSet objectValidator controls (constraints) can be added to form input fieldsJavaScript to enforce constraints at client, and separately enforced at s
49、erverUser actions such as selecting a value from a menu can be associated with actions at serverDataGrid provides convenient way of displaying SQL query results in tabular formatApplication PerformanceImproving Web Server PerformancePerformance is an issue for popular Web sites May be accessed by mi
50、llions of users every day, thousands of requests per second at peak timeCaching techniques used to reduce cost of serving pages by exploiting commonalities between requestsAt the server site:Caching of JDBC connections between servlet requestsa.k.a. connection poolingCaching results of database quer
51、iesCached results must be updated if underlying database changesCaching of generated HTMLAt the clients networkCaching of pages by Web proxyApplication SecuritySQL InjectionSuppose query is constructed usingselect * from instructor where name = + name + Suppose the user, instead of entering a name,
52、enters:X or Y = Ythen the resulting statement becomes:select * from instructor where name = + X or Y = Y + which is:select * from instructor where name = X or Y = YUser could have even usedX; update instructor set salary = salary + 10000; -Prepared statement internally uses:select * from instructor
53、where name = X or Y = YAlways use prepared statements, with user inputs as parametersIs the following prepared statemen secure? conn.prepareStatement(select * from instructor where name = + name + “)Cross Site ScriptingHTML code on one page executes action on another pageE.g. Risk: if user viewing p
54、age with above code is currently logged into mybank, the transfer may succeedAbove example simplistic, since GET method is normally not used for updates, but if the code were instead a script, it could execute POST methodsAbove vulnerability called cross-site scripting (XSS) or cross-site request fo
55、rgery (XSRF or CSRF)Prevent your web site from being used to launch XSS or XSRF attacksDisallow HTML tags in text input provided by users, using functions to detect and strip such tagsProtect your web site from XSS/XSRF attacks launched from other sites.next slideCross Site ScriptingProtect your web
56、 site from XSS/XSRF attacks launched from other sitesUse referer value (URL of page from where a link was clicked) provided by the HTTP protocol, to check that the link was followed from a valid page served from same site, not another siteEnsure IP of request is same as IP from where the user was au
57、thenticatedprevents hijacking of cookie by malicious userNever use a GET method to perform any updatesThis is actually recommended by HTTP standardPassword LeakageNever store passwords, such as database passwords, in clear text in scripts that may be accessible to usersE.g. in files in a directory a
58、ccessible to a web serverNormally, web server will execute, but not provide source of script files such as file.jsp or file.php, but source of editor backup files such as file.jsp, or .file.jsp.swp may be served Restrict access to database server from IPs of machines running application serversMost
59、databases allow restriction of access by source IP addressApplication AuthenticationSingle factor authentication such as passwords too risky for critical applicationsguessing of passwords, sniffing of packets if passwords are not encryptedpasswords reused by user across sitesspyware which captures p
60、asswordTwo-factor authenticatione.g. password plus one-time password sent by SMSe.g. password plus one-time password devicesdevice generates a new pseudo-random number every minute, and displays to useruser enters the current number as passwordapplication server generates same sequence of pseudo-ran
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 健康中國戰(zhàn)略下的智慧醫(yī)院設(shè)計與建設(shè)
- 企業(yè)類贈與合同范例
- 付協(xié)調(diào)費合同范例
- 橙青色扁平風牙齒健康模板
- 書采編合同范例
- 會議宣傳合同范例
- 溫州市普通高中2025屆高三第三次適應性考試英語試題及答案
- 區(qū)塊鏈技術(shù)在供應鏈管理中的未來發(fā)展預測
- 醫(yī)技升級新篇章-基于大數(shù)據(jù)的醫(yī)療培訓與模擬應用研究
- 會議設(shè)備維護合同范例
- 10以內(nèi)加減法練習題1000題-直接打印版
- 教育部《中小學德育工作指南》-道德修養(yǎng)手冊
- RAG技術(shù):人工智能的新篇章
- JGT163-2013鋼筋機械連接用套筒
- 2024年7月浙江省高中學業(yè)水平考試數(shù)學試卷真題(含答案詳解)
- DL∕T 782-2001 110kV及以上送變電工程啟動及竣工驗收規(guī)程
- 用友大易-2022雇主品牌白皮書
- JJF(通信) 068-2023 雷達回波模擬器校準規(guī)范(報批稿)
- 《公路橋梁施工監(jiān)控技術(shù)規(guī)程》(JTGT3650-01-2022)
- 上交所金橋數(shù)據(jù)中心用戶手冊
- 胸腔積液考試試題
評論
0/150
提交評論