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

servlet服务器端验证

编程:编写服务器端验证的程序

要求:(1)编写表单界面如下图:


(2)编写servlet程序对用户所输入的内容进行验证,要求用户名不能为空,密码与确认密码不能为空且长度在4-10之间,密码与确认密码相同。如果用户输入的条件符合要求,则请求转发到success.jsp,否则请求转发到error.jsp


(3)success.jsp用于输出用户所输入的用户名及密码。


(4)error.jsp用于输出用户输入时出错的信息。

 


├─.myeclipse
├─.settings
├─src
│  └─com
│      └─mars
└─WebRoot
    ├─META-INF
    └─WEB-INF
        ├─classes
        │  └─com
        │      └─mars
        └─lib

 

 

登录login.jsp

[html]
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%> 
<% 
    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>login</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> 
        <center> 
            <h1> 
                服务器端验证的程序 
            </h1> 
            <form action="login" method="get"> 
                <table border="1"> 
                    <tr> 
                        <td> 
                            用 户 名: 
                        </td> 
                        <td> 
                            <input type="text" name="username"> 
                        </td> 
                    </tr> 
 
                    <tr> 
                        <td> 
                            密    码: 
                        </td> 
                        <td> 
                            <input type="password" name="password1"> 
                        </td> 
                    </tr> 
 
                    <tr> 
                        <td> 
                            确认密码: 
                        </td> 
                        <td> 
                            <input type="password" name="password2"> 
                        </td> 
                    </tr> 
 
                    <tr> 
                        <td colspan="2"> 补充:Web开发 , Jsp ,

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,