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

📄 classicaddcookietag.java

📁 JSP设计(第三版)一书源代码 JSP设计(第三版)》得到了充分的修订和更新
💻 JAVA
字号:
package com.ora.jsp.tags.xmp;

import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import com.ora.jsp.util.*;
import org.apache.taglibs.standard.lang.support.*;

/**
 * This class is a custom action for adding a cookie header
 * to the response.
 *
 * @author Hans Bergsten, Gefion software <hans@gefionsoftware.com>
 * @version 2.0
 */
public class ClassicAddCookieTag extends TagSupport {
    private String name;
    private String value;
    private String maxAgeString;

    /**
     * Sets the cookie name attribute.
     *
     * @param name the name of the cookie
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Sets the cookie value attribute.
     *
     * @param value the value of the cookie
     */
    public void setValue(String value) {
        this.value = value;
    }

    /**
     * Sets the cookie maxAge attribute.
     *
     * @param maxAgeString the max age (in seconds) of the cookie
     */
    public void setMaxAge(String maxAgeString) {
        this.maxAgeString = maxAgeString;
    }

    /**
     * Creates a cookie and adds it to the response
     */
    public int doEndTag() throws JspException {
        int maxAge = -1;
        if (maxAgeString != null) {
	    try {
		maxAge = Integer.valueOf(maxAgeString).intValue();
	    }
	    catch (NumberFormatException e) {
		throw new JspTagException("Invalid maxAge", e);
	    }
        }
        CookieUtils.sendCookie(name, value, maxAge,
            (HttpServletResponse) pageContext.getResponse());
        return EVAL_PAGE;
    }
    
    /**
     * Releases all instance variables.
     */
    public void release() {
        name = null;
        value = null;
        maxAgeString = null;
        super.release();
    }
}

⌨️ 快捷键说明

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