?? setstatustag.java
字號:
/*
* 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.io.*;
import java.lang.*;
import java.lang.reflect.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
/**
* JSP Tag <b>setStatus</b>, used to set the status code for the HTTP Response.
* <p>
* JSP Tag Lib Descriptor
* <p><pre>
* <name>setStatus</name>
* <tagclass>org.apache.taglibs.response.SetStatusTag</tagclass>
* <bodycontent>empty</bodycontent>
* <info>Set the status code for the HTTP Response.</info>
* <attribute>
* <name>status</name>
* <required>true</required>
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* </pre>
*
* @author Glenn Nielsen
*/
public class SetStatusTag extends TagSupport
{
private String status;
/**
* Method called at end of tag which sets the HTTP Response status code.
*
* @return SKIP_BODY
*/
public final int doEndTag() throws JspException
{
int status_code = 0;
HttpServletResponse resp = null;
Field ec = null;
try {
resp = (HttpServletResponse)pageContext.getResponse();
Class rc = resp.getClass();
ec = rc.getField(status);
status_code = ec.getInt(resp);
} catch(Exception e) {
throw new JspException(
"Response setStatus tag could not find status code: " + status);
}
((HttpServletResponse)pageContext.getResponse()).setStatus(status_code);
return EVAL_PAGE;
}
/**
* Required attribute status, set the status code to return.
*
* The status must be a text string for a status code as
* defined in java class HttpServletResponse. For example,
* <b>SC_OK</b> to return HTTP status code 200.
*
* @param String Status Code name, e.g. "SC_OK"
*/
public final void setStatus(String stat)
{
status = stat;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -