• 用户管理系统1.0(主界面与分界面Servlet)


    LoinServlet.java

    package com.view;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class Loin
     */
    @WebServlet("/Loin")
    public class LoinServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public LoinServlet() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            //浏览器uft-8展示
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            PrintWriter out=response.getWriter();
            //返回一个界面
    //        out.println("你好");
            out.println("<h1>用户登录</h1>");
            out.println("<form action='/user/ControlServlet' method='post'>");
            out.println("用户名:<input type='text' name='username'></br>");
            out.println("密 码:<input type='password' name='password'></br>");
            out.println("<input type='submit' value='登录'></br>");
            out.println("</form>");
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            this.doGet(request,response);
        }
    
    }
    View Code

    ControlServlet.java

    package com.controller;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.xml.ws.Response;
    
    /**
     * Servlet implementation class ControlServlet
     */
    @WebServlet("/ControlServlet")
    public class ControlServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public ControlServlet() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            PrintWriter out=response.getWriter();
            response.setContentType("text/html;charset=utf-8");
            String username=request.getParameter("username");
            String password=request.getParameter("password");
    //        System.out.println(username+password);
            //这里进行简单的认证
            if("wangzhi".equals(username)&&"123456".equals(password)){
                response.sendRedirect("/user/MainFrame");
            }else{
                response.sendRedirect("/user/Loin");
            }
            
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            this.doGet(request,response);
        }
    
    }
    View Code

    MainFrame.java

    package com.view;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class MainFrame
     */
    @WebServlet("/MainFrame")
    public class MainFrame extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        /**
         * @see HttpServlet#HttpServlet()
         */
        public MainFrame() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
         *      response)
         */
        protected void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            PrintWriter out = response.getWriter();
            out.println("zhujiemian");
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
         *      response)
         */
        protected void doPost(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            this.doGet(request, response);
        }
    
    }
    View Code

     增加功能;

    添加在主界面的超链接,可以返回登录主界面

    MainFrame;

    package com.view;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class MainFrame
     */
    @WebServlet("/MainFrame")
    public class MainFrame extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        /**
         * @see HttpServlet#HttpServlet()
         */
        public MainFrame() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
         *      response)
         */
        protected void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            response.setCharacterEncoding("utf-8");
            PrintWriter out = response.getWriter();
            out.println("<h1>主界面</h1>");
            out.println("<a href='/user/Loin'>返回重新登陆</a>");
            
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
         *      response)
         */
        protected void doPost(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            this.doGet(request, response);
        }
    
    }
    View Code
  • 相关阅读:
    添加了tabBar之后就不能使用wx.navigateTo跳转页面
    nodejs的安装及创建项目
    人名币转大写
    C#后台去除HTML标签
    自动化测试中excel的使用
    ddt方法介绍
    requests返回值
    requests提供的get方法,有几个常用的参数
    serveragent组件含义
    jmeter使用PerfMon Metrics Collector的图表分析
  • 原文地址:https://www.cnblogs.com/helloworld2019/p/10991821.html
Copyright © 2020-2023  润新知