手机版
你好,游客 登录 注册
背景:
阅读新闻

Android Tomcat 的应用之服务器部分

[日期:2012-03-05] 来源:Linux社区  作者:chenlong12580 [字体:大 中 小]

最后就是实现servlet,主要是处理来自客户端的查询请求和返回查询结果:

  1. public class Login extends HttpServlet {  
  2.   
  3.     public void doGet(HttpServletRequest request, HttpServletResponse response)  
  4.             throws ServletException, IOException {  
  5.         response.setContentType("text/html");  
  6.         PrintWriter out = response.getWriter();  
  7.         UserDao dao = new UserDaoImpl();  
  8.         // 获得客户端请求参数   
  9.         String username = request.getParameter("username");  
  10.         String password = request.getParameter("password");  
  11.           
  12.         User u = dao.login(username, password);  
  13.         if(u!=null){  
  14.             out.print("登录成功");  
  15.         }else{  
  16.             out.print("null");  
  17.         }  
  18.         out.flush();  
  19.         out.close();  
  20.     }  
  21.       
  22.   
  23.     public void doPost(HttpServletRequest request, HttpServletResponse response)  
  24.             throws ServletException, IOException {  
  25.         doGet(request,response);  
  26.     }  
  27.     public void init() throws ServletException {  
  28.     }  
  29.       
  30.     public LoginServlet() {  
  31.         super();  
  32.     }  
  33.   
  34.     public void destroy() {  
  35.         super.destroy();  
  36.     }  
  37.   
  38. }  

至于Tomcat和MySQL的配置、使用。http://www.linuxidc.com/topicnews.aspx?tid=11 有不少教程!至此就可以实现登录模块了!

linux
相关资讯       Tomcat  Android开发教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款