当前位置: 首页 > news >正文

wordpress支持 nginxseo关键词优化指南

wordpress支持 nginx,seo关键词优化指南,万网的怎么做网站地图,做网站怎样做最近在做一个小项目,项目开发中需要实现一个登录验证功能,具体的要求就是,在Android端输入用户名和密码,在服务器端验证MySQL数据库中是否有此用户,实现之前当然首要的是,如何使Android端的数据发送到服务器…

最近在做一个小项目,项目开发中需要实现一个登录验证功能,具体的要求就是,在Android端输入用户名和密码,在服务器端验证MySQL数据库中是否有此用户,实现之前当然首要的是,如何使Android端的数据发送到服务器端,具体的实现方法:

服务器端:ManageServlet.java

public class ManageServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");String name = request.getParameter("name");String password = request.getParameter("password");System.out.println("用户名:"+name+"  密码:"+password);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {}}

 在这里实现的仅仅是把用户端的数据在控制台打印出来,相信学过jsp开发的大神,剩下的数据验证应该不在话下,在此不再赘述。

接下来就是Android端了:

主activity:MainActivity.java

public class MainActivity extends Activity {private  EditText textname = null;private  EditText textpassword = null;private  Button button = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);textname = (EditText)findViewById(R.id.name);textpassword = (EditText)findViewById(R.id.password);button = (Button)findViewById(R.id.button);button.setOnClickListener(new mybuttonlistener());}class mybuttonlistener implements OnClickListener{boolean result=false;String name;String password;public void onClick(View v) {try {				name = textname.getText().toString();name = new String(name.getBytes("ISO8859-1"), "UTF-8");password = textpassword.getText().toString();password = new String(password.getBytes("ISO8859-1"), "UTF-8");} catch (UnsupportedEncodingException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}try {result = NewsService.save(name,password);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}if(result){Toast.makeText(MainActivity.this, R.string.ok, Toast.LENGTH_SHORT).show();}else{Toast.makeText(MainActivity.this, R.string.error, Toast.LENGTH_SHORT).show();}}}}

 布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="${relativePackage}.${activityClass}" ><LinearLayout android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/name" /><EditText android:id="@+id/name"android:layout_width="fill_parent"android:layout_height="wrap_content"android:hint="@string/playname"android:singleLine="true"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/password" /><EditText android:id="@+id/password"android:layout_width="fill_parent"android:layout_height="wrap_content"android:password="true"android:hint="@string/playpass"android:singleLine="true"/><Button android:id="@+id/button"android:layout_width="fill_parent"android:layout_height="wrap_content"android:onClick=""android:text="@string/submit"/></LinearLayout>
</RelativeLayout>

 用于向服务器端发送数据的service(NewsService):

public class NewsService {/*** 登录验证* @param name  姓名* @param password  密码* @return*/public static boolean save(String name, String password){String path = "http://192.168.1.104:8080/Register/ManageServlet";  Map<String, String> student = new HashMap<String, String>();student.put("name", name);student.put("password", password);try {return SendGETRequest(path, student, "UTF-8");} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}return false;}/*** 发送GET请求* @param path   请求路径* @param student   请求参数* @return  请求是否成功* @throws Exception*/private static boolean SendGETRequest(String path, Map<String, String> student, String ecoding) throws Exception{// http://127.0.0.1:8080/Register/ManageServlet?name=1233&password=abcStringBuilder url = new StringBuilder(path);url.append("?");for(Map.Entry<String, String> map : student.entrySet()){url.append(map.getKey()).append("=");url.append(URLEncoder.encode(map.getValue(), ecoding));url.append("&");}url.deleteCharAt(url.length()-1);System.out.println(url);HttpsURLConnection conn = (HttpsURLConnection)new URL(url.toString()).openConnection();conn.setConnectTimeout(100000);conn.setRequestMethod("GET");if(conn.getResponseCode() == 200){return true;}return false;}}

  红色的为自己电脑的IP地址。 

 因为需要连接网络,一定要在AndroidManifest.xml进行网络权限配置:

 <uses-permission android:name="android.permission.INTERNET"/>

  写到这里基本已经把Android向服务器端发送数据,给大家分享完毕,如有不对的地方还望指正。

转载于:https://www.cnblogs.com/AndroidJotting/p/3911441.html

http://www.lbrq.cn/news/2638747.html

相关文章:

  • 昆山网站建设推荐百度站长工具怎么关闭教程视频
  • 重庆网站建设设计公司哪家好百度推广登录入口
  • 做网站最常用的软件是什么2020国内十大小说网站排名
  • 网站url超链接怎么做最佳搜索引擎磁力
  • 京东联盟怎么做CMS网站百度信息流投放方式有哪些
  • 广州建设网站的公司哪家好每日精选12条新闻
  • 网做网站百度seo泛解析代发排名
  • 网站建设报价方案模板国际十大市场营销公司
  • 帮企业做网站的照片查询百度图片搜索
  • 网站建设分金手指排名十四不屏蔽的国外搜索引擎
  • 国外最新创意产品网站有哪些方面排名优化公司哪家靠谱
  • 附近那里有做网站的公司做网站一般多少钱
  • 网站建设及应用实施方案软文案例300字
  • 网站项目策划大纲网站公司
  • 什么更新wordpress河南关键词优化搜索
  • 做网站的书知乎免费创建属于自己的网站
  • 交河做网站价格亚马逊跨境电商个人开店
  • 我是做废品回收,最近有个变宝网主动联系我说是再生资源网站的,可信吗?做专业搜索引擎优化
  • 网站建设的功能有哪些建网站需要哪些步骤
  • 公司基础建设的意义湖南seo优化价格
  • 邢台哪里做网站湖南seo推广多少钱
  • 做的好的购物网站目前搜索引擎排名
  • 类网站建设淘宝代运营1个月多少钱
  • 莱芜做网站的商家有哪些常德今日头条新闻
  • 最便宜网站推广公司产品
  • 网站的主题网站浏览器
  • 沈阳网站做app推广公司
  • ubuntu server wordpress石家庄seo网站管理
  • 免费推广seo本溪seo优化
  • 靖江网站微信营销软件免费版
  • 【代码随想录day 14】 力扣 104.二叉树的最大深度
  • @CacheConfig​​当前类中所有缓存方法详解
  • WinForm 对话框的 Show 与 ShowDialog:阻塞与非阻塞的抉择
  • 北京-4年功能测试2年空窗-报培训班学测开-第七十天-面试第一天
  • 无人机未来的通信脉络:深度解析远距离无线通信模块的革新
  • 基于django的非物质文化遗产可视化网站设计与实现