containsheadertag.java
来自「jakarta-taglibs」· Java 代码 · 共 98 行
JAVA
98 行
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.taglibs.response;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
/**
* JSP Tag <b>containsHeader</b>, used to determine if the Http Response
* contains the header named <b>name</b>.
* <p>
* Includes the body of the tag if the header exists.
* <p>
* You can set the optional tag attribute <b>value</b> to <b>true</b> or
* <b>false</b>. The body of the tag is included if containsHeader matches
* the value.
* <p>
* JSP Tag Lib Descriptor
* <p><pre>
* <name>containsHeader</name>
* <tagclass>org.apache.taglibs.response.ContainsHeaderTag</tagclass>
* <bodycontent>JSP</bodycontent>
* <info>Test whether the HTTP Response contains a header.</info>
* <attribute>
* <name>name</name>
* <required>required</required>
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* <attribute>
* <name>value</name>
* <required>false</required>
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* </pre>
*
* @author Glenn Nielsen
*/
public class ContainsHeaderTag extends TagSupport
{
private String name = null;
private boolean value = true;
/**
* Used to test whether the HTTP Response contains a header.
*
* @return SKIP_BODY if containsHeader doesn't match value, EVAL_BODY_INCLUDE if containsHeader matches value
*/
public final int doStartTag() throws JspException
{
boolean result =
((HttpServletResponse)pageContext.getResponse()).containsHeader(name);
if( value == result )
return EVAL_BODY_INCLUDE;
return SKIP_BODY;
}
/**
* Set the optional tag attribute <b>value</b> to true or false.
*
* @param boolean true or false
*/
public final void setValue(boolean value)
{
this.value = value;
}
/**
* Required attribute, name of the header.
*
* @param String name
*/
public final void setName(String nam)
{
name = nam;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?