Email 代码:
package itcast;
import java.io.Serializable;
public class Email implements Serializable {
private static final long serialVersionUID = 1L;
private String mailAdd;
private boolean email;
public Email() {
}
public Email(String mailAdd) {
this.mailAdd = mailAdd;
}
public boolean isEmail() {
String regex = "\\w+\\x40\\w+\\x2e\\w+";
if (mailAdd.matches(regex)) {
email = true;
}
return email;
}
public String getMailAdd(){
return mailAdd;
}
public void setMailAdd(String mailAdd){
this.mailAdd = mailAdd;
}
}
index代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"
errorPage="error.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'error.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="result.jsp">
邮箱系统: <input type="text" name="mailAdd"> <br> <input
type="submit">
</form>
</body>
</html>
result代码:
<%@ page language="java" import="java.util.* " pageEncoding="UTF-8"%>
<%@page import="itcast.Email"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'result.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String mailAdd = request.getParameter("mailAdd");
itcast.Email email = new itcast.Email(mailAdd);
if(email.isEmail()){
out.print(mailAdd + "<br>是一个标准的邮箱地址!<br>");
}else{
out.print(mailAdd + "<br>不是一个标准的邮箱地址!<br>");
}
%>
<a href="index.jsp">返回</a>
</body>
</html>