ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# 用户注册实例 ~~~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> ~~~