编写一个JSP页面,实现根据一个人 18 位身份证显示生日的功能,要求把表达式,小脚本全部用到,

 编写思路:

  1. 身份证信息需要集合来存储,可用Set或者List, 将身份证号加入到集合中去,
  2. 通过循环(Iterator for循环)来遍历身份证,取出每个身份号,
  3. 通过字符串的方法取得年月日:

substring(int beginIndex, int endIndex) 
          返回一个新字符串,它是此字符串的一个子字符串。

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>身份证</title>
</head>
<body>
<% String id[]={"320483199503046516","320483199503046517"}; %>
<table border="1">
<tr bgcolor="pink"><td>身份证</td><td>生日</td></tr>
<% for(int i=0;i<id.length;i++){ %>
    <tr>
    <td><%=id[1] %></td>
    <td><%=id[i].substring(6,10) %>-<%=id[i].substring(10,12) %>-
    <%=id[i].substring(12,14) %></td>
    </tr>
    <%}
%>
</table>
</body>
</html>

 

原文地址:https://www.cnblogs.com/sunstudy/p/12313705.html