Monday, March 24, 2014

Java EE offers Filter mechanism for Request / Response for additional processing program, such as H


Java EE offers Filter mechanism for Request / Response for additional processing program, such as Header information, parameter information and HTML content generated. Filter water purification methods what circumstances need to use it? For example, if we want to increase website hits each page features a number of statistical and browser information, the processing water purification methods can be done in each controller's action, and then repeat this process write function calls used. However, under the help of Filter, Filter can increase would not affect an existing code of each controller, and then processed water purification methods for specific or all web access. A common application examples in the past to develop Java EE application coding problem frequently encountered, such as Tomcat water purification methods and other container conversion for form data sent by the browser, you may need to go through getBytes () in order to solve the Chinese garbled. String name = new String (. (Request.getParameter ("name")) getBytes ("ISO-8859-1"), "utf-8"); since before the Request Filter allows the main program to be executed in front to do first processing, so it can be handed over to the main program code conversion water purification methods Fortunately, in the logic of the main program, water purification methods you do not need to add this treatment coding trivial details. Grails is able to correctly handle the coding Request form data is to use the data first CharacterEncodingFilter been processed, so the use of the information obtained in the Controller params are converted to the correct encoding. The Filter Grails very easy way to define, for example: grails create-filter Some will produce grails-app/conf/test1/SomeFilters.groovy code, which reads as follows. class SomeFilters {def filters = {all (controller: '*', action: water purification methods '*') {before = {} after = {Map model ->} afterView = {Exception e ->}}}} in def filters block inside, can be used to define multiple forms of DSL Filter, pre-defined all the Filter Sample / action processing for all controller. In addition water purification methods you can specify which controller and processing carried Filter action against uri parameter setting can also use the URL format, when Request URL matches will be processed (with prefix plus ** wildcard setting). someURIs (uri: '/ water purification methods book / **') {} examples provided below, is the use of Grails Filter date form data automatically converted into the form of GORM parameters can be automatically processed. all (controller: '*', action: '*') {before = {log.info "Start $ {controllerName} - $ {actionName}-Filter" params.each {key, value -> / / Transform value from Ext JS to Grails date style if (value == ~ / ^ \ d \ d \ d \ d \ - \ d \ d \ - \ d \ dT \ d \ d: \ d \ d: \ d \ d $ /) {/ / Convert into Date object / / params [key] = Date.parse ('yyyy-MM-dd HH: mm: ss', value.replaceFirst ('T', '')) / / Convert into Grails style date string / / params [key] = "$ {value} Z" / / Convert into GORM properties recognization params [key] = 'date.struct' params ["$ {key} _year"] = value.substring water purification methods (0,4 ) params ["$ {key} _month"] = value.substring (5,7) params ["$ {key} _day"] = value.substring (8,10) params ["$ {key} _hour"] = value.substring (11,13) params ["$ {key} _minute"] = value.substring (14,16) params ["$ {key} _second"] = value.substring (17,19) log.info " Found $ {value} is a Ext JS date format, transform into Grails style "log.info" params [$ {key}] = $ {params [key]} "}}} after = {Map model ->} afterView = {Exception e ->}} water purification methods
2014 (8) February (4) January (4) 2013 (133) December (6) November (9) October (13) September (4) eight May (4) O'Reilly book introduces JavaScript Testing with Jasmine by E. .. Gradle as Minimum Web Server for Testing Web-based test designed ultra-lightweight ... Grails 2/30 using a filter (Filters) Grails 1/30 message Record (Logging) mechanism July (4) April (2) March (12) February (29) January (50) 2012 (181) December (26) eleven May (9) October (9) September (24) August water purification methods (9) July (6) June (21) May (16) April (10) March ( 19) February (15) January (17) 2011 (197) December (17) November (19) October (20) September (7) August (16 ) July (15) June (27) May (33) April (30) March (4)

No comments:

Post a Comment