版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、本科畢業(yè)設計(論文)外文翻譯(附外文原文) 系 ( 院 ): 信息科學與工程學院 課題名稱: 學生信息管理系統(tǒng) 專業(yè)(方向):計算機科學與技術(應用)7.1 enter actionmappingsthe model 2 architecture (see chapter 1) encourages us to use servlets and java-server pages in the same application. under model 2, we start by calling a servlet.the servlet handles the business logic
2、 and directs control to the appropriate pageto complete the response.the web application deployment descriptor (web.xml) lets us map a url patternto a servlet. this can be a general pattern, like *.do, or a specific path, likesaverecord.do.some applications implement model 2 by mapping a servlet to
3、each businessoperation. this approach works, but many applications involve dozens or hundredsof business operations. since servlets are multithreaded, instantiating so manyservlets is not the best use of server resources. servlets are designed to handle anynumber of parallel requests. there is no pe
4、rformance benefit in simply creatingmore and more servlets.the servlets primary job is to interact with the container and http. handlinga business operation is something that a servlet could delegate to another component.struts does this by having the actionservlet delegate the business operationto
5、an object. using a servlet to receive a request and route it to a handler is knownas the front controller pattern go3.of course, simply delegating the business operation to another componentdoes not solve the problem of mapping uris w3c, uri to business operations.our only way of communicating with
6、a web browser is through http requests anduris. arranging for a uri to trigger a business operation is an essential part ofdeveloping a web application.meanwhile, in practice many business operations are handled in similar ways.since java is multithreaded, we could get better use of our server resou
7、rces if wecould use the same action object to handle similar operations. but for this towork, we might need to pass the object a set of configuration parameters to usewith each operation.so whats the bottom line? to implement model 2 in an efficient and flexibleway, we need to:enter actionmappings 1
8、95_ route requests for our business operations to a single servlet_ determine which business operation is related to the request_ load a multithreaded helper object to handle the business operation_ pass the helper object the specifics of each request along with any configurationdetail used by this
9、operationthis is where actionmappings come in.7.1.1 the actionmapping beanan actionmapping (org.apache.struts.action.actionmapping) describes howthe framework handles each discrete business operation (or action). in struts,each actionmapping is associated with a specific uri through its path propert
10、y.when a request comes in, the actionservlet uses the path property to select thecorresponding actionmapping. the set of actionmapping objects is kept in anactionmappings collection (org.apache.struts.action.actionmappings).originally, the actionmapping object was used to extend the action objectrat
11、her than the action class. when used with an action, a mapping gives a specificaction object additional responsibilities and new functionality. so, it was essentiallyan action decorator go4. along the way, the actionmapping evolved into anobject in its own right and can be used with or without an ac
12、tion.definition the intent of the decorator pattern is to attach additional responsibilities toan object dynamically. decorators provide a flexible alternative to subclassingfor extending functionality go4.the actionmappings are usually created through the struts configuration file.for more about th
13、is file, see chapter the actionmappings catalogthe actionmappings catalog the business logic available to a struts application.when a request comes in, the servlet finds its entry in the actionmappings catalogand pulls the corresponding bean.the actionservlet uses the actionmapping bean to d
14、ecide what to do next. itmay need to forward control off to another resource. or it may need to populateand validate an actionform bean. at some point, it may have to pass control to anaction object, and when the action returns, it may have to look up an action-forward associated with this mapping.1
15、96 chapter 7designing with actionmappingsthe actionmapping works like a routing slip for the servlet. depending onhow the mapping is filled out, the request could go just about anywhere.the actionmappings represent the core design of a struts application. if youwant to figure out how a struts applic
16、ation works, start with the actionmappings. ifyou want to figure out how to write a new struts application, start with the action-mappings. the mappings are at the absolute center of every struts application.in this chapter, we take a close look at the actionmapping properties andexplore how they he
17、lp you design the flow of a struts application.1.0 vs 1.1 in struts 1.1, actionmapping subclasses actionconfig (org.apache.struts.config.actionconfig) and adds api methods required forbackward compatibility. actionmapping is not deprecated, and how thehierarchy will be handled in future releases has
18、 not been determined.for now, we refer to the actionmapping class, but you should note thatin struts 1.1 all of the action properties are actually defined by the actionconfigsuper class. the actionmapping class otherwise works thesame way in both versions.7.2 actionmapping propertiestable 7.1 descri
19、bes the base actionmapping properties. as with other configurationcomponents, developers may extend actionmapping to provide additionalproperties.table 7.1 the base actionmapping propertiesproperty descriptionpath the uri path from the request used to select this mapping. (api command)forward the co
20、ntext-relative path of the resource that should serve this request via a forward.exactly one of the forward, include, or type properties must be specified.orinclude the context-relative path of the resource that should serve this request via aninclude. exactly one of the forward, include, or type pr
21、operties must bespecified.ortype optionally specifies a subclass of org.apache.struts.action.actionmappingthat should be used when instantiating this mapping.classname the fully qualified name of the action class used by this mapping.sincestruts 1.1actionmapping properties 197in the sections that fo
22、llow, we take a look at each of these properties.7.2.1 the path propertythe actionmapping uri, or path, will look to the user like just another file onthe web server. but it does not represent a file. it is a virtual reference to ouractionmapping.because it is exposed to other systems, the path is n
23、ot really a logical name, likethose we use with actionforward. the path can include slashes and an extensionas if it referred to a file systembut they are all just part of a single name.the actionmappings themselves are a “flat” namespace with no type of internalhierarchy whatsoever. they just happe
24、n to use the same characters that we areused to seeing in hierarchical file the name of the form bean, if any, associated with this action. this is not the classname. it is the logical name used in the form bean configuration.roles the list of security roles that may access this mapping
25、.scope the identifier of the scope (request or session) within which the form bean, if any,associated with this mapping will be created.validate set to true if the validate method of the form bean (if any) associated with thismapping should be called.input context-relative path of the input form to
26、which control should be returned if a validationerror is encountered. this can be any uri: html, jsp, vm, or another action-mapping.parameter general-purpose configuration parameter that can be used to pass extra informationto the action selected by this actionmapping.attribute name of the request-s
27、cope or session-scope attribute under which our form bean isaccessed, if it is other than the beans specified name.prefix prefix used to match request parameter names to form bean property names, if any.suffix suffix used to match request parameter names when populating the properties ofour actionfo
28、rm bean, if any.unknown can be set to true if this mapping should be configured as the default for this application(to handle all requests not handled by another mapping). only one mappingcan be defined as the default unknown mapping within an application.forwards(s) block of actionforwards for this
29、 mapping to use, if any.exception(s) block of exceptionhandlers for this mapping to use, if any.table 7.1 the base actionmapping properties (continued)property descriptionsincestruts 1.1sincestruts 1.1198 chapter 7designing with actionmappingsof course, it can still be useful to treat your actionmap
30、pings as if they werepart of a hierarchy and group related commands under the same folder. theonly restriction is that the names must match whatever pattern is used in theapplications deployment description (web.xml) for the actionservlet. this is usuallyeither /do/* or *.do, but any similar pattern
31、 can be used.if you are working in a team environment, different team members can begiven different actionmapping namespaces to use. some people may be workingwith the /customer actionmappings, others may be working with the /vendoractionmappings. this may also relate to the java package hierarchy t
32、he team isusing. since the actionmapping uris are logical constructs, they can be organizedin any way that suits your project.with struts 1.1, these types of namespaces can be promoted to applicationmodules. each team can work independently on its own module, with its own setof configuration files a
33、nd presentation pages. configuring your application to usemultiple modules is covered in chapter 4.definition the web runs on uris, and most uris map to physical files. if you want tochange the resource, you change the corresponding file. some uris, likestruts actions, are virtual references. they d
34、o not have a correspondingfile but are handled by a programming component. to change the resource,we change how the component is programmed. but since thepath is a uri and interacts with other systems outside our control, thepath is not a true logical referencethe name of an actionforward, forinstan
35、ce. we can change the name of an actionforward without consultingother systems. its an internal, logical reference. if we change thepath to an actionmapping, we might need to update other systems thatrefer to the actionmapping through its public uri.7.2.2 the forward propertywhen the forward propert
36、y is specified, the servlet will not pass the request to anaction class but will make a call to requestdispatcher.forward. since the operationdoes not use an action class, it can be used to integrate struts with otherresources and to prototype systems. the forward, include, and type propertiesare mu
37、tually exclusive. (see chapter 6 for more information.)7.2.3 the include propertywhen the include property is specified, the servlet will not pass the request to anaction class but will make a call to requestdispatcher.include. the operationactionmapping properties 199does not use an action class an
38、d can be used to integrate struts with other components.the forward, include, and type properties are mutually exclusive. (seechapter 6 for more information.)7.2.4 the type propertymost mappings will specify an action class type rather than a forward or include.an action class may be used by more th
39、an one mapping. the mappings may specifyform beans, parameters, forwards, or exceptions. the forward, include, andtype properties are mutually exclusive.7.2.5 the classname propertywhen specified, classname is the fully qualified java classname of the actionmappingsubclass that should be used for th
40、is object. this allows you to use your ownactionmapping subclass with specialized methods and properties. see alsosection .6 the name propertythis property specifies the logical name for the form bean, as given in the formbeansegment of the struts configuration file. by default, this is also
41、the name tobe used when placing the form bean in the request or session context. use theattribute property of this class to specify a different attribute key.7.2.7 the roles propertythis property is a comma-delimited list of the security role names that are allowedaccess to this actionmapping object
42、. by default, the same system that is used withstandard container-based security is applied to the list of roles given here. thismeans you can use action-based security in lieu of specifying url patterns in thedeployment descriptor, or you can use both together.the security check is handled by the p
43、rocessroles method of the request-processor (org.apache.struts.action.requestprocessor). by subclassingrequestprocessor, you can also use the roles property with application-basedsecurity. see chapter 9 for more about subclassing requestprocessor.7.2.8 the scope propertythe actionform bean can be st
44、ored in the current request or in the session scope(where it will be available to additional requests). while most developers userequest scope for the actionform, the framework default is session scope. tomake request the default, see section 7.4.sincestruts 1.1sincestruts 1.1200 chapter 7designing
45、with actionmappings7.2.9 the validate propertyan important step in the lifecycle of an actionform is to validate its data beforeoffering it to the business layer. when the validate property for a mapping is true,the actionservlet will call the actionforms validate method. if validate returnsfalse, t
46、he request is forwarded to the resource given by the input property.often, developers will create a pair of mappings for each data entry form. onemapping will have validate set to false, so you can create an empty form. theother has validate set to true and is used to submit the completed form.note
47、whether or not the actionform validate method is called does not relateto the actionservlets validating property. that switch controlshow the struts configuration file is processed.7.2.10 the input propertywhen validate is set to true, it is important that a valid path for input be provided.this is
48、where control will pass should the actionform validate methodreturn false. often, this is the address for a presentation page. sometimes it willbe another action path (with validate set to false) that is required to generatedata objects needed by the page.note the input path often leads back to the
49、page that submitted the request.while it seems natural for the framework to return the request to whereit originated, this is not a simple task in a web application. a request is oftenpassed from component to component before a response is sent backto the browser. the browser only knows the path it
50、used to retrieve theinput page, which may or may not also be the correct path to use for theinput property. while it may be possible to try and generate a default inputpage based on the http referrer attribute, the struts designersdeemed that approach unreliable.inputforwardin struts 1.0, the action
51、mapping input property is always a literal uri. instruts 1.1, it may optionally be the name of an actionforward instead. theactionforward is retrieved and its path property is used as the input property.this can be a global or local actionforward.to use actionforwards here instead of literal paths,
52、set the inputforwardattribute on the element for this module to true:sincestruts 1.1actionmapping properties 201for more about configuring struts, see chapter 4. for more about actionforwards,see chapter 1 the parameter propertythe generic parameter property allows actions to be configured at
53、 runtime. severalof the standard struts actions make use of this property, and the standardscaffold actions often use it, too. the parameter property may contain a uri, thename of a method, the name of a class, or any other bit of information an actionmay need at runtime. this flexibility allows som
54、e actions to do double and tripleduty, slashing the number of distinct action classes an application needs on hand.within an action class, the parameter property is retrieved from the mappingpassed to perform:parameter = mapping.getparameter();multiple parameterswhile multiple parameters are not sup
55、ported by the standard actionmappingsclass, there are some easy ways to implement this, including using httputils, astringtokenizer, or a properties file (java.util.properties).httputils. although deprecated as of the servlet api 2.3 specification, thehttputils package (javax.servlet.http.httputils)
56、 provides a static methodthat parses any string as if it were a query string and returns a hashtable(java.util.hashtable):hashtable parameters = parsequerystring(parameter);the parameter property for your mapping then becomes just another querystring, because you might use it elsewhere in the struts
57、 configuration.stringtokenizer. another simple approach is to delimit the parameters using thetoken of your choicesuch as a comma, colon, or semicolonand use thestringtokenizer to read them back:stringtokenizer incoming =new stringtokenizer(mapping.getparameter(),;);int i = 0;string parameters = new stringincoming.counttokens();while (incoming.hasmoretokens() parametersi+ = incoming.nexttoken().trim();202 chapter 7designing with actionmappingsproperties file. while slightly
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年凝血分析儀器試劑項目資金申請報告代可行性研究報告
- 強化融資租賃-提升中小企業(yè)財務自由度
- 數(shù)據(jù)要素產(chǎn)業(yè)集聚區(qū)評估指南編制說明
- 2.2 30°,45°,60°角的三角函數(shù)值 同步練習
- 【浙教】期中模擬卷02【1-4章】
- 盤山的導游詞(30篇)
- 畫房子的美術教案6篇
- 銷售季度個人述職報告
- 銷售員成功溝通技巧(3篇)
- 鐵路心得體會模板5篇
- 河南省信陽市2024-2025學年七年級上學期期中歷史試題(含答案)
- GB/T 44570-2024塑料制品聚碳酸酯板材
- 中國航空協(xié)會:2024低空經(jīng)濟場景白皮書
- 2024年學校食堂管理工作計劃(六篇)
- 天車工競賽考核題
- 民辦非企業(yè)單位理事會制度
- 臨床輸血的護理課件
- 民生銀行在線測評真題
- 人教版(PEP)小學六年級英語上冊全冊教案
- 部編版二年級上冊-課文一-快樂讀書吧:讀讀童話故事-孤獨的小螃蟹(課件)(共26張課件)
- 大學美育學習通超星期末考試答案章節(jié)答案2024年
評論
0/150
提交評論