013_request对象包含的内容以及获取

例子:

做一个用户登录系统:

1、新建一个login.jsp,写form表单

2、做2个页面ok.jsp (成功),error.jsp(错误)

3、新建一个Servlet接收request,并取得username和password

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

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

        System.out.println(username+"  "+ password);

        //模拟管理员是admin,密码是123456

        if (  username.equals("admin") & password.equals("123456") ){

            //代表登录成功,跳转到成功页面去

            response.sendRedirect("ok.jsp");

        }

        else{

            //不符合条件就是登录失败,跳转到失败页面

            response.sendRedirect("error.jsp");

        }

猜你喜欢

转载自www.cnblogs.com/wyj1212/p/9000846.html