版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 五上第10课 传统美德 源远流长 第一课课件
- 2025年北京邮电大学人工智能学院招聘备考题库(人才派遣)及参考答案详解1套
- 2025年南宁市良庆区大沙田街道办事处公开招聘工作人员备考题库及一套参考答案详解
- 2025年中国人民大学物业管理中心现面向社会公开招聘非事业编制工作人员备考题库及1套完整答案详解
- 2025年成都市龙泉驿区同安中学校小学部面向社会公开招聘临聘教师备考题库及完整答案详解1套
- 2025年青海能源投资集团有限责任公司招聘备考题库及1套完整答案详解
- 2025年武汉某初级中学招聘备考题库及完整答案详解一套
- 2025年重庆医科大学附属北碚医院重庆市第九人民医院招聘非在编护理员备考题库完整参考答案详解
- 2025年上海三毛资产管理有限公司招聘备考题库含答案详解
- 河南轻工职业学院2025年公开招聘工作人员(硕士)备考题库及答案详解1套
- 福建省福州市四校联盟2025-2026学年高三上学期期中联考历史试题
- 2025年谷胱甘肽及酵母提取物合作协议书
- 农业机械安全培训课件
- 2026广西融资担保集团校园招聘补充参考笔试题库及答案解析
- 2026贵州安创数智科技有限公司社会公开招聘119人参考笔试题库及答案解析
- 韩家园林业局工勤岗位工作人员招聘40人备考题库新版
- 2025年云南省人民检察院聘用制书记员招聘(22人)参考笔试题库及答案解析
- 雨课堂在线学堂《医学实验技术与方法新进展》单元考核测试答案
- 【MOOC】《学术交流英语》(东南大学)章节中国大学慕课答案
- 探槽地质编录工作方法
- GB/T 10609.2-1989技术制图明细栏
评论
0/150
提交评论