# 用戶注冊實例
~~~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>用戶注冊</title>
</head>
<body>
<form action="service.jsp" method="POST">
用戶名:<input type="text" name="name" value=""/><br/>
密碼:<input type="password" name="password" value=""/><br/>
<input type="submit" value="注冊"/>
</form>
</body>
</html>
~~~
~~~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>服務</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name");
String password = request.getParameter("password");
boolean flag1 = false;
if(name != null && name.trim().length() <= 6) {
flag1 = true;
}
boolean flag2 = false;
if(password != null && password.trim().length() <= 6) {
flag2 = true;
}
if(flag1 && flag2) {
//往數據庫中插入信息
%>
<jsp:forward page="regSuccess.jsp">
<jsp:param value="<%=name %>" name="name"/>
<jsp:param value="<%=password %>" name="passwrod"/>
</jsp:forward>
<%
} else {
%>
<jsp:forward page="regError.jsp"></jsp:forward>
<%
}
%>
</body>
</html>
~~~
~~~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>成功注冊</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name");
%>
<h1>恭喜<%=name %>用戶,注冊成功!</h1>
</body>
</html>
~~~
~~~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>注冊失敗頁面</title>
</head>
<body>
<h1>用戶名或密碼格式有誤,請<a href="reg.jsp">重新注冊</a></h1>
</body>
</html>
~~~