RequestContext 这个类在 OSChina 中是很重要的一个类。该类由全局 Filter 进行初始化。并传递给包含 Action 和 页面中直接使用。使用时通过 RequestContext.get() 来获取当前请求上下文实例。 这种方法基本的功能包含:自己主动转码、处理文件上传、登录信息处理,以及一些跟请求相关的经常用法封装。 假设你从中发现了什么问题。请指教。

标签: OSCHINA

[1].[代码] java代码 跳至 [1]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
package

my.mvc;
 
import

java.io.*;
import

java.net.*;
import

java.text.*;
import

java.util.*;
 
import

javax.servlet.*;
import

javax.servlet.http.*;
 
import

my.util.CryptUtils;
import

my.util.Multimedia;
import

my.util.RequestUtils;
import

my.util.ResourceUtils;
import

net.oschina.beans.User;
 
import

org.apache.commons.beanutils.BeanUtils;
import

org.apache.commons.beanutils.ConvertUtils;
import

org.apache.commons.beanutils.Converter;
import

org.apache.commons.beanutils.converters.SqlDateConverter;
import

org.apache.commons.codec.binary.Base64;
import

org.apache.commons.io.FileUtils;
import

org.apache.commons.lang.RandomStringUtils;
import

org.apache.commons.lang.StringUtils;
import

org.apache.commons.lang.math.NumberUtils;
import

org.apache.commons.logging.Log;
import

org.apache.commons.logging.LogFactory;
 
/**
 *
请求上下文
 *
@author Winter Lau
 *
@date 2010-1-13 下午04:18:00
 */
public

class

RequestContext {
     
    private

final

static

Log log = LogFactory.getLog(RequestContext.
class);
 
    private

final

static

int

MAX_FILE_SIZE =
10*1024*1024;
    private

final

static

String UTF_8 =
"UTF-8";
     
    private

final

static

ThreadLocal<RequestContext> contexts =
new

ThreadLocal<RequestContext>();
    private

final

static

boolean

isResin;
    private

final

static

String upload_tmp_path;
    private

final

static

String TEMP_UPLOAD_PATH_ATTR_NAME =
"$OSCHINA_TEMP_UPLOAD_PATH$";
 
    private

static

String webroot =
null;
     
    private

ServletContext context;
    private

HttpSession session;
    private

HttpServletRequest request;
    private

HttpServletResponse response;
    private

Map<String, Cookie> cookies;
     
    static

{
        webroot
= getWebrootPath();
        isResin
= _CheckResinVersion();
        //上传的暂时文件夹
        upload_tmp_path
= webroot +
"WEB-INF"

+ File.separator +
"tmp"

+ File.separator;
        try

{
            FileUtils.forceMkdir(new

File(upload_tmp_path));
        }
catch

(IOException excp) {}
         
        //BeanUtils对时间转换的初始化设置
        ConvertUtils.register(new

SqlDateConverter(
null),
java.sql.Date.
class);
        ConvertUtils.register(new

Converter(){
            SimpleDateFormat
sdf =
new

SimpleDateFormat(
"yyyy-M-d");
            SimpleDateFormat
sdf_time =
new

SimpleDateFormat(
"yyyy-M-d
H:m"
);
            @SuppressWarnings("rawtypes")
            public

Object convert(Class type, Object value) {
                if(value
==
null)
return

null
;
                if

(value
instanceof

Date)
return

(value);
                try

{
                    return

sdf_time.parse(value.toString());
                }
catch

(ParseException e) {
                    try

{
                        return

sdf.parse(value.toString());
                    }
catch

(ParseException e1) {
                        return

null
;
                    }
                }
            }},
java.util.Date.
class);
    }
     
    private

final

static

String getWebrootPath() {
        String
root = RequestContext.
class.getResource("/").getFile();
        try

{
            root
=
new

File(root).getParentFile().getParentFile().getCanonicalPath();
            root
+= File.separator;
        }
catch

(IOException e) {
            throw

new

RuntimeException(e);
        }
        return

root;
    }
     
    /**
     *
初始化请求上下文
     *
@param ctx
     *
@param req
     *
@param res
     */
    public

static

RequestContext begin(ServletContext ctx, HttpServletRequest req, HttpServletResponse res) {
        RequestContext
rc =
new

RequestContext();
        rc.context
= ctx;
        rc.request
= _AutoUploadRequest(_AutoEncodingRequest(req));
        rc.response
= res;
        rc.response.setCharacterEncoding(UTF_8);
        rc.session
= req.getSession(
false);
        rc.cookies
=
new

HashMap<String, Cookie>();
        Cookie[]
cookies = req.getCookies();
        if(cookies
!=
null)
            for(Cookie
ck : cookies) {
                rc.cookies.put(ck.getName(),
ck);
            }
        contexts.set(rc);
        return

rc;
    }
 
    /**
     *
返回Web应用的路径
     *
@return
     */
    public

static

String root() {
return

webroot; }
     
    /**
     *
获取当前请求的上下文
     *
@return
     */
    public

static

RequestContext get(){
        return

contexts.get();
    }
     
    public

void

end() {
        String
tmpPath = (String)request.getAttribute(TEMP_UPLOAD_PATH_ATTR_NAME);
        if(tmpPath
!=
null){
            try

{
                FileUtils.deleteDirectory(new

File(tmpPath));
            }
catch

(IOException e) {
                log.fatal("Failed
to cleanup upload directory: "

+ tmpPath, e);
            }
        }
        this.context
=
null;
        this.request
=
null;
        this.response
=
null;
        this.session
=
null;
        this.cookies
=
null;
        contexts.remove();
    }
     
    public

Locale locale(){
return

request.getLocale(); }
 
    public

void

closeCache(){
        header("Pragma","No-cache");
        header("Cache-Control","no-cache");
        header("Expires",
0L);
    }
     
    /**
     *
自己主动编码处理
     *
@param req
     *
@return
     */
    private

static

HttpServletRequest _AutoEncodingRequest(HttpServletRequest req) {
        if(req
instanceof

RequestProxy)
            return

req;
        HttpServletRequest
auto_encoding_req = req;
        if("POST".equalsIgnoreCase(req.getMethod())){
            try

{
                auto_encoding_req.setCharacterEncoding(UTF_8);
            }
catch

(UnsupportedEncodingException e) {}
        }
        else

if
(!isResin)
            auto_encoding_req
=
new

RequestProxy(req, UTF_8);
         
        return

auto_encoding_req;
    }
     
    /**
     *
自己主动文件上传请求的封装
     *
@param req
     *
@return
     */
    private

static

HttpServletRequest _AutoUploadRequest(HttpServletRequest req){
        if(_IsMultipart(req)){
            String
path = upload_tmp_path + RandomStringUtils.randomAlphanumeric(
10);
            File
dir =
new

File(path);
            if(!dir.exists()
&& !dir.isDirectory()) dir.mkdirs();
            try{
                req.setAttribute(TEMP_UPLOAD_PATH_ATTR_NAME,path);
                return

new

MultipartRequest(req, dir.getCanonicalPath(), MAX_FILE_SIZE, UTF_8);
            }catch(NullPointerException
e){            
            }catch(IOException
e){
                log.fatal("Failed
to save upload files into temp directory: "

+ path, e);
            }
        }
        return

req;
    }
     
    public

long

id() {
        return

param(
"id",
0L);
    }
     
    public

String ip(){
        return

RequestUtils.getRemoteAddr(request);
    }
     
    @SuppressWarnings("unchecked")
    public

Enumeration<String> params() {
        return

request.getParameterNames();
    }
     
    public

String param(String name, String...def_value) {
        String
v = request.getParameter(name);
        return

(v!=
null)?v:((def_value.length>0)?

def_value[0]:null);

    }
     
    public

long

param(String name,
long

def_value) {
        return

NumberUtils.toLong(param(name), def_value);
    }
 
    public

int

param(String name,
int

def_value) {
        return

NumberUtils.toInt(param(name), def_value);
    }
 
    public

byte

param(String name,
byte

def_value) {
        return

(
byte)NumberUtils.toInt(param(name),
def_value);
    }
 
    public

String[] params(String name) {
        return

request.getParameterValues(name);
    }
 
    public

long
[]
lparams(String name){
        String[]
values = params(name);
        if(values==null)
return

null
;
        return

(
long[])ConvertUtils.convert(values,
long.class);
    }
     
    public

String uri(){
        return

request.getRequestURI();
    }
     
    public

String contextPath(){
        return

request.getContextPath();
    }
     
    public

void

redirect(String uri)
throws

IOException {
        response.sendRedirect(uri);
    }
     
    public

void

forward(String uri)
throws

ServletException, IOException {
        RequestDispatcher
rd = context.getRequestDispatcher(uri);
        rd.forward(request,
response);
    }
 
    public

void

include(String uri)
throws

ServletException, IOException {
        RequestDispatcher
rd = context.getRequestDispatcher(uri);
        rd.include(request,
response);
    }
     
    public

boolean

isUpload(){
        return

(request
instanceof

MultipartRequest);
    }
    public

File file(String fieldName) {
        if(request
instanceof

MultipartRequest)
            return

((MultipartRequest)request).getFile(fieldName);
        return

null
;
    }
    public

File image(String fieldname) {
        File
imgFile = file(fieldname);
        return

(imgFile!=
null&&Multimedia.isImageFile(imgFile.getName()))?imgFile:null;
    }
     
    public

boolean

isRobot(){
        return

RequestUtils.isRobot(request);
    }
 
    public

ActionException fromResource(String bundle, String key, Object...args){
        String
res = ResourceUtils.getStringForLocale(request.getLocale(), bundle, key, args);
        return

new

ActionException(res);
    }
 
    public

ActionException error(String key, Object...args){       
        return

fromResource(
"error",
key, args);
    }
     
    /**
     *
输出信息到浏览器
     *
@param msg
     *
@throws IOException
     */
    public

void

print(Object msg)
throws

IOException {
        if(!UTF_8.equalsIgnoreCase(response.getCharacterEncoding()))
            response.setCharacterEncoding(UTF_8);
        response.getWriter().print(msg);
    }
 
    public

void

output_json(String[] key, Object[] value)
throws

IOException {
        StringBuilder
json =
new

StringBuilder(
"{");
        for(int

i=
0;i<key.length;i++){
            if(i>0)
                json.append(',');
            boolean

isNum = value[i]
instanceof

Number ;
            json.append("\"");
            json.append(key[i]);
            json.append("\":");
            if(!isNum)
json.append(
"\"");
            json.append(value[i]);
            if(!isNum)
json.append(
"\"");
        }
        json.append("}");
        print(json.toString());
    }
 
    public

void

output_json(String key, Object value)
throws

IOException {
        output_json(new

String[]{key},
new

Object[]{value});
    }
    public

void

error(
int

code, String...msg)
throws

IOException {
        if(msg.length>0)
            response.sendError(code,
msg[
0]);
        else
            response.sendError(code);
    }
     
    public

void

forbidden()
throws

IOException {
        error(HttpServletResponse.SC_FORBIDDEN);
    }
 
    public

void

not_found()
throws

IOException {
        error(HttpServletResponse.SC_NOT_FOUND);
    }
 
    public

ServletContext context() {
return

context; }
    public

HttpSession session() {
return

session; }
    public

HttpSession session(
boolean

create) {
        return

(session==
null

&& create)?

(session=request.getSession()):session;

    }
    public

Object sessionAttr(String attr) {
        HttpSession
ssn = session();
        return

(ssn!=
null)?

ssn.getAttribute(attr):null;

    }
    public

HttpServletRequest request() {
return

request; }
    public

HttpServletResponse response() {
return

response; }
    public

Cookie cookie(String name) {
return

cookies.get(name); }
    public

void

cookie(String name, String value,
int

max_age,
boolean

all_sub_domain) {
        RequestUtils.setCookie(request,
response, name, value, max_age, all_sub_domain);
    }
    public

void

deleteCookie(String name,
boolean

all_domain) { RequestUtils.deleteCookie(request, response, name, all_domain); }
    public

String header(String name) {
return

request.getHeader(name); }
    public

void

header(String name, String value) { response.setHeader(name, value); }
    public

void

header(String name,
int

value) { response.setIntHeader(name, value); }
    public

void

header(String name,
long

value) { response.setDateHeader(name, value); }
 
    /**
     *
将HTTP请求參数映射到bean对象中
     *
@param req
     *
@param beanClass
     *
@return
     *
@throws Exception
     */
    public

<T> T form(Class<T> beanClass) {
        try{
            T
bean = beanClass.newInstance();
            BeanUtils.populate(bean,
request.getParameterMap());
            return

bean;
        }catch(Exception
e) {
            throw

new

ActionException(e.getMessage());
        }
    }
     
    /**
     *
返回当前登录的用户资料
     *
@return
     */
    public

IUser user() {
        return

User.GetLoginUser(request);
    }
     
    /**
     *
保存登录信息
     *
@param req
     *
@param res
     *
@param user
     *
@param save
     */
    public

void

saveUserInCookie(IUser user,
boolean

save) {
        String
new_value = _GenLoginKey(user, ip(), header(
"user-agent"));
        int

max_age = save ?

MAX_AGE : -1;

        deleteCookie(COOKIE_LOGIN,
true);
        cookie(COOKIE_LOGIN,new_value,max_age,true);
    }
 
    public

void

deleteUserInCookie() {
        deleteCookie(COOKIE_LOGIN,
true);
    }
     
    /**
     *
3.0 以上版本号的 Resin 无需对URL參数进行转码
     *
@return
     */
    private

final

static

boolean

_CheckResinVersion() {
        try{
            Class<?

>
verClass = Class.forName(
"com.caucho.Version");

            String
ver = (String)verClass.getDeclaredField(
"VERSION").get(verClass);
            String
mainVer = ver.substring(
0,
ver.lastIndexOf(
'.'));
            /**
            float
fVer = Float.parseFloat(mainVer);
            System.out.println("---------------->
" + fVer);
            */
            return

Float.parseFloat(mainVer) >
3.0;
        }catch(Throwable
t) {}
        return

false
;
    }
 
 
    /**
     *
自己主动解码
     *
@author liudong
     */
    private

static

class

RequestProxy
extends

HttpServletRequestWrapper {
        private

String uri_encoding;
        RequestProxy(HttpServletRequest
request, String encoding){
            super(request);
            this.uri_encoding
= encoding;
        }
         
        /**
         *
重载getParameter
         */
        public

String getParameter(String paramName) {
            String
value =
super.getParameter(paramName);
            return

_DecodeParamValue(value);
        }
 
        /**
         *
重载getParameterMap
         */
        @SuppressWarnings({
"unchecked",
"rawtypes"

})
        public

Map<String, Object> getParameterMap() {
            Map
params =
super.getParameterMap();
            HashMap<String,
Object> new_params =
new

HashMap<String, Object>();
            Iterator<String>
iter = params.keySet().iterator();
            while(iter.hasNext()){
                String
key = (String)iter.next();
                Object
oValue = params.get(key);
                if(oValue.getClass().isArray()){
                    String[]
values = (String[])params.get(key);
                    String[]
new_values =
new

String[values.length];
                    for(int

i=
0;i<values.length;i++)
                        new_values[i]
= _DecodeParamValue(values[i]);
                     
                    new_params.put(key,
new_values);
                }
                else{
                    String
value = (String)params.get(key);
                    String
new_value = _DecodeParamValue(value);
                    if(new_value!=null)
                        new_params.put(key,new_value);
                }
            }
            return

new_params;
        }
 
        /**
         *
重载getParameterValues
         */
        public

String[] getParameterValues(String arg0) {
            String[]
values =
super.getParameterValues(arg0);
            for(int

i=
0;values!=null&&i<values.length;i++)
                values[i]
= _DecodeParamValue(values[i]);
            return

values;
        }
 
        /**
         *
參数转码
         *
@param value
         *
@return
         */
        private

String _DecodeParamValue(String value){
            if

(StringUtils.isBlank(value) || StringUtils.isBlank(uri_encoding)
                    ||
StringUtils.isNumeric(value))
                return

value;      
            try{
                return

new

String(value.getBytes(
"8859_1"),
uri_encoding);
            }catch(Exception
e){}
            return

value;
        }
 
    }
     
    private

static

boolean

_IsMultipart(HttpServletRequest req) {
        return

((req.getContentType() !=
null)
&& (req.getContentType()
                .toLowerCase().startsWith("multipart")));
    }
 
    /**
     *
生成用户登录标识字符串
     *
@param user
     *
@param ip
     *
@param user_agent
     *
@return
     */
    public

static

String _GenLoginKey(IUser user, String ip, String user_agent) {
        StringBuilder
sb =
new

StringBuilder();
        sb.append(user.getId());
        sb.append('|');
        sb.append(user.getPwd());
        sb.append('|');
        sb.append(ip);
        sb.append('|');
        sb.append((user_agent==null)?0:user_agent.hashCode());
        sb.append('|');
        sb.append(System.currentTimeMillis());
        return

_Encrypt(sb.toString());
    }
 
    /**
     *
加密
     *
@param value
     *
@return
     *
@throws Exception
     */
    private

static

String _Encrypt(String value) {
        byte[]
data = CryptUtils.encrypt(value.getBytes(), E_KEY);
        try{
            return

URLEncoder.encode(
new

String(Base64.encodeBase64(data)), UTF_8);
        }catch(UnsupportedEncodingException
e){
            return

null
;
        }
    }
 
    /**
     *
解密
     *
@param value
     *
@return
     *
@throws Exception
     */
    private

static

String _Decrypt(String value) {
        try

{
            value
= URLDecoder.decode(value,UTF_8);
            if(StringUtils.isBlank(value))
return

null
;
            byte[]
data = Base64.decodeBase64(value.getBytes());
            return

new

String(CryptUtils.decrypt(data, E_KEY));
        }
catch

(UnsupportedEncodingException excp) {
            return

null
;
        }
    }  
 
    /**
     *
从cookie中读取保存的用户信息
     *
@param req
     *
@return
     */
    public

IUser getUserFromCookie() {
        try{
            Cookie
cookie = cookie(COOKIE_LOGIN);
            if(cookie!=null

&& StringUtils.isNotBlank(cookie.getValue())){
                return

userFromUUID(cookie.getValue());
            }
        }catch(Exception
e){}
        return

null
;
    }
 
    /**
     *
从cookie中读取保存的用户信息
     *
@param req
     *
@return
     */
    public

IUser userFromUUID(String uuid) {
        if(StringUtils.isBlank(uuid))
            return

null
;
        String
ck = _Decrypt(uuid);
        final

String[] items = StringUtils.split(ck,
'|');
        if(items.length
==
5){
            String
ua = header(
"user-agent");
            int

ua_code = (ua==
null)?0:ua.hashCode();
            int

old_ua_code = Integer.parseInt(items[
3]);
            if(ua_code
== old_ua_code){
                return

new

IUser(){
                    public

boolean

IsBlocked() {
return

false
;
}
                    public

long

getId() {
return

NumberUtils.toLong(items[
0],-1L);
}
                    public

String getPwd() {
return

items[
1];
}
                    public

byte

getRole() {
return

IUser.ROLE_GENERAL; }
                };
            }
        }
        return

null
;
    }
     
    public

final

static

String COOKIE_LOGIN =
"oscid";
    private

final

static

int

MAX_AGE =
86400

*
365;
    private

final

static

byte
[]
E_KEY =
new

byte
[]{'1','2','3','4','5','6','7','8'};
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

OSChina 其中很重要的一类——RequestContext的更多相关文章

  1. 非关系型数据库(NoSql)

    最近了解了一点非关系型数据库,刚刚接触,觉得这是一个很好的方向,对于大数据 方面的处理,非关系型数据库能起到至关重要的地位.这里我主要是整理了一些前辈的经验,仅供参考. 关系型数据库的特点 1.关系型 ...

  2. 转载 什么是P问题、NP问题和NPC问题

    原文地址http://www.matrix67.com/blog/archives/105 这或许是众多OIer最大的误区之一.    你会经常看到网上出现“这怎么做,这不是NP问题吗”.“这个只有搜 ...

  3. P和NP问题

    1. 通俗详细地讲解什么是P和NP问题 http://blog.sciencenet.cn/blog-327757-531546.html   NP----非定常多项式(英语:non-determin ...

  4. 第二章平稳时间序列模型——ACF和PACF和样本ACF/PACF

    自相关函数/自相关曲线ACF   AR(1)模型的ACF: 模型为: 当其满足平稳的必要条件|a1|<1时(所以说,自相关系数是在平稳条件下求得的):          y(t)和y(t-s)的 ...

  5. MFC编程入门之十七(对话框:文件对话框)

    上一讲介绍的是消息对话框,本节讲解文件对话框.文件对话框也是很常用的一类对话框. 文件对话框的分类 文件对话框分为打开文件对话框和保存文件对话框,相信大家在Windows系统中经常见到这两种文件对话框 ...

  6. Android常见崩溃或闪退的问题描述及原因总结、及与性能相关的模块——持续更新

    1.nullpointer——就是使用一个对象的时候还没有对其进行初始化导致该问题 一般在何种情况下容易出现呢? (1)父窗口+子窗口同时出现的,父窗口因为某种原因消掉了,子窗口还在,操作子窗口找不到 ...

  7. linux下gcc编译多个源文件、gdb的使用方法

    一. gcc常用编译命令选项 假设源程序文件名为test.c. 1. 无选项编译链接 用法:#gcc test.c 作用:将test.c预处理.汇编.编译并链接形成可执行文件.这里未指定输出文件,默认 ...

  8. P问题、NP问题、NPC问题、NP难问题的概念

    P问题.NP问题.NPC问题.NP难问题的概念 离入职尚有几天时间,闲来无事,将大家常见却又很容易搞糊涂的几个概念进行整理,希望对大家有所帮助.你会经常看到网上出现“这怎么做,这不是NP问题吗”.“这 ...

  9. MATLAB学习笔记(十)——MATLAB图形句柄

    (一)图形对象及其句柄 一.图形对象 MATLAB图形对象包括: 1.MATLAB每一个具体图形一定包括计算机屏幕和图形窗口两个对象 二.图形对象句柄 1.定义 MATLAB在创建每一个图形对象时,都 ...

随机推荐

  1. Centos JAVA Eclipse

    wget http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-i586.tar.gz vi /etc/profile 在 ...

  2. CSS3学习--dispaly:inline和float:left两者区别

    1.display:inline: 任何不是块级元素的可见元素都是内联元素.其表现的特性是“行布局”形式!(行布局:其表现形式始终以行进行显示)   2.float:left:指定元素脱离普通的文档流 ...

  3. 详解函数声明VS函数表达式

    函数声明 比方如下:1.我们以一个完整的语句以function开头,不加任何东西. 2.有一个函数名(add) 3.参数可带可不带(x,y) 4.有一个数体 满足以上要求的我们统称为函数声明! 附加小 ...

  4. 讯飞语音SDK Android平台使用

    1. 支持功能介绍: 2. Android API主要业务接口和流程介绍 -------------------------------------------------------- 工程代码: ...

  5. python自动开发之第十八天

    一.JS正则 test - 判断字符串是否符合规定的正则 rep = /\d+/; rep.test("asdfoiklfasdf89asdfasdf") # true rep = ...

  6. Perl常用特殊变量

    perl 内置变量 $- 当前页可打印的行数,属于Perl格式系统的一部分 $! 根据上下文内容返回错误号或者错误串 $” 列表分隔符 $# 打印数字时默认的数字输出格式 $$ Perl解释器的进程I ...

  7. ECMAScript 6 模块简介

    任何平台的其中一个重要特性,除了需要支持代码库外就是模块.直到现在,Javascript还不支持原生的模块化.结果是,各种解决方案都将模块添加到类库中,比如CommonJS modules(部分由no ...

  8. 45 Useful JavaScript Tips, Tricks and Best Practices(有用的JavaScript技巧,技巧和最佳实践)

    As you know, JavaScript is the number one programming language in the world, the language of the web ...

  9. hdu 5135 Little Zu Chongzhi's Triangles

    http://acm.hdu.edu.cn/showproblem.php?pid=5135 题意:给你N个木棍的长度,然后让你组成三角形,问你组成的三角形的和最大是多少? 思路:先求出可以组成的所有 ...

  10. Agri-Net poj 1258

    WA了好多次,注意语言和数据范围 Description Farmer John has been elected mayor of his town! One of his campaign pro ...