首页 > 编程语言 >利用JavaWeb,简单实现身份ID校验系统

利用JavaWeb,简单实现身份ID校验系统

时间:2022-09-26 20:36:05浏览次数:55  
标签:String charAt int 校验 substring flag ID JavaWeb

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Welcome CheckID System</title>
    <style type="text/css">
        .st1{
            color:blue;
        }
        .st2{
            color: orangered;
        }
        .st3{
            color: magenta;
        }
    </style>
</head>
<body>
<div align="center">
<form action="" methed="get">
    <h1 class="st1">请输入您的身份证号:</h1>
    <br>
    <h2 class="st2">Please enter your ID number</h2>
    <br>
    <h4 class="st3">注:我们会运用<a href="https://www.98158.com/bjhuzheng/shenfenzheng/737.html"> 国家身份证ID算法</a>对您的身份ID进行核查</h4>
    <h5 class="st3">详情参考-><a href="http://www.npc.gov.cn/npc/c12435/201110/6a4ca1c55fbe4ef58927ea6180305b15.shtml ">《中华人民共和国居民身份证法》</a></h5>
        <br>
        <input id="id" name="id" type="text" style="width: 200px; height: 75px;" size="10" required onchange="this.form.submit();"/>
    <br><br><br><br>
<%
    request.setCharacterEncoding("UTF-8");//识别汉字等
    String ID = request.getParameter("id");//输入
    if(ID!=null) {
        int flag = 0;
        int[] c= new int[18];
        if(ID.length()==18){
        String a1 = ID.substring(0,1);
        int b1;
        b1 = a1.charAt(0)-48;
        if(b1>9)
        {
            flag=1;
            c[1]=1;
        }
        String a2 = ID.substring(1,2);
            int b2;
            b2 = a2.charAt(0)-48;
            if(b2>9)
            {
                flag=1;
                c[2]=2;
            }
        String a3 = ID.substring(2,3);
            int b3;
            b3 = a3.charAt(0)-48;
            if(b3>9)
            {
                flag=1;
                c[3]=3;
            }
        String a4 = ID.substring(3,4);
            int b4;
            b4 = a4.charAt(0)-48;
            if(b4>9)
            {
                flag=1;
                c[4]=4;
            }
        String a5 = ID.substring(4,5);
            int b5;
            b5 = a5.charAt(0)-48;
            if(b5>9)
            {
                flag=1;
                c[5]=5;
            }
        String a6 = ID.substring(5,6);
            int b6;
            b6 = a6.charAt(0)-48;
            if(b6>9)
            {
                flag=1;
                c[6]=6;
            }
        String a7 = ID.substring(6,7);
            int b7;
            b7 = a7.charAt(0)-48;
            if(b7>9)
            {
                flag=1;
                c[7]=7;
            }
        String a8 = ID.substring(7,8);
            int b8;
            b8 = a8.charAt(0)-48;
            if(b8>9)
            {
                flag=1;
                c[8]=8;
            }
        String a9 = ID.substring(8,9);
            int b9;
            b9 = a9.charAt(0)-48;
            if(b9>9)
            {
                flag=1;
                c[9]=9;
            }
        String a10 = ID.substring(9,10);
            int b10;
            b10 = a10.charAt(0)-48;
            if(b10>9)
            {
                flag=1;
                c[10]=10;
            }
        String a11 = ID.substring(10,11);
            int b11;
            b11 = a11.charAt(0)-48;
            if(b11>9)
            {
                flag=1;
                c[11]=11;
            }
        String a12 = ID.substring(11,12);
            int b12;
            b12 = a12.charAt(0)-48;
            if(b12>9)
            {
                flag=1;
                c[12]=12;
            }
        String a13 = ID.substring(12,13);
            int b13;
            b13 = a13.charAt(0)-48;
            if(b13>9)
            {
                flag=1;
                c[13]=13;
            }
        String a14 = ID.substring(13,14);
            int b14;
            b14 = a14.charAt(0)-48;
            if(b14>9)
            {
                flag=1;
                c[14]=14;
            }
        String a15 = ID.substring(14,15);
            int b15;
            b15 = a15.charAt(0)-48;
            if(b15>9)
            {
                flag=1;
                c[15]=15;
            }
        String a16 = ID.substring(15,16);
            int b16;
            b16 = a16.charAt(0)-48;
            if(b16>9)
            {
                flag=1;
                c[16]=16;
            }
        String a17 = ID.substring(16,17);
            int b17;
            b17 = a17.charAt(0)-48;
            if(b17>9)
            {
                flag=1;
                c[17]=17;
            }
        String a18 = ID.substring(17,18);
            int b18;
            b18 = a18.charAt(0)-48;
        int sum=b1*7+b2*9+b3*10+b4*5+b5*8+b6*4+b7*2+b8*1+b9*6+b10*3+b11*7+b12*9+b13*10+b14*5+b15*8+b16*4+b17*2;
        int check = sum % 11;
        int check1,check2;
        if(check==0)
        {
            check1=1;
            if(b18==check1)
            {
                out.print("您输入的是正确的身份证号");
            }
            else
            {
                out.print("您输入的身份证号错误!");
            }
        }
        else if(check==1)
        {
            check1=0;
            if(b18==check1)
            {
                out.print("您输入的是正确的身份证号");
            }
            else
            {
                out.print("您输入的身份证号错误!");
            }
        }
        else if(check==2)
        {
            check1=40;
            check2=72;
            if(b18==check1 || b18==check2)
            {
                out.print("您输入的是正确的身份证号");
            }
            else
            {
                out.print("您输入的身份证号错误!");
            }
        }
        else if(check>2)
        {
            int check3=1;
            for(int i=3,j=9;i<=10;i++,j--)
            {
                if(check==i)
                {
                    check1=j;
                    if(b18==check1&&flag==0)
                    {
                        out.print("您输入的是正确的身份证号");
                        check3=0;
                    }
                }
            }
            if(check3==1&&flag==0)
            {
                out.print("您输入的身份证号错误!");
            }
            else if(flag==1) {
                out.print("您输入的身份证号不合法!");
                for (int i = 1; i <= 17; i++) {
                    if(c[i]!=0){
                    out.print("-----且不合法的位数是:第"+c[i]+"位!");
                }}
            }
        }

    }
        else {
            out.print("身份证号位数有问题");
        }
    }
%>

</form>
    <br>
    <br>
</div>
</body>
</html>

  

标签:String,charAt,int,校验,substring,flag,ID,JavaWeb
From: https://www.cnblogs.com/5ran2yl/p/16732282.html

相关文章

  • 分布式ID生成方案
    分布式ID策略为什么要用分布式ID?在我们业务数据量不大的时候,单库单表完全可以支撑现有业务,数据再大一点搞个MySQL主从同步读写分离也能对付。但随着数据日渐增长,主从......
  • CentOS7 - 软raid
    前言参考链接:https://blog.csdn.net/u011130086/article/details/119172119有台服务器没有RAID卡,虽然数据不太重要,但是真要丢失了还是会存在一些麻烦。因此考虑用......
  • Failed to find a valid digest in the 'integrity' attribute for resource
    一、Bootstrap 引入报错在使用bootstrap过程中发现无法使用下拉导航栏,或者是显示不出效果。Failedtofindavaliddigestinthe'integrity'attributeforresour......
  • width和max-width区别
    https://www.w3school.com.cn/css/css_max-width.asp 使用max-width可以改善浏览器对小窗口的处理。例如div宽度是500px,当宽度小于500时,max-width对应的窗口显示的内......
  • 「国产系统」Tubian 0.2,兼容Windows和Android的GNU/Linux系统!
    Tubian是我的自用系统整理而成的Linux发行版,基于Debian,对Windows和Android应用提供了较为完善的兼容。可以直装QQTIM微信MSOFFICE等大量Windows应用,并且几乎实现对Android......
  • display:none和visibility:hidden区别
    二者都是将元素属性隐藏,但不同的是,display:none隐藏后,不占位置;而visibility:hidden隐藏后,原位置仍然存在   display:none;  visibility:hidden;  ......
  • Android activity控制RecyclerView中Adapter中的控件的显示和隐藏
    在实际开发中,我们通常会遇到,通过外面的控件去控制Adapter里面的checkbox按钮的显示或隐藏: 需求就是:点击批量选择显示checkbox,再次点击隐藏。 思路:在activity中,定义......
  • java8 idea+struts2+spring+hiberate
    前置ideajdk8u202tomcat8.5.82创建项目file->new->project->mavenarthetype->webapppom.xmlstruct2dependency点击查看代码<projectxmlns="http:/......
  • [Oracle] LeetCode 32 Longest Valid Parentheses 思维
    Givenastringcontainingjustthecharacters'('and')',findthelengthofthelongestvalid(well-formed)parenthesessubstring.Solution不妨把左括号记为......
  • provide 和 inject 用法及原理
    在父子组件传递数据时,通常使用的是props和emit,父传子时,使用的是props,如果是父组件传孙组件时,就需要先传给子组件,子组件再传给孙组件,如果多个子组件或多个孙组件使用时,......