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

📄 setheadertag.java

📁 看看吧,java类书籍JSP设计第二版源代码,有需要的请下载!
💻 JAVA
字号:
package com.ora.jsp.tags;

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

/**
 * This class is a custom action for setting response header
 * values.
 *
 * @author Hans Bergsten, Gefion software <hans@gefionsoftware.com>
 * @version 1.0
 */
public class SetHeaderTag extends TagSupport {
    private String nameEL;
    private String valueEL;

    /**
     * Sets the name attribute.
     *
     * @param name the parameter name
     */
    public void setName(String name) {
        nameEL = name;
    }

    /**
     * Sets the value attribute from a String.
     *
     * @param value the parameter String value
     */
    public void setValue(String value) {
        valueEL = value;
    }

    /**
     * Sets the header specified by the name property to the value
     * specified by the value property.
     */
    public int doEndTag() throws JspException {
        /*
         * Evaluate the EL expressions
         */
        String name = (String)
            ExpressionEvaluatorManager.evaluate("name", nameEL, 
                String.class, this, pageContext);
        String value = (String)
            ExpressionEvaluatorManager.evaluate("value", valueEL, 
                String.class, this, pageContext);

        if (value == null || name == null) {
            throw new JspTagException("setHeader: " +
                 "one of the attributes is null");
        }
        HttpServletResponse response = 
            (HttpServletResponse) pageContext.getResponse();
        response.setHeader(name, value);

        return EVAL_PAGE;
    }

    public void release() {
        nameEL = null;
        valueEL = null;
    }
}

⌨️ 快捷键说明

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