<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alex's Blog &#187; response</title>
	<atom:link href="http://www.hialex.net/tags/response/feed" rel="self" type="application/rss+xml" />
	<link>http://www.hialex.net</link>
	<description>记录生活与工作中的点点滴滴</description>
	<lastBuildDate>Sat, 09 Jan 2010 12:37:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>(六)JSP基本语法E&#8211;response对象</title>
		<link>http://www.hialex.net/2008/01/jsp-syntax-e.html</link>
		<comments>http://www.hialex.net/2008/01/jsp-syntax-e.html#comments</comments>
		<pubDate>Thu, 31 Jan 2008 08:40:43 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[response]]></category>
		<category><![CDATA[跳转]]></category>

		<guid isPermaLink="false">http://www.hialex.net/2008/01/jsp-syntax-e.html</guid>
		<description><![CDATA[response对象：服务器端回应客户端的请求

所属接口：javax.servlet.http.HttpServletResponse,其父接口是ServletResponse，而且ServletResponse也现在只有唯一一个HttpServletResponse子接口，主要原因是，现在的J2EE的WEB程序主要以HTTP协议为主要通讯协议。

response对象的功能：

设置头信息：response.setHeader(&#34;头信息内容&#34;,&#34;头信息参数&#34;);

常用的刷新refresh，例如：response.setHeader(&#34;refresh&#34;,&#34;1&#34;);

几秒后跳转：response.setHeader(&#34;refresh&#34;,&#34;2:URL=XXX&#34;);




重定向&#8211;response跳转：response.sendRedirect(&#34;跳转地址&#34;);

此语句执行后，页面地址也变为跳转后的地址 
面试中常见问题：两种跳转的区别：

&#60;jsp:forward page=&#34;xxx&#34; /&#62;:

地址栏不改变&#8211;属于服务器端跳转 
执行到跳转语句后无条件立刻跳转&#8211;之后的代码将不再执行

注意：若使用forward跳转则一定要在跳转前释放掉全部资源； 
使用forward时，request设置的属性(setAttribute)依然能保留到下一个页面


通过&#60;jsp:Param name=&#34;&#34; value=&#34;&#34; /&#62;传递参数


response.sendRedirect(&#34;跳转地址&#34;):

地址栏改变&#8211;属于客户端跳转 
页面的所有代码执行完毕之后再跳转

不能保存request属性，地址栏改变了，客户端跳转


通过对URL地址的重写传递参数






设置Cookie

Cookie是服务器端保存在客户端的一组资源 
通过Cookie实现保存密码或者多长时间无需再输入密码等功能 
设置Cookie的方法：Public Void addCookie(Cookie cookie) 
Cookie是通过服务器端设置到客户端上去的&#8211;response

如果要在服务器端取得Cookie&#8211;request 
在request对象中有Public Cookie[] getCookies()方法 
在使用request对象取得全部Cookie时会出现JSESSIONID，表示唯一的客户端在服务器上的编号，这个值在客户端第一次访问服务器端之后设置


默认情况下Cookie只针对当前浏览器有效，如果需要长留在计算机上，可以设置Cookie的保存时间，通过设置Cookie最大保留时间方法：setMaxAge()



Related Posts2008-02-02 -- (七)JSP基本语法&#8211;session对象 (0)2008-04-02 -- Servlet程序设计 (0)2008-03-15 -- JavaBean语法(下) (0)2008-03-01 -- (九)JDBC操作技术 (0)2008-03-01 -- JavaBean语法(上) (0)]]></description>
			<content:encoded><![CDATA[<p>response对象：服务器端回应客户端的请求</p>
<ul>
<li>所属接口：javax.servlet.http.HttpServletResponse,其父接口是ServletResponse，而且ServletResponse也现在只有唯一一个HttpServletResponse子接口，主要原因是，现在的J2EE的WEB程序主要以HTTP协议为主要通讯协议。</li>
</ul>
<p>response对象的功能：</p>
<ol>
<li><strong>设置头信息</strong>：response.setHeader(&quot;头信息内容&quot;,&quot;头信息参数&quot;);
<ul>
<li>常用的刷新refresh，例如：<strong>response.setHeader(&quot;refresh&quot;,&quot;1&quot;);</strong>
<ul>
<li>几秒后跳转：<strong>response.setHeader(&quot;refresh&quot;,&quot;2:URL=XXX&quot;);</strong></li>
</ul>
</li>
</ul>
</li>
<li><strong>重定向&#8211;response跳转</strong>：<strong>response.sendRedirect(&quot;跳转地址&quot;);</strong>
<ul>
<li>此语句执行后，页面地址也变为跳转后的地址 </li>
<li><strong>面试中常见问题：两种跳转的区别：</strong>
<ul>
<li><strong>&lt;jsp:forward page=&quot;xxx&quot; /&gt;:</strong>
<ol>
<li><strong>地址栏不改变&#8211;属于服务器端跳转</strong> </li>
<li>执行到跳转语句后无条件立刻跳转&#8211;之后的代码将不再执行
<ul>
<li>注意：若使用forward跳转则一定要在跳转前释放掉全部资源； </li>
<li>使用forward时，request设置的属性(setAttribute)依然能保留到下一个页面</li>
</ul>
</li>
<li>通过&lt;jsp:Param name=&quot;&quot; value=&quot;&quot; /&gt;传递参数</li>
</ol>
</li>
<li><strong>response.sendRedirect(&quot;跳转地址&quot;):</strong>
<ol>
<li><strong>地址栏改变&#8211;属于客户端跳转</strong> </li>
<li>页面的所有代码执行完毕之后再跳转
<ul>
<li>不能保存request属性，地址栏改变了，客户端跳转</li>
</ul>
</li>
<li>通过对URL地址的重写传递参数</li>
</ol>
</li>
</ul>
</li>
</ul>
</li>
<li><strong>设置Cookie</strong>
<ul>
<li>Cookie是服务器端保存在客户端的一组资源 </li>
<li>通过Cookie实现保存密码或者多长时间无需再输入密码等功能 </li>
<li><strong>设置Cookie的方法：Public Void addCookie(Cookie cookie)</strong> </li>
<li>Cookie是通过服务器端设置到客户端上去的&#8211;response
<ul>
<li>如果要在服务器端取得Cookie&#8211;request </li>
<li>在request对象中有<strong>Public Cookie[] getCookies()方法</strong> </li>
<li>在使用request对象取得全部Cookie时会出现<strong>JSESSIONID，表示唯一的客户端在服务器上的编号，这个值在客户端第一次访问服务器端之后设置</strong></li>
</ul>
</li>
<li>默认情况下Cookie只针对当前浏览器有效，如果需要长留在计算机上，可以设置Cookie的保存时间，通过<strong>设置Cookie最大保留时间方法：setMaxAge()</strong></li>
</ul>
</li>
</ol>
<p><a href="http://17fav.com/?url=http%3A%2F%2Fwww.hialex.net%2F2008%2F01%2Fjsp-syntax-e.html&title=%28%E5%85%AD%29JSP%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95E--response%E5%AF%B9%E8%B1%A1" title="用 17fav 收藏和分享本文"><img src="http://17fav.com/i/bookmark.gif" alt="17fav 收藏本文" /></a></p><h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li>2008-02-02 -- <a href="http://www.hialex.net/2008/02/jsp-syntax-f.html" title="(七)JSP基本语法&#8211;session对象">(七)JSP基本语法&#8211;session对象</a> (0)</li><li>2008-04-02 -- <a href="http://www.hialex.net/2008/04/servlet-note.html" title="Servlet程序设计">Servlet程序设计</a> (0)</li><li>2008-03-15 -- <a href="http://www.hialex.net/2008/03/javabean-syntax-b.html" title="JavaBean语法(下)">JavaBean语法(下)</a> (0)</li><li>2008-03-01 -- <a href="http://www.hialex.net/2008/03/usage-of-jdbc.html" title="(九)JDBC操作技术">(九)JDBC操作技术</a> (0)</li><li>2008-03-01 -- <a href="http://www.hialex.net/2008/03/javabean-syntax-a.html" title="JavaBean语法(上)">JavaBean语法(上)</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.hialex.net/2008/01/jsp-syntax-e.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
