java异步方式实现登录

网友投稿 237 2023-07-16


java异步方式实现登录

本文实例为大家分享了java异步登录的具体代码,供大家参考,具体内容如下

1.LoginServletAjax.java

package com.scce.servlet;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import com.scce.dao.AdminUserDao;

import com.scce.pojo.AdminUser;

public class LoginServletAjax extends HttpServlet {

@Override

protected void service(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

request.setCharacterEncoding("utf-8");

response.setContentType("text/html;charset=utf-8");

String method = request.getMethod();

if (method.equals("POST")) {

doLoginAjax(request, response);

} else if (method.equals("GET")) {

}

}

public void doLoginAjax(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

PrintWriter out = response.getWriter();

// 用户名

String username = request.getParameter("username");

// 密码

String password = request.getParameter("password");

String msg = "";

AdminUserDao adminUserDao = new AdminUserDao();

AdminUser adminUser = adminUserDao.queryUser(username, password);

if (adminUser != null) {

msg="登录成功!";

String jsonObj= JSONObject.fromObject(adminUser).toString();

out.print("{\"Msg\":\""+msg+"\",\"rows\":"+jsonObj+"}");

System.out.println("{\"Msg\":\""+msg+"\",\"rows\":"+jsonObj+"}");

} else {

msg="用户名或者密码不正确!";

out.print("{\"Msg\":\""+msg+"\"}");

}

out.flush();

out.close();

}

}

2.test2.html

type="text/css">

用户名:

class="easyui-validatebox textbox">

http://

密码:

class="easyui-validatebox textbox" type="password">

用户信息加载中......

src="../video/B4934A0C53FC55703BFE3F6843E66166.mp4" type="video/mp4">

Your browser does not support the video tag.

src="../video/B4934A0C53FC55703BFE3F6843E66166.mp4" type="video/mp4">

Your browser does not support the video tag.

以上就是本文的全部内容,希望对大家学习java程序设计有所帮助。


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:详解Java中的迭代迭代器Iterator与枚举器Enumeration
下一篇:30分钟快速掌握Bootstrap框架
相关文章

 发表评论

暂时没有评论,来抢沙发吧~