当前位置:编程学习 > JS >>

登陆界面(jsp)客户端验证

[html] 
<pre class="html" name="code">第二步:通过servlet处理</pre><pre class="html" name="code"> </pre><pre class="html" name="code"> </pre><pre class="html" name="code">import java.io.IOException; 
import java.io.PrintWriter; 
import java.util.ArrayList; 
import java.util.List; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
 
public class validateServlet extends HttpServlet { 
 
    public void doGet(HttpServletRequest req, HttpServletResponse resp) 
            throws ServletException, IOException { 
            //获得用户的信息 
        String username=req.getParameter("username"); 
        String password=req.getParameter("password"); 
        String repassword=req.getParameter("repassword"); 
        String shuoming=req.getParameter("shuoming");//说明 
        String []易做图=req.getParameterValues("易做图");//获得性别 
        String []aihao=req.getParameterValues("aihao");//获得兴趣 
        String []add=req.getParameterValues("add");//获得地址 
         
 
         
        //String repassword=req.getParameter("repassword"); 
        //String repassword=req.getParameter("repassword"); 
         
        List<String> list=new ArrayList<String>(); 
        List<String> xingqu=new ArrayList<String>(); 
        if (null=="username"||"".equals(username)) 
        { 
            list.add("there can't be a blank!");             
        } 
        if (password==null||password.length()<6||password.length()>10) 
        { 
            list.add(" the password's length must Between6 and 10 !"); 
        } 
        if (repassword==null||repassword.length()<6||repassword.length()>10) 
        { 
            list.add(" the password's length must Between 6 and 10!"); 
        } 
        if (password!=null&&repassword!=null&&!password.equals(repassword)) 
        { 
            list.add("the two password isn't the same!"); 
             
        } 
         
        if (list.isEmpty()) 
        {  
            req.setAttribute("username",username); 
            req.setAttribute("password",password); 
            req.setAttribute("repassword",repassword); 
            req.setAttribute("shuoming",shuoming);//说明 
            for(int i=0;i<易做图.length;i++)//性别 
            req.setAttribute("易做图",易做图[i]); 
            //兴趣 
            for(int i=0;i<aihao.length;i++) 
            { 
                xingqu.add(aihao[i]); 
            } 
            req.setAttribute("aihao",xingqu+" "); 
            //地址 
            for(int i=0;i<add.length;i++) 
                req.setAttribute("add",add[i]); 
            //说明 
            req.getRequestDispatcher("success.jsp").forward(req,resp); 
             
        } 
        else 
        { 
            req.setAttribute("list",list); 
            req.getRequestDispatcher("unsuccess.jsp").forward(req,resp); 
        } 
         
         
     
    } 
 
     

</pre><br> 
最近在学习jsp先写了个登陆界面的例子 
<pre></pre> 
<pre class="html" name="code">第一步:</pre><pre class="html" name="code"> </pre><pre class="html" name="code"><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<html> 
    <head> 
        <title> 登录界面 </title> 
        <%--客户端验证服务器端验证未启动 --%> 
    &n
补充:Web开发 , Jsp ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,