﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-金家寶-随笔分类-J2EE 基础</title><link>http://www.blogjava.net/jiabao/category/30911.html</link><description>機會只會給垂青有准備的人，運氣不是每個人都有的.</description><language>zh-cn</language><lastBuildDate>Sat, 19 Apr 2008 14:20:07 GMT</lastBuildDate><pubDate>Sat, 19 Apr 2008 14:20:07 GMT</pubDate><ttl>60</ttl><item><title>Servlet使用</title><link>http://www.blogjava.net/jiabao/archive/2008/04/19/194225.html</link><dc:creator>金家寶</dc:creator><author>金家寶</author><pubDate>Sat, 19 Apr 2008 12:31:00 GMT</pubDate><guid>http://www.blogjava.net/jiabao/archive/2008/04/19/194225.html</guid><wfw:comment>http://www.blogjava.net/jiabao/comments/194225.html</wfw:comment><comments>http://www.blogjava.net/jiabao/archive/2008/04/19/194225.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jiabao/comments/commentRss/194225.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiabao/services/trackbacks/194225.html</trackback:ping><description><![CDATA[
		<table style="BORDER-COLLAPSE: collapse; WORD-WRAP: break-word" cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td align="middle" height="25">
								</td>
						</tr>
						<tr>
								<td bgcolor="#d2dee2" height="1">
								</td>
						</tr>
						<tr>
								<td bgcolor="#ffffff" height="1">
								</td>
						</tr>
						<tr>
								<td align="middle">
										<table style="BORDER-COLLAPSE: collapse; WORD-WRAP: break-word" cellspacing="0" cellpadding="0" width="100%" border="0">
												<tbody>
														<tr>
																<td width="100%">
																		<div id="art" style="MARGIN: 15px" width="100%">
																				<div>1.1重定向(如果对方不支持cookie,回写sessionID进行session跟踪)<br /> response.sendRedirect(response.encodeRedirectURL(request.getContextPath()+"/next"));<br />******************************************************************<br />1.2转发<br /> RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);<br /> dispatcher.forward(request,response);<br />******************************************************************<br />1.3字符<br />  request.setCharacterEncoding("utf-8");<br />  response.setContentType("text/html;charset=utf-8");<br />******************************************************************<br />String servletPath = request.getServletPath();<br />  servletPath = servletPath.substring(servletPath.lastIndexOf("/") + 1);<br />  String operation = servletPath.substring(0, servletPath.indexOf(".do"));</div>
																				<div>1.设置连接超时时间(分钟)<br /> &lt;session-config&gt;<br />  &lt;session-timeout&gt;50&lt;/session-timeout&gt;<br /> &lt;/session-config&gt;<br />******************************************************************<br />4.相对路径匹配<br /> 1&gt;绝对匹配 /xx/yy<br /> 2&gt;后缀匹配 *.xx<br /> 3&gt;后面匹配 /xx/*<br />******************************************************************<br />5.监听器<br />5.1ServletRequestListener<br />   getServletContext() <br />   getServletRequest() <br /> requestDestroyed(ServletRequestEvent)<br /> requestInitialized(ServletRequestEvent)<br />5.2HttpSessionListener<br />   getSession() <br /> sessionCreated(HttpSessionEvent)<br /> sessionDestroyed(HttpSessionEvent)<br />5.3ServletContextListener<br />   getServletContext() <br /> contextInitialized(ServletContextEvent)<br /> contextDestroyed(ServletContextEvent)<br /> <br />5.4ServletRequestAttributeListener<br />   getName() <br />   getValue() <br /> attributeAdded(ServletRequestAttributeEvent)<br /> attributeRemoved(ServletRequestAttributeEvent)<br /> attributeReplaced(ServletRequestAttributeEvent)<br />5.5HttpSessionAttributeListener<br />   getName() <br />   getValue() <br />   getSession() <br /> attributeAdded(HttpSessionBindingEvent)<br /> attributeRemoved(HttpSessionBindingEvent)<br /> attributeReplaced(HttpSessionBindingEvent)<br />5.6ServletContextAttributeListener<br />   getName() <br />   getValue() <br /> attributeAdded(ServletContextAttributeEvent)<br /> attributeRemoved(ServletContextAttributeEvent)<br /> attributeReplaced(ServletContextAttributeEvent)<br /></div>
																		</div>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
<img src ="http://www.blogjava.net/jiabao/aggbug/194225.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiabao/" target="_blank">金家寶</a> 2008-04-19 20:31 <a href="http://www.blogjava.net/jiabao/archive/2008/04/19/194225.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>