⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcookie.java~20~

📁 梅花雪树的经典制作
💻 JAVA~20~
字号:
package com.test;

import javax.servlet.http.*;
import javax.servlet.ServletConfig;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import java.util.Enumeration;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2008</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class TestCookie extends HttpServlet {
    public TestCookie() {
    }


    public void doPost(HttpServletRequest req,
                           HttpServletResponse resp) throws ServletException,
            IOException{
        req.setCharacterEncoding("GBK");
        resp.setCharacterEncoding("GBK");
        PrintWriter out = resp.getWriter();
        String name = req.getParameter("username");
        String pwd = req.getParameter("password");

        if(name==null&&pwd==null){
           out.print("<html><head><title>cookie的使用</title></head>");
           out.print("<body><form action=\"\">"+
                     "<input type = text name=username >"+
                     "<input type = text name=password >"+
                     "<input type = submit value=提交 >"+
                     "</form></body>");
           out.print("</html>");
           return;
        }else{
            Cookie[] ck = req.getCookies();
            String username = null;
            String password = null;
            if (ck != null) {
                for (int i = 0; i < ck.length; i++) {
                    if (ck[i].getName().equals("username")) {
                        username = ck[i].getValue();
                    }

                    if (ck[i].getName().equals("password")) {
                        password = ck[i].getValue();
                    }
                }
            }

            if (username == null && password == null) {
            } else {
                out.print("<html><head><title>cookie的使用</title></head>");
                out.print("<body><form action=\"\">" +
                          "<input type = text name=username value=" + username +
                          ">" +
                          "<input type = text name=password value=" + password +
                          ">" +
                          "<input type = submit value=提交 >" +
                          "</form></body>");
                out.print("</html>");
            }
        }
    }

    public void doGet(HttpServletRequest req,
                           HttpServletResponse resp) throws ServletException,
                       IOException{
        this.doPost(req,resp);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -