servlet服务器端验证(9)
来源:未知 责任编辑:责任编辑 发表时间:2014-02-02 17:48 点击:次
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class login extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
request.setCharacterEncoding("GBK");
//String name = request.getParameter("username");
String newname = new String(request.getParameter("username").getBytes("ISO-8859-1"),"GBK");
String password1 = request.getParameter("password1");
String password2 = request.getParameter("password2");
ArrayList l = new ArrayList();
if (newname.equals("") || newname.equals(null)) {
l.add("用户不为空");
}
if (password1== null || password1.length() < 4 || password1.length() > 10) {
l.add("密码的长度4-10位");
}
if (password2 == null || password2.length() < 4 || password2.length() > 10) {
l.add("确认密码的长度4-10位");
}
if (password1 != null && password2 != null
&& !password1.equals(password2)) {
l.add("密码和确认密码应该一致");
}
if (l.isEmpty()) {
request.setAttribute("name", newname);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>