Java写的一个数字匹配的正则表达式

//abin.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hello</title>
</head>
<body>
<a href="page.jsp?id=1">第一个</a>
<br/>
<a href="page.jsp?id=2">第二个</a>
<br/>
<a href="page.jsp?id=3">第三个</a>
<br/>
<a href="page.jsp?id=4">第四个</a>
<br/>
<a href="page.jsp?id=5">第五个</a>
<br/>
<a href="page.jsp?id=6">第六个</a>
<br/>
<a href="page.jsp?id=7">第七个</a>
<br/>
<a href="page.jsp?id=8">第八个</a>
<br/>
<a href="page.jsp?id=9">第九个</a>
<br/>
<a href="page.jsp?id=10">第十个</a>
<br/>

</body>
</html>




//page.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="java.sql.*,java.util.*,java.util.regex.Matcher,java.util.regex.Pattern" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Mysql Page</title>
</head>
<body>
<%
	String td=request.getParameter("id");
	String pattern="[0-9]";
	Pattern p=Pattern.compile(pattern);
	Matcher m=p.matcher(td);
	boolean result=m.matches();
	if(result){
	int tid=Integer.parseInt(td);
		switch(tid){
			case 1:
			out.println("第一个,哈哈,朋友");
			break;
			case 2:
			out.println("第二个,哈哈,朋友");
			break;
			case 3:
			out.println("第三个,哈哈,朋友");
			break;
			case 4:
			out.println("第四个,哈哈,朋友");
			break;
			case 5:
			out.println("第五个,哈哈,朋友");
			break;
			case 6:
			out.println("第六个,哈哈,朋友");
			break;
			case 7:
			out.println("第七个,哈哈,朋友");
			break;
			case 8:
			out.println("第八个,哈哈,朋友");
			break;
			case 9:
			out.println("第九个,哈哈,朋友");
			break;
			
			default:
			out.println("输出的不是0-9之间的数字");
			break;
		}
	}else{
		out.println(result);
		out.println(td);
	}

 %>
</body>
</html>

你可能感兴趣的:(java,sql,jsp,mysql,正则表达式)