response.jsp

来自「jakarta-taglibs」· JSP 代码 · 共 79 行

JSP
79
字号
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <title>Jakarta RESPONSE Taglib Example</title>
</head>
<body bgcolor="#FFFFFF">

<center>
<h1>
Jakarta RESPONSE Taglib Example</h1></center>
<br>
<%@ taglib uri="http://jakarta.apache.org/taglibs/response-1.0" prefix="res" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/request-1.0" prefix="req" %>
<p>
<pre>
Test to see if response output is committed:
<res:isCommitted>
   Response is already committed!
</res:isCommitted>
<res:isCommitted value="false">
   Response is not committed yet.
</res:isCommitted>
Add a Cookie using tag attributes and JSP:
<res:addCookie name="test1" value="First test cookie" comment="response addCookie tag" maxAge="-1" path="/example-response/" secure="false" version="1">
   Now add the domain dynamically, any of the attributes except <b>name</b>
   can be added dynamically. The domain is obtained from the JSESSIONID
   cookie if it exists.
   <req:existsCookie name="JSESSIONID">
    <req:cookies id="sess" name="JSESSIONID">
     <res:domain><jsp:getProperty name="sess" property="domain"/></res:domain>
    </req:cookies>
   </req:existsCookie>
</res:addCookie>
See if the Expires HTTP header exists:
<res:containsHeader name="Expires">
   Expires header already exists!
</res:containsHeader>
<res:containsHeader name="Expires" value="false">
   Set Expires HTTP Header to 0:
   <res:setIntHeader name="Expires">0</res:setIntHeader>
</res:containsHeader>
Now see if the Expires HTTP header exists:
<res:containsHeader name="Expires">
   Expires header exists.
</res:containsHeader>
<res:containsHeader name="Expires" value="false">
   Expires header does not exist.
</res:containsHeader>
Test addHeader by adding the Cache-Control header:
   Cache-Control:no-cache
   <res:addHeader name="Cache-Control">no-cache</res:addHeader>
   Cache-Control:no-store
   <res:addHeader name="Cache-Control">no-store</res:addHeader>

Test flushing output buffer:
<res:flushBuffer/>
Now see if response output is committed:
<res:isCommitted>
   Response is already committed!
</res:isCommitted>
<res:isCommitted value="false">
   Response is not committed yet.
</res:isCommitted>
Test the encodeUrl tag:
Try the <a href="<res:encodeUrl>sendredirect.jsp</res:encodeUrl>">sendredirect.jsp</a> page, it redirects you back to index.html.
Try the <a href="<res:encodeUrl>senderror.jsp</res:encodeUrl>">senderror.jsp</a> page, it returns back an unathorized error (401).

Test setting the status code for the response to SC_OK:
<res:setStatus status="SC_OK"/>

Test setting the content type to text/html:
<res:setContentType>text/html</res:setContentType>


</pre>
</body>
</html>

⌨️ 快捷键说明

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