一.常用数据类型转换
other to String
public static void main(String[] args) {
int m=110;
String s=String.valueOf(m);
System.out.println(s);
}
String to other(int,float,doubble,,,,);
公式:other i=other.parseother(String);
String to Date
公式:SimpleDateFormat sd=new SimpleDateFormat(yyyy-MM-dd(日期格式))
Date date=sd.parse(String);
Date to String
公式:String string=sd.format(Date);
二。日期类型之间的转换
sql.Date= new sql.Date(util.Date.getTime());
三。汉字字符的转换;
方法one: 在Servlet的接受语句中,将该语句的接受对象(设为string),做如下操作:
方法two:标准写法,在接受数据的页面之前,加上四大基础对象之一的filter(过滤器),
在dofilter方法中,加入如下语句:
request。setcharacterEncoding(“UTF-8”);
之后在web。xmail,中配置如下信息:
<filter>
<filter-name>filtername</filter-name>
<filter-class>filter的位置</filter-class>
</filter>
<filter-maping>
<filter-name>filtername</filter-name>
<url-pattern>/web地址(*所有的页面都过滤)</url-pattern>
</filter-maping>
转载于:https://blog.51cto.com/7865145/1296624