Most_important

toString 和 String.ValueOf() , (String)

obj.toString()是在Object中定义的,obj不能为null
String.ValueOf(null) => "null"

Xml中,不能用逗号分隔,一般是用空格!!

正确:

错误:
<constructor-arg name="name" , value="user-ok" />
注意: constructor-arg name="paraname", paraname是参数名字,不能随意写错!!

要求被注入的属性 , 必须有set方法 , set方法的方法名由set + 属性首字母大写 , 如果属性是boolean类型 , 没
有set方法 , 是 is.

解决Servlet中文乱码问题

一、出现乱码的原因   
由于浏览器默认使用UTF-8码表进行编码,而servlet使用ISO-8859-1码表进行编码,传输和接收方编码不一致导致乱码的产生。
二、乱码的类型以及解决办法   
response.setHeader("content-type", "text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
第一句目的是为了指定浏览器以UTF-8码表打开服务器发出的数据   
第二句目的是设置response使用的码表,控制response以UTF-8码表向浏览器写入数据(必须写在方法中第一行)   

OutputStream out=response.getOutputStream();
out.write("<metahttp-equiv='content-type' content='text/html;charset=UTF-8'>".getBytes());

response.setHeader("content-type", "text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
//String username=request.getParameter("username");
//username=new String(username.getBytes("iso8859-1"),"UTF-8");

posted @ 2022-02-05 02:19  wqheng6  阅读(43)  评论(0)    收藏  举报