欢迎来到天天文库
浏览记录
ID:37899029
大小:766.50 KB
页数:12页
时间:2019-06-02
《Tomcat 上如何部署Servlet及Android中如何与服务器通信》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Tomcat上如何部署Servlet及Android中如何与服务器通信下载Tomcat并安装ApacheTomcatpowersnumerouslarge-scale,mission-criticalwebapplicationsacrossadiverserangeofindustriesandorganizations.SomeoftheseusersandtheirstoriesarelistedonthePoweredBywikipage.ApacheTomcat,Tomcat,Apache,theApachefeather,andtheApacheTomcatprojectlogoa
2、retrademarksoftheApacheSoftwareFoundation.IaddthisEnglishdescriptionduetojunkbaiduwenku`srulesEclipse中编写Servlet代码:创建java工程packagecom.webservice.test;importjava.io.IOException;importjava.io.PrintWriter;importjava.util.ArrayList;importjava.util.List;importjavax.servlet.ServletException;importjavax.ser
3、vlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importnet.sf.json.JSONArray;importnet.sf.json.JSONObject;publicclassWebserviceTestextendsHttpServlet{privatestaticfinallongserialVersionUID=512;privateListlist;protectedvoiddoPost(
4、HttpServletRequestreq,HttpServletResponseresponse)throwsServletException,IOException{doGet(req,response);}protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresponse)throwsServletException,IOException{response.setContentType("test/plain");response.setCharacterEncoding("UTF-8");PrintWriterou
5、tPrintWriter=response.getWriter();JSONArrayjsonArray=newJSONArray();list=initData();for(Studentbean:list){JSONObjectjsonObject=newJSONObject();try{jsonObject.put("stunum",bean.getStunum());jsonObject.put("name",bean.getName());jsonObject.put("chinese",bean.getChinese());jsonObject.put("math",bean.ge
6、tMath());jsonObject.put("english",bean.getEnglish());}catch(Exceptione){e.printStackTrace();}jsonArray.put(jsonObject);}outPrintWriter.write(jsonArray.toString());outPrintWriter.flush();outPrintWriter.close();}privateListinitData(){Liststudentlist=newArrayList();Studentstu
7、One=newStudent();stuOne.setStunum(10001);stuOne.setName("sloden");stuOne.setChinese(82);stuOne.setMath(88);stuOne.setEnglish(80);studentlist.add(stuOne);StudentstuTwo=newStudent();stuTwo.setStunum(100
此文档下载收益归作者所有