标题:关于一个小小的ajax用于java web的问题
只看楼主
thegoodboy
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2016-6-4
 问题点数:0 回复次数:4 
关于一个小小的ajax用于java web的问题
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   <title>表单验证</title>   
   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
   <script type="text/javascript">
   
      function formcheck(){  
        var xmlHttpRequest;
      if(window.XMLHttpRequest){
        xmlHttpRequest = new XMLHttpRequest();
      }else{
        xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlHttpRequest.onreadystatechange=showresult;
        var url="FormCheck";
        var params="userid="+userid.value+"&userpwd="+userpwd.value;   
      xmlHttpRequest.open("POST",url, true);
      xmlHttpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
      xmlHttpRequest.send(params);
    }
    function showresult(){
        if (xmlHttpRequest.readyState == 4) {
            if (xmlHttpRequest.status == 200) {
          var info = xmlHttpRequest.responseText;
          result.innerHTML=info;
            }
        }
}
</script>
  </head>
  <body>
    请输入用户名:<input type="text" name="userid" onblur="formcheck()"/><br/>
    请输入密码 :<input type="password" name="userpwd"/><br/>
    <input type="button" value="登录" onclick="formcheck()"/>
    <div id="result"></div>   
  </body>
</html>



import
import
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//省略了导入包
public class FormCheck extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("utf-8");
        String userid=request.getParameter("userid");
        if(!"张三".equals(userid)){
            String mgs1="用户名不存在";
            out.print(mgs1);
            System.out.println(mgs1);
        }
        else{
            String userpwd=request.getParameter("userpwd");
            if(!"".equals(userpwd)){
                if("123".equals(userpwd))
                {
                    out.print("欢迎您");
                System.out.println("欢迎您");
                }
                else
                {
                    out.print("密码错误");
                System.out.println("密码错误");
                }
                }
            
        }
        
    }
}










搜索更多相关主题的帖子: PUBLIC content function javascript title 
2016-06-04 00:29
thegoodboy
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2016-6-4
得分:0 
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
    xmlns="http://java.
    xmlns:xsi="http://www.
    xsi:schemaLocation="http://java.
    http://java.
  <display-name></display-name>
<servlet>
    <servlet-name>FormCheck</servlet-name>
    <servlet-class>FormCheck </servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>FormCheck</servlet-name>
    <url-pattern>/FormCheck</url-pattern>
  </servlet-mapping>   
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

2016-06-04 00:30
thegoodboy
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2016-6-4
得分:0 
有没有高手救命啊 搞了好久了
2016-06-04 00:30
thegoodboy
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2016-6-4
得分:0 
2016-06-04 00:32
xss_wl
Rank: 5Rank: 5
等 级:禁止访问
威 望:3
帖 子:100
专家分:315
注 册:2016-10-15
得分:0 
不行就找我吧,我的扣扣:775420425,共同学习,共同进步!
2016-11-02 14:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-465576-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.127656 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved