解决方案 »

  1.   

    客户端 用户名 和 密码验证 比较好的就是用ajax  
      

  2.   

    登录的 login.jsp
    <%@ page contentType="text/html;charset=gbk" language="java" %>
    <%@ page import="java.util.*"%>
    <%@ page import="com.wgh.UserInfo"%>
    <%@ page import="com.wgh.UserListener"%>
    <%
    request.setCharacterEncoding("gbk");
    String username=request.getParameter("username"); //获得登录用户名
    UserInfo user=UserInfo.getInstance(); //获得UserInfo类的对象
    session.setMaxInactiveInterval(600); //设置Session的过期时间为10分钟
    Vector vector=user.getList();
    boolean flag=true; //标记是否登录的变量
    //判断用户是否登录
    if(vector!=null&&vector.size()>0){
    for(int i=0;i<vector.size();i++){
    if(user.equals(vector.elementAt(i))){
    out.println("<script language='javascript'>alert('该用户已经登录');window.location.href='index.jsp';</script>");
    flag=false;
    break;
    }
    }
    }
    //保存用户信息
    if(flag){
    UserListener ul=new UserListener();
    ul.setUser(username);
    session.setAttribute("user",ul);
    session.setAttribute("username",username);
    user.addUser(ul.getUser());
    //保存当前登录的用户名
    session.setAttribute("loginTime",new Date().toLocaleString()); //保存登录时间
    //重定向
    response.sendRedirect("MessagesAction?action=loginRoom");
    }
    %>
      

  3.   

    var net=new Object(); //定义一个全局变量net
    //编写构造函数
    net.AjaxRequest=function(url,onload,onerror,method,params){
      this.req=null;
      this.onload=onload;
      this.onerror=(onerror) ? onerror : this.defaultError;
      this.loadDate(url,method,params);
    }
    //编写用于初始化XMLHttpRequest对象并指定处理函数,最后发送HTTP请求的方法
    net.AjaxRequest.prototype.loadDate=function(url,method,params){
      if (!method){
        method="GET";
      }
      if (window.XMLHttpRequest){
        this.req=new XMLHttpRequest();
      } else if (window.ActiveXObject){
        this.req=new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (this.req){
        try{
          var loader=this;
          this.req.onreadystatechange=function(){
            net.AjaxRequest.onReadyState.call(loader);
          }      this.req.open(method,url,true);
      if(method=="POST"){
    this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
      }
          this.req.send(params);
        }catch (err){
          this.onerror.call(this);
        }
      }
    }//重构回调函数
    net.AjaxRequest.onReadyState=function(){
      var req=this.req;
      var ready=req.readyState;
      if (ready==4){
        if (req.status==200 ){
          this.onload.call(this);
        }else{
          this.onerror.call(this);
        }
      }
    }
    //重构默认的错误处理函籹
    net.AjaxRequest.prototype.defaultError=function(){
      alert("错误数据\n\n回调状态:"+this.req.readyState+"\n状态: "+this.req.status);
    }
      

  4.   

    这个比简单的注册 登录复杂  源码就看
     
    http://download.csdn.net/detail/cheney20121/4960289
     包括一些登录 和注册的源代码
      

  5.   

    其实我用在网络爬虫过程中用到的,是爬外国的网站,可有些内容是需要认证用户名和密码,现在用户名和密码已经有了,可是尝试了好几种方法,在java后台去匹配登录,但好像是跨域了,现在准备用cookies来做一下,纠结啊!!!