android远程连接mysql数据库连接_Android 怎么连接远程数据库-百度经验

然后编写struts.xml文件,并放在WebRoot/WEB-INF/lib目录下:如下代码: View Code <?xml version="1.0" encoding="UTF-8"?>   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"    "http://struts.apache.org/dtds/struts-2.0.dtd">                                                                           配置好后,我们再根据标签内容来编写action。方法为method对应的login,类名为loginAction,?注意:包继承为:json-default ,输出结果类型为json如下: View Code public class loginAction extends ActionSupport implements                          ServletRequestAware,ServletResponseAware {    /**     *      */    private static final long serialVersionUID = 1L;    HttpServletRequest request;    HttpServletResponse response;    public void setServletRequest(HttpServletRequest request) {     this.request=request;    }    public void setServletResponse(HttpServletResponse response) {        this.response=response;    }    public void  login(){          try {             //HttpServletRequest request =ServletActionContext.getRequest();             // HttpServletResponse response=ServletActionContext.getResponse();             this.response.setContentType("text/html;charset=utf-8");             this.response.setCharacterEncoding("UTF-8");                 if(this.request.getParameter("username").equals("123456")){                      this.response.getWriter().write("真的很奇怪,日本人!");                 }else if(this.request.getParameter("username").equals("zhd")){                     this.response.getWriter().write("没有错,我就是东子哥!");                 }else{                     this.response.getWriter().write("我就是东子哥!");                 }            //将要返回的实体对象进行json处理                    //  JSONObject json=JSONObject.fromObject(this.getUsername());                  //输出格式如:{"id":1, "username":"zhangsan", "pwd":"123"}                   //   System.out.println(json);                     //   this.response.getWriter().write(json.toString());            /**               JSONObject json=new JSONObject();                json.put("login", "login");                response.setContentType("text/html;charset=utf-8");               System.out.println(json);               byte[] jsonBytes = json.toString().getBytes("utf-8");               response.setContentLength(jsonBytes.length);               response.getOutputStream().write(jsonBytes);               **/            /**              JSONObject json=new JSONObject();                json.put("login", "login");               byte[] jsonBytes = json.toString().getBytes("utf-8");               response.setContentType("text/html;charset=utf-8");               response.setContentLength(jsonBytes.length);               response.getOutputStream().write(jsonBytes);               response.getOutputStream().flush();               response.getOutputStream().close();                 **/          } catch (Exception e) {             e.printStackTrace();        }        // return null;    }}

运行查看下: 当然你可以输入其他参数的URL

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值