Courage


Courage

John Fitzgerald Kennedy

The courage of life is often a less dramatic spectacle than the courage of a final moment; but it is no less a magnificent mixture of triumph and tragedy. A man does what he must—in spite of personal consequences, in spite of obastacles and dangers and pressures— and that is the basis of human morality.


To be courageous…requires no exceptional qualifications, no magic formula, no special combination of time, place and circumstances. It is an opportunity that sooner or later is presented to us all. Politics merely furnishes one arena of life which imposes special tests of courage. In whatever arena of life one may meet the challenge of courage, whatever may be the sacrifices he faces if he follows his own conscience—the loss of his friends, his fortune, his contentment, even the esteem of his fellow men—each man must decide for himself the course he will follow. The stories of past courage can define that ingredient—they can teach, they can offer hope, they can provide inspiration. But they can not supply courage itself. For this each man must look into his own soul.

spring对国际化的支持

spring对国际化的支持,需要3步:

    1. 配置bean,增加spring对国际化的支持  ReloadableResourceBundleMessageSource
    2. 资源文件  messages_zh_CN.properties
    3. 使用国际化  <s:message code=”hello”/>   context.getMessage(“hello”);

spring-service.xml,之前在spring-web.xml,导致获取不到bean
    <bean id=”messageSource” 
            class=”org.springframework.context.support.ReloadableResourceBundleMessageSource”> 
        <property name=”basenames”> 
    <list> 
        <value>classpath:/messages</value> 
    </list> 
    </property> 
    <property name=”defaultEncoding” value=”UTF-8″ /> 
    <property name=”useCodeAsDefaultMessage” value=”true”></property> 
</bean> 
<bean id=”localeResolver” class=”org.springframework.web.servlet.i18n.SessionLocaleResolver”> 
        <property name=”defaultLocale” value=”zh_CN”></property> 
</bean>

spring-web.xml 语言切换的时候拦截
  <mvc:interceptors> 
    <bean id=”localeChangeInterceptor” 
            class=”org.springframework.web.servlet.i18n.LocaleChangeInterceptor”> 
    <property name=”paramName” value=”lang” /> 
</bean> 
</mvc:interceptors>

资源文件在resources目录下,直接在classpath下


使用:jsp:标签使用,java:上下文.getMessage()

错误分析:
1. 加载资源文件的时候,会去判断beanFactory中有没有包含bean id=”messageSource”的bean,这也是为什么ReloadableResourceBundleMessageSource类的bean的id一定要为“messageSource”。这个时候可以通过beanFactory.getBeanDefinition(“messageSource”),如果没有包含,则不走if语句,spring就没有加载资源文件,那么当你在使用<s:message code=”hello”/>

将会报错:No message found under code ‘title’ for locale ‘zh_CN’, 换句话说此错误是没有加载到bean messageSource。

2. 语言切换无效。通过地址栏http://localhost:8080/page/index.jsp?lang=en 

地址栏请求是*.jsp,参照tomcat home/conf/web.xml截图


所有的*.jsp 会被tomcat容器拦截,根据servlet匹配原则,就不会走DispatcherServlet,就不会走拦截器LocaleChangeInterceptor,所以设置语言无效。

方案:
现在将切换语言的功能通过访问controller

http://localhost:8080/page/index?lang=en 

让拦截LocaleChangeInterceptor去设置语言

THE POWER OF YET

THE POWER OF YET

Carol Dweck

I heard about a school at Chicago where
students had to pass a certain number of courses to graduate, and if they didn’t
pass the a course, they got the grade “Not Yet.” And I thought that it was
fantastic, because if you get a failing grade, you think, I’m nothing, I’m
nowhere. But if you get “Not Yet”,you understand you are on a learning curve. It
gives you a path into the future. “Not Yet” also gave me insight into a
critical event in my career, a real turning point. I hope to see how children
coped with challenge and difficulty, so I gave ten-year-old kids problems that
were slightly too hard for them. Some of them reacted in a shockingly positive
way. They said things like “I love a challenge,” or, “You know, I was hoping
this would be informative.” They understood their ability could be developed. They
had what I called a growth mindset. But other students felt it was tragic,
catastrophic. From their more fixed mindset perspective, their intelligence had
been up for judgment and they failed. Instead of luxuriating the power of yet,
they were gripped in the tyranny of now. So what did they do next? I’ll tell
you what did they do next. In one study, they told us they could probably cheat
the next time instead of studying more if they failed a test. In another study,
after their failure, they looked for someone who did worse than they did, so
they could feel really good about themselves. And in study after study, they
have run from difficulty.

Scientists measured the electrical activity
from  the brain as students confronted an
error. On the left, you see the fixed mindset students. There’s hardly any
activity. They run from the error. They don’t engaged with it. But on the right
you have the students with the growth mindset, the idea that abilities can be
developed. They engaged deeply. Their brain is on fire with yet. They process
the error. They learn from it. They correct it. How are we raising our kids? Are
we raising them from now instead of yet? Are we raising kids who don’t know how
to dream big dreams? Their biggest goal is getting another A or another test
score? And are they carrying this need for constant validation with them into
their future lives?

Maybe employers are coming  to me and saying  we have already raised a generation of young
workers who can’t get through the day without an award. So what can we do? How can
we build bridge to yet? Here are something you can do. First of all, we can
praise wisely, not praising intelligence or talent. That has failed. Don’t do
that anymore. But praising the process that kids engage in: their effort, their
strategies, their focus, their perseverance, their improvement. This process
praise creates kids who are hardy and resilient. There are other ways to reward
yet. We recently teamed up with game scientists from the University of
Washington to create a new online math game that rewarded yet. In this game,
students were rewarded for effort, strategy and process. The usual math game
rewards you for getting answers right right now, but this game rewarded
process. And we got more effort, more strategies, more engagement over longer
periods of time, and more perseverance when they hit really, really hard
problems. Just the words “yet” or “not yet,” we’re finding, give kids
confidence, give kind a path into the future with greater perseverance. And we
can actually change students’ mindsets. In one study, I told them that every
time they push out of their comfort zone to learn something new and difficult,
the neurons in their brain can form new, stronger connections, and over time
they can get smarter. Look what happened: in this study, students who were not
taught this growth mindset continued to show declining grades over this
difficult school transition, but those who were taught this lesson showed a
sharp rebound in their grades. We have shown this now, this kind of improvement
with thousands and thousands of kids, especially struggling students. So let’s talk
about  equality. In our country there are
groups of students who chronically underperform, for example, children in inner
cities, or children on native American reservations. And they’ve done so poorly
for so long that many people think it’s inevitable. But when educators create
growth mindset classrooms steeped in yet, equality happens. Here are just a few
examples. In one year, a kindergarten class in Harlem, New York scored in the
95th percentile on the National Achievement Test. Many of those kids could not
hold a pencil when they arrived at school. In one year, forth grade students in
the South Bronx, way behind, became the number one forth grade class in the
state of New York on the state math test. In a year to a year and a half,
Native American students in a school on a reservation  went from the bottom of their district to the
top, and that district included affluent sections of Seattle. So the native
kids outdid the Microsoft kids. This happened because the meaning of effort and
difficulty transformed. Before, effort and difficulty made them feel dumb, made
them feel giving up, but now, effort and difficulty, that’s when their neurons
are making new connections. That’s when they are getting smarter. I received a
letter recently from a 13-year-old boy. He said, ”Dear Professor Dweck, I appreciate
that your writing is based on solid scientific research, and that’s why I decided
to put it into practice. I put more effort into my schoolwork, into my
relationship with my family, into my relationship with kids at school, and I experienced
great improvement in all of those areas. I now realized I’ve wasted most of my
life.” Let’s not waste any more lives, because once we know that abilities are
capable of such growth, it become a basic human right for children, all
children, to live in places that create that growth, to live in places filled
with yet. Thank you.

multipart/form-data获取文件和表单参数

控件:commons-fileupload-1.2.1.jar

当上传文件的时候表单,表单这个写:

<form name="" action="xx.do" method="post"  
enctype="multipart/form-data">  
<input type="file">
<input type="text" name="username">
</form>

这个时候获取username表单参数的时候,不能用request.getParameter(“username”),这个样无论如何获取到的都是null,这句需要控件来帮助获取值。

DiskFileItemFactory factory = new DiskFileItemFactory();  
ServletFileUpload upload = new ServletFileUpload(factory); 

upload.setHeaderEncoding(request.getCharacterEncoding());
  
Map<String,String> paramMap = new HashMap<String,String>(6);
	try {  
        List items = upload.parseRequest(req);  
	Iterator itr = items.iterator(); 
	String fileName=null;
	while (itr.hasNext()) {  
	FileItem item = (FileItem) itr.next();  

	if(item.isFormField()) {  
	String name = item.getFieldName();  
	String value = item.getString(request.getCharacterEncoding()); 
	paramMap.put(name, value);
	} else {
	    if (item.getName() != null && !item.getName().equals("")) {  
	        fileName = item.getName();
	        File file = new File(RESOURCE_PATH,fileName);  
                item.write(file);  
	        paramMap.put("src", fileName);
	    }   
	}
		 
        }
	} catch (FileUploadException e) {  
		e.printStackTrace();  
	} catch (Exception e) {  
		e.printStackTrace();  
	}  

通过”item.isFormField()“来获取表单字段的值,同时itme.getString(request.getCharacterEncodring()).来解决字符乱码的问题。这个地方尤其要注意。

Oracle CHAR,VARCHAR,VARCHAR2,nvarchar类型的区别与使用

1.varchar,nvarchar, 

四个类型都属于变长字符类型, varchar和varchar2的区别在与后者把所有字符都占两字节,前者只对汉字和全角等字符占两字节。 nvarchar和nvarchar2的区别和上面一样,   与上面区别在于是根据Unicode   标准所进行的定义的类型,通常用于支持多国语言类似系统的定义。 

1.char 

char的长度是固定的,比如说,你定义了char(20),即使你你插入abc,不足二十个字节,数据库也会在abc后面自动加上17个空格,以补足二十个字节; 

char是区分中英文的,中文在char中占两个字节,而英文占一个,所以char(20)你只能存20个字母或10个汉字。 

char适用于长度比较固定的,一般不含中文的情况 

2.varchar/varchar2 

varchar是长度不固定的,比如说,你定义了varchar(20),当你插入abc,则在数据库中只占3个字节。 

varchar同样区分中英文,这点同char。 

varchar2基本上等同于varchar,它是oracle自己定义的一个非工业标准varchar,不同在于,varchar2用null代替varchar的空字符串 

varchar/varchar2适用于长度不固定的,一般不含中文的情况 

3.nvarchar/nvarchar2 

nvarchar和nvarchar2是长度不固定的 

nvarchar不区分中英文,比如说:你定义了nvarchar(20),你可以存入20个英文字母/汉字或中英文组合,这个20定义的是字符数而不是字节数 

nvarchar2基本上等同于nvarchar,不同在于nvarchar2中存的英文字母也占两个字节 

nvarchar/nvarchar2适用于存放中文 

char [ ( n ) ] 

    固定长度,非 Unicode 字符数据,长度为 n 个字节。n 的取值范围为 1 至 8,000,存储大小是 n 个字节。 

varchar [ ( n | max ) ] 

    可变长度,非 Unicode 字符数据。n 的取值范围为 1 至 8,000。max 指示最大存储大小是 2^31-1 个字节。存储大小是输入数据的实际长度加 2 个字节,用于反映存储的数据的长度。所输入数据的长度可以为 0 个字符。 

    * 如果列数据项的大小一致,则使用 char。 

    * 如果列数据项的大小差异相当大,则使用 varchar。 

    * 如果列数据项大小相差很大,而且大小可能超过 8,000 字节,请使用 varchar(max)。 

如果未在数据定义或变量声明语句中char 或 varchar 数据类型指定 n,则默认长度为 1。如果在使用 CAST 和 CONVERT 函数时char 或 varchar 数据类型未指定 n,则默认长度为 30。 

当执行 CREATE TABLE 或 ALTER TABLE 时,如果 SET ANSI_PADDING 为 OFF,则定义为 NULL 的 char 列将作为 varchar 处理。 

另外帮助理解的,只供参考:转自http://www.51testing.com/?uid-258885-action-viewspace-itemid-141197 

也可参照学习http://ce.sysu.edu.cn/garden/dispbbs.asp?boardid=26&ID=8774&replyID=18180&skin=1 

1.NULL值(空值)。 

     a. char列的NULL值占用存储空间。 

     b. varcahr列的NULL值不占用存储空间。 

     c. 插入同样数量的NULL值,varchar列的插入效率明显高出char列。 

2.插入数据 

    无论插入数据涉及的列是否建立索引,char的效率都明显低于varchar。 

3. 更新数据 

     如果更新的列上未建立索引,则char的效率低于varchar,差异不大;建立索引的话,效率较高。 

4. 修改结构 

     a. 无论增加或是删除的列的类型是char还是varchar,操作都能较快的完成,而且效率上没有什么差异。 

     b. 对于增加列的宽度而言,char与varchar有非常明显的效率差异,修改varcahr列基本上不花费时间,而修改char列需要花费很长的时间。 

5.数据检索 

     无论是否通过索引,varchar类型的数据检索略优于char的扫描。 

选择char还是选择varchar的建议 

    1.适宜于char的情况: 

     a. 列中的各行数据长度基本一致,长度变化不超过50字节; 

     b. 数据变更频繁,数据检索的需求较少。 

     c. 列的长度不会变化,修改char类型列的宽度的代价比较大。 

     d. 列中不会出现大量的NULL值。 

     e. 列上不需要建立过多的索引,过多的索引对char列的数据变更影响较大。 

    2.适宜于varchar的情况; 

     a. 列中的各行数据的长度差异比较大。 

     b. 列中数据的更新非常少,但查询非常频繁。 

     c. 列中经常没有数据,为NULL值或为空值 

nchar [ ( n ) ] 

    n 个字符的固定长度的 Unicode 字符数据。n 值必须在 1 到 4,000 之间(含)。存储大小为两倍 n 字节。 

nvarchar [ ( n | max ) ] 

    可变长度 Unicode 字符数据。n 值在 1 到 4,000 之间(含)。max 指示最大存储大小为 2^31-1 字节。存储大小是所输入字符个数的两倍 + 2 个字节。所输入数据的长度可以为 0 个字符。 

注释 

如果没有在数据定义或变量声明语句中指定 n,则默认长度为 1。如果没有使用 CAST 函数指定 n,则默认长度为 30。 

如果列数据项的大小可能相同,请使用 nchar。 

如果列数据项的大小可能差异很大,请使用 nvarchar。 

sysname 是系统提供的用户定义数据类型,除了不可为空值外,在功能上与 nvarchar(128) 相同。sysname 用于引用数据库对象名。 

为使用 nchar 或 nvarchar 的对象分配的是默认的数据库排序规则,但可使用 COLLATE 子句分配特定的排序规则。 

SET ANSI_PADDING ON 永远适用于 nchar 和 nvarchar。SET ANSI_PADDING OFF 不适用于 nchar 或 nvarchar 数据类型。 

在Oracle中CHAR,NCHAR,VARCHAR,VARCHAR2,NVARCHAR2这五种类型的区别 

1.CHAR(size)和VARCHAR(size)的区别 

    CHAR为定长的字段,最大长度为2K字节; 

    VARCHAR为可变长的字段,最大长度为4K字节; 

2.CHAR(size)和NCHAR(size)的区别 

    CHAR如果存放字母数字占1个字节,存放GBK编码的汉字存放2个字节,存放UTF-8编码的汉字占用3个字节; 

    NCHAR根据所选字符集来定义存放字符的占用字节数,一般都为2个字节存放一个字符(不管字符或者汉字) 

3.VARCHAR(size)和VARCHAR2(size)的区别 

    在现在的版本中,两者是没有区别的;最大长度为4K字节;推荐使用VARCHAR2; 

4.VARCHAR2(size)和NVARCHAR2(size)的区别 

    最大长度为4K字节,区别同CHAR与NCHAR的区别;(如果数据库字符集长度是2,则NVARCHAR2最大为2K) 

5.共同特性 

    当执行insert的时候,插入的值为”,则转变成null,即insert … values(”) <=> insert … values(null) 

    搜索的条件须用where xx is null 

6.例子 

    比如有一个性别字段,里面存放“男,女”的其中一个值,两种常用选择 

        CHAR(2)    和 NCHAR(1)


转载自http://winie.iteye.com/blog/540340