Java 正则表达式

//aaa.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!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>Java正则表达式</title>
</head>
<body>
<a href="bbb.jsp?id=1">第一个</a>
<br/>
<a href="bbb.jsp?id=2">第二个</a>
<br/>
<%
		


%>
</body>
</html>




//bbb.jsp


<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.util.regex.*"%>
<!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>Java正则表达式</title>
</head>
<body>
<%
		
	String id=request.getParameter("id");
	String pattern="[0-9]";
	Pattern p=Pattern.compile(pattern);
	Matcher m=p.matcher(id);
	boolean result=m.matches();
	if(result==true){
		out.println("估计是个真的吧");
	}else{
		out.println("估计是水货");
	}
		

%>
</body>
</html>

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