Servlet 注册与提交作业

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录页</title>
<script type="text/javascript">
function check()
{
    var uid = document.getElementById("userid");
    if (uid.value == "")
        {
        alert("用户代码不能为空");

        return false;

        }
    if(uform.password.value == "")
        {
         alert("密码不能为空");

        return false;
        }
    return true;
    }

</script>

</head>
<body>
<form id="uform"  action="yanzheng"  method ="post" onsubmit="return check()">

用户:<input id="userid" type="text" name="userid" width="30" />

密码:<input id="password" type="password" name="password" width="30"/>

<input type="submit" value="登录">

<a href="zhuce.html">注册新用户</a>

</form>
</body>
</html>

login.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">

//在本页面对注册信息进行验证,使之不能为空
function check()
{
    var uid = document.getElementById("userid");
    if (uid.value == "")
        {
        alert("用户代码不能为空");

        return false;

        }
     if(uform.usermingc.value == "")
        {
         alert("用户名称不能为空");

        return false;
        }
    if(uform.password.value == "")
        {
         alert("密码不能为空");

        return false;
        }

    if(uform.quer.value != uform.password.value)
      {
       alert("登录密码和确认密码不一致");

       return false;
      }

    return true;
    }

</script>

</head>

<body>
<form id="uform" action ="saveUser" onsubmit="return check()" >

用户代码:<input id="userid" type="text" name="userid" width=30 >
<br><br>
用户名称:<input id="usermingc" type="text" name="username" width=30>
<br><br>
登录密码:<input id="password" type="password" name="password" width=30>
<br><br>
确认密码:<input id="quer" type="password" name="queren" width=30>
<br><br>
<input type="submit" value="提交">
</form>

</body>
</html>

zhuce.html

package com.hanqi;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hanqi.*;

/**
 * Servlet implementation class saveUser
 */
public class saveUser extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public saveUser() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setCharacterEncoding("GBK");

        String strUserid =  request.getParameter("userid");

        String strUsername =  request.getParameter("username");

        String strPW =  request.getParameter("password");

        if(strUserid == null ||strUserid.trim().length() == 0)
        {
            response.getWriter().append("账户不能为空");

            response.setHeader("refresh","3;URL=login.html");
        }

        else if(strUsername == null ||strUsername.trim().length() == 0)
        {
            response.getWriter().append("用户名不能为空");

            response.setHeader("refresh","3;URL=login.html");
        }

        else if(strPW == null ||strPW.trim().length() == 0)
        {
            response.getWriter().append("密码不能为空");

            response.setHeader("refresh","3;URL=login.html");
        }

        else{

            ServletContext application = this.getServletContext();

            Object obj = application.getAttribute(strUserid);

            if( obj != null)
             {
                response.getWriter().append("该用户已存在");

                response.setHeader("refresh","3;URL=login.html");
             }

            else
                {

                strUsername = new String(strUsername.getBytes("ISO-8859-1"),"UTF-8");

                User user = new User();

                user.setUserID(strUserid);

                user.setUserName(strUsername);

                user.setPassword(strPW);

                application.setAttribute(strUserid, user);

                response.getWriter().append("注册成功");

                response.setHeader("refresh","3;URL=login.html");

                }

        }

        response.getWriter().append("Served at: saveUser").append(request.getContextPath());
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

saveUser.java

package com.hanqi;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hanqi.*;

/**
 * Servlet implementation class yanzheng
 */
public class yanzheng extends HttpServlet {
    private static final long serialVersionUID = 1L;
    String strType = "";

    /**
     * @see HttpServlet#HttpServlet()
     */
    public yanzheng() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setCharacterEncoding("GBK");

        String strUserid = request.getParameter("userid");

        String strPW = request.getParameter("password");

        if (strUserid == null || strUserid.trim().length() == 0) {
            response.getWriter().append("账户不能为空");

            response.setHeader("refresh", "3;URL=login.html");
        }

        else if (strPW == null || strPW.trim().length() == 0) {
            response.getWriter().append("密码不能为空");

            response.setHeader("refresh", "3;URL=login.html");
        }

        else {
            ServletContext application = this.getServletContext();

            Object obj = application.getAttribute(strUserid);

            if (obj != null)
            {
                User user = (User) obj;

                String strUID = user.getUserID();

                String strUsername = user.getUserName();

                String strP = user.getPassword();

                if (strUserid.equals(strUID))
                {
                    if (strPW.equals(strP))
                    {
                        response.getWriter().append("欢迎" + strUsername + "登陆系统");
                    } else
                    {
                        response.getWriter().append("密码输入错误");

                        response.setHeader("refresh", "3;URL=login.html");
                    }
                } 

            }
            else
            {
                response.getWriter().append("该用户不存在");

                response.setHeader("refresh", "3;URL=login.html");
            }

        }

        // response.getWriter().append("Served at:
        // yanzheng").append(request.getContextPath());
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

yanzheng.java

package com.hanqi;

//关于用户的实体类
public class User {

    //用户代码
    private String UserID;

    public String getUserID()
    {
        return UserID;
    }

    public void setUserID(String userID)
    {
        this.UserID = userID;
    }

    //用户名称
    private String UserName;

    public String getUserName() {
        return UserName;
    }

    public void setUserName(String userName) {
        UserName = userName;
    }

    //密码
    private String Password;

    public String getPassword() {
        return Password;
    }

    public void setPassword(String password) {
        Password = password;
    }
}

User.java

时间: 2024-10-13 12:24:21

Servlet 注册与提交作业的相关文章

Spark源码系列(一)spark-submit提交作业过程

前言 折腾了很久,终于开始学习Spark的源码了,第一篇我打算讲一下Spark作业的提交过程.有不明白Spark的原理的话,有另外一位大牛已经写了一个系列的Spark的源码分析了,大家可以去参考他的,他的过程图画得非常好,他写过的我可能就不写了,实在没办法比人家写得更好. 下面给出他的地址: http://www.cnblogs.com/hseagle/p/3664933.html,屌丝们,赶紧去膜拜大神吧. 这个是Spark的App运行图,它通过一个Driver来和集群通信,集群负责作业的分配

oozie 提交作业时因请求资源不足而suspend的解决方法

1,环境情况 安装的CDH5.4,使用CM来管理各个组件(Yarn.Spark.HDFS.Hive.Oozie……). 2,在shell命令下提交Oozie作业 ①sudo –u hdfs hadoop fs –mkdir /user/cdhfive      创建一个专门的用户目录,这里为cdhfive ②sudo –u hdfs hadoop –chown –R cdhfive /user/cdhfive      权限更改 ③hadoop fs –put examples /user/cd

统计学生提交作业情况

在研一上学期当了C语言课程的助教,每周老师都会布置作业,同学们会把作业打包成压缩文件上传到学院ftp,我的任务是下载同学的作业并统计提交人数,抽样检查作业.学生的压缩文件按学号(9位).姓名.日期的格式命名,于是我想统计提交情况的任务可以用python来解决,以减轻我的工作量. 程序的基本思路是: 1.老师给我一个保存所有学生信息(学号.姓名)的excel表,我先把所有学生的学号保存到一个字典的key中,value初始化为0代表学生提交的次数 2.遍历提交的所有文件并取出学号,并在前面建好的字典

JSP中(servlet)如何使用定时作业Quartz框架

以下介绍的是在JSP或者servlet中使用定时作业Quartz框架,这篇文章是我大学第二次实习时写的,当时带我的师傅维护一个旧业务系统时需要定时作业处理,因为我之前大三实习的时候接触过,知道有这么个东西,所以师傅交给我处理,特意给我说让我整理出一个文档来交给他作为以后他的参考,因为之前是在spring中集成的,那比较简单实现,现在让我在JSP中实现,不是想象的那么顺利,利用一晚上搞定了,以下为我为师傅整理的参考文档,特意翻出来和分享给大家: 目录 1.JSP项目中引入4个jar包 1 2.we

2017-2018-1 20155305 《信息安全系统设计基础》第四周学习总结(课堂提交作业未来得及提交码云链接myod补充博客)

2017-2018-1 20155305 <信息安全系统设计基础>第四周学习总结(课堂提交作业未来得及提交码云链接myod补充博客) 课堂提交题目要求 编写MyOD.java 用java MyOD XXX实现Linux下od -tx -tc XXX的功能 代码码云链接补交 源代码main函数 #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.

ajax验证用户名是否被注册 ; ajax提交form表单

register.html 文件代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html lang="en"><head><meta http-equiv="Content-Type" content="text

spark-submit提交作业过程

1. 作业提交方法以及参数 我们先看一下用Spark Submit提交的方法吧,下面是从官方上面摘抄的内容. # Run application locally on 8 cores ./bin/spark-submit --class org.apache.spark.examples.SparkPi --master local[8] /path/to/examples.jar 100 # Run on a Spark standalone cluster ./bin/spark-submi

Flink运行时之客户端提交作业图-下

submitJob方法分析 JobClientActor通过向JobManager的Actor发送SubmitJob消息来提交Job,JobManager接收到消息对象之后,构建一个JobInfo对象以封装Job的基本信息,然后将这两个对象传递给submitJob方法: case SubmitJob(jobGraph, listeningBehaviour) => val client = sender() val jobInfo = new JobInfo(client, listeningB

期末提交作业清单

1.实验报告:根据<软件测试实践教程>,提交实验报告,共15个实验.实验报告使用标准模板. 2.Android程序:提交Android期末考试作品,包括源代码和编译后程序,用于移动端应用测试使用. 3.以“软件工程课程建议”为主题写一篇博文,提出对这门课的建议. 4.以“软件团队管理”为主题的论文,要求: l  独立完成,不可抄袭. l  不少于2500字. l  从团队管理的某个角度进行讨论,例如团队绩效激励机制,团队成员沟通方法等. l  论文首页使用标准论文封皮(见群附件) l  论文正