JSP根据身份证号码计算生日
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>birthday</title> 6 </head> 7 8 <body> 9 <table> 10 <tr><td>身份证</td><td>生日</td></tr> 11 <% String id = "010020198810092211" ; 12 String birth = id.substring(6,14); 13 %> 14 <tr><td>010020198810092211</td><td><% out.print(birth); %></td></tr> 15 <% String id2 = "010020199009302211" ; 16 String birth2 = id2.substring(6,14); 17 %> 18 <tr><td>010020199009302211</td><td><% out.print(birth2); %></td></tr> 19 </table> 20 </body> 21 </html>
虽然写好了,感觉可弱智了,我的方案,呵呵
改进方案:
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>birthday</title> 6 </head> 7 8 <body> 9 <table> 10 <tr><td>身份证</td><td>生日</td></tr> 11 <%! 12 public String birthJisuan(String id){ 13 String birth = id.substring(6,14); 14 return birth; 15 } 16 %> 17 <tr><td>010020198810092211</td><td><%=birthJisuan("010020198810092211") %></td></tr> 18 <tr><td>010020199009302211</td><td><%=birthJisuan("010020199009302211") %></td></tr> 19 </table> 20 </body> 21 </html>
感觉稍稍进步了一点,呵呵