server端封装json:
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
PrintWriter out= response.getWriter();
response.setContentType("text/html;charset=gbk");
System.out.println("doget");
String method=request.getParameter("method");
Map<String, Object> map = new HashMap<String, Object>();
if("selectUrl".equals(method)){
String mechid = request.getParameter("mechid");//获得从android端传过来的参数
Mechine mechine = iUser.selectUrl(mechid);//logo_picurl,background_picurl,AboutusUrl三张图地址
List<BigPic> bigpics = iUser.selectBig(mechid);
List<SmallPic> smallPics = iUser.selectSmall(mechid);
List<LunboPic> lunboPics = iUser.selectLunBo(mechid);
map = new HashMap<String, Object>();
map.put("logourl", mechine.getLogoUrl());
map.put("backurl", mechine.getBackUrl());
map.put("abouturl", mechine.getAboutusUrl());
map.put("bigs", bigpics);
map.put("smalls", smallPics);
map.put("lunbos", lunboPics);
JSONObject.fromObject(map).write(out);//把值封装成json格式
out.close();
out = null;
}
}
@Override
public Mechine selectUrl(String id) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
//String logoUrl = null;
Mechine mechine = new Mechine();
try {
conn = JdbcUtils.getConnection();
String sql = "SELECT * FROM [VenMaDB_Iked].[dbo].[P_MachineInfo] WHERE id = ?";
ps = conn.prepareStatement(sql);
</