Tomcat安装和部署到MyEclipse
Tomcat安装:
1.配置环境变量:
建立系统环境变量---->CATALINA_HOME
值为:D:\developInstall\apache-tomcat-7.0.40-windows-x86\apache-tomcat-7.0.40
这个的前提是配置好JAVA_HOME,然后在Path路径下配置;%CATALINA_HOME%\bin
2.网页输入http://localhost:8080/出现Tomcat猫就成功了
3.配置部署Tomcat服务器:
图(1)
图(2)
图(3)
图(4)
图(5)
图(6)
图(7)
4.解决乱码:
(1)服务端:
1 /**解决服务器端乱码*/
2 String name=req.getParameter("name");
3 String newName=new String(name.getBytes("ISO-8859-1"),"UTF-8");
4 System.out.println("newName="+newName);
(2)客户端:
1 /**解决客户端乱码*/
2 resp.getOutputStream()
3 .write(JSONUtils.fromObject(map3).toString().getBytes("UTF-8"));
5.使用Json数据格式返回:
/**
*
{'name':'张三','age':2}
*/
Map<String,Object> map1 = new HashMap<String,Object>();
map1.put("name", "张三");
map1.put("age", 2);
System.out.println(JSONUtils.fromObject(map1));
/**
{'dd':1.3,'arr':[0,1,2,3],'ff':1.3,'ttt':true,'name':'张三','date':'2017-03-16','blog':'http://www.sojson.com/blog/'}
*/
JSONUtils util = new JSONUtils();
util.put("name", "张三");
util.put("blog", "http://www.sojson.com/blog/");
util.put("ttt", true);
util.put("dd", 1.3d);
util.put("ff", 1.3f);
util.put("date", new java.util.Date());
int[] a = new int[] { 2, 3, 4, 5 };
util.put("arr", a);
System.out.println(util);
/**
*
{'data':{'likeList':[{'imgUrl':'图片地址','imgList':[{'imgUrl':'图片地址列表----0'},{'imgUrl':'图片地址列表----1'},{'imgUrl':'图片地址列表----2'}],'name':'图片名称'}],'brandId':'品牌id'}}
/
Map<String,Object> map3 = new HashMap<String,Object>();
Map<String,Object> data = new HashMap<String,Object>();
List<Object>likeList=new ArrayList<Object>();
Map<String,Object> likeListItem = new HashMap<String,Object>();
likeListItem.put("imgUrl", "图片地址");
likeListItem.put("name", "图片名称");
List<Object>imgList=new ArrayList<Object>();
for (int i = 0; i < 3; i++) {
Map<String,Object> imgListItem = new HashMap<String,Object>();
imgListItem.put("imgUrl", "图片地址列表----"+i);
imgList.add(imgListItem);
}
likeListItem.put("imgList", imgList);
likeList.add(likeListItem);
data.put("brandId", "品牌id");
data.put("likeList",likeList );
map3.put("data", data);
System.out.printf(JSONUtils.fromObject(map3));
map3打印结果如下