Skip to content

Commit dc608d1

Browse files
committed
Site updated: 2018-06-05 00:48:33
1 parent 17b8698 commit dc608d1

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

2017/04/06/JavaWeb-09-HttpServletRequest/index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<meta property="og:site_name" content="geekhoon">
9494
<meta property="og:description" content="概述HttpServletRequest对象是封装请求消息的对象,用于操作请求消息,是Tomcat创建和管理的">
9595
<meta property="og:image" content="http://oj3s07yy0.bkt.clouddn.com/blog/20180605/000335386.png">
96-
<meta property="og:updated_time" content="2018-06-04T16:09:57.332Z">
96+
<meta property="og:updated_time" content="2018-06-04T16:48:01.414Z">
9797
<meta name="twitter:card" content="summary">
9898
<meta name="twitter:title" content="HttpServletRequest">
9999
<meta name="twitter:description" content="概述HttpServletRequest对象是封装请求消息的对象,用于操作请求消息,是Tomcat创建和管理的">
@@ -406,6 +406,13 @@ <h4 id="8-dao"><a href="#8-dao" class="headerlink" title="8.dao"></a>8.dao</h4><
406406
<h4 id="9-utils"><a href="#9-utils" class="headerlink" title="9.utils"></a>9.utils</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">package</span> com.geekhoon.utils;</div><div class="line"></div><div class="line"><span class="keyword">import</span> java.sql.Connection;</div><div class="line"><span class="keyword">import</span> java.sql.SQLException;</div><div class="line"></div><div class="line"><span class="keyword">import</span> javax.sql.DataSource;</div><div class="line"></div><div class="line"><span class="keyword">import</span> com.mchange.v2.c3p0.ComboPooledDataSource;</div><div class="line"></div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">C3P0Utils</span> </span>&#123;</div><div class="line"> <span class="keyword">private</span> <span class="keyword">static</span> DataSource ds = <span class="keyword">new</span> ComboPooledDataSource();</div><div class="line"> </div><div class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> DataSource <span class="title">getDs</span><span class="params">()</span></span>&#123;</div><div class="line"> <span class="keyword">return</span> ds;</div><div class="line"> &#125;</div><div class="line"> </div><div class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> Connection <span class="title">getConnection</span><span class="params">()</span> <span class="keyword">throws</span> SQLException</span>&#123;</div><div class="line"> <span class="keyword">return</span> ds.getConnection();</div><div class="line"> &#125;</div><div class="line"> </div><div class="line">&#125;</div></pre></td></tr></table></figure>
407407
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">package</span> com.geekhoon.utils;</div><div class="line"></div><div class="line"><span class="keyword">import</span> java.lang.reflect.InvocationTargetException;</div><div class="line"><span class="keyword">import</span> java.util.Date;</div><div class="line"><span class="keyword">import</span> java.util.Map;</div><div class="line"></div><div class="line"><span class="keyword">import</span> org.apache.commons.beanutils.BeanUtils;</div><div class="line"><span class="keyword">import</span> org.apache.commons.beanutils.ConvertUtils;</div><div class="line"><span class="keyword">import</span> org.apache.commons.beanutils.converters.DateConverter;</div><div class="line"></div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyBeanUtils</span> </span>&#123;</div><div class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">populate</span><span class="params">(Object obj,Map map)</span></span>&#123;</div><div class="line"> <span class="comment">//设置并注册一个时间转换器</span></div><div class="line"> DateConverter dc = <span class="keyword">new</span> DateConverter();</div><div class="line"> <span class="comment">//设置当前转换的字符串的格式</span></div><div class="line"> dc.setPattern(<span class="string">"yyyy-MM-dd"</span>);</div><div class="line"> <span class="comment">//注册该转换器</span></div><div class="line"> ConvertUtils.register(dc, Date.class);</div><div class="line"> <span class="comment">//2、使用BeanUtils 为 JavaBean 对象赋值</span></div><div class="line"> <span class="keyword">try</span> &#123;</div><div class="line"> BeanUtils.populate(obj, map);</div><div class="line"> &#125; <span class="keyword">catch</span> (IllegalAccessException e) &#123;</div><div class="line"> <span class="comment">// TODO Auto-generated catch block</span></div><div class="line"> e.printStackTrace();</div><div class="line"> &#125; <span class="keyword">catch</span> (InvocationTargetException e) &#123;</div><div class="line"> <span class="comment">// TODO Auto-generated catch block</span></div><div class="line"> e.printStackTrace();</div><div class="line"> &#125;</div><div class="line"> &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
408408
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">package</span> com.geekhoon.utils;</div><div class="line"></div><div class="line"><span class="keyword">import</span> java.util.UUID;</div><div class="line"></div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UUIDUtils</span> </span>&#123;</div><div class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">getId</span><span class="params">()</span></span>&#123;</div><div class="line"> <span class="keyword">return</span> UUID.randomUUID().toString().replace(<span class="string">"-"</span>, <span class="string">""</span>);</div><div class="line"> &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
409+
<h2 id="补充重要内容"><a href="#补充重要内容" class="headerlink" title="补充重要内容"></a>补充重要内容</h2><h3 id="域对象"><a href="#域对象" class="headerlink" title="域对象"></a>域对象</h3><p>注意两个重要的域对象:<strong>ServletContext和Request</strong><br>ServletContext:Web项目启动后,创建唯一的ServletContext对象,存取的数据为所有的Servlet所共享。<br>Request:Request存取的数据只在当前请求中有效。</p>
410+
<p>存取的方法都是setAttribute和getAttribute。</p>
411+
<h3 id="请求转发和重定向举例"><a href="#请求转发和重定向举例" class="headerlink" title="请求转发和重定向举例"></a>请求转发和重定向举例</h3><p>请求重定向相当于是重新发送了一次请求,而请求转发是一次请求;<br><strong>请求重定向</strong>:就好比我们找一个A广告公司给设计名片,A明确告诉我们他们不会设计,就让我们找B公司,结果B公司给我设计好了,所以我们会对外宣称是B公司给我们设计的名片,(所以我们就相当于发送了两次次请求,URL地址栏里就从A变成了B公司)</p>
412+
<p><strong>请求转发</strong>:同样去找A公司给设计名片,A公司虽然不能设计但是他们接下了我们的活,把这项任务外包(转发)给B公司,最终我们会把钱给A公司,也就会对外宣称是A公司给我们设计的名片这就是请求重定向(所以我们就相当于只对A发送了一次请求,URL地址栏里依然是A公司)。</p>
413+
<h3 id="请求转发和重定向如何选择"><a href="#请求转发和重定向如何选择" class="headerlink" title="请求转发和重定向如何选择"></a>请求转发和重定向如何选择</h3><p>1.涉及到数据传递,使用请求转发,否则重定向<br>2.对数据进行修改、删除、添加操作的时候,应该用重定向,如果采用请求转发,那么操作前后的地址栏不发生改变,仍然是修改的Servlet,如果此时再对当前页面刷新的话,就会重新发送一次请求对数据进行修改,这也就是有的人在刷新一次页面就增加一条数据的原因。</p>
414+
<h3 id="使用重定向如何传递参数"><a href="#使用重定向如何传递参数" class="headerlink" title="使用重定向如何传递参数"></a>使用重定向如何传递参数</h3><p>1.可以选择session,但要在第二个文件中删除<br>2.可以在请求的url中带上参数,如”add.html?id=1”</p>
415+
409416

410417
</div>
411418

@@ -662,7 +669,7 @@ <h4 id="9-utils"><a href="#9-utils" class="headerlink" title="9.utils"></a>9.uti
662669

663670

664671

665-
<div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#概述"><span class="nav-number">1.</span> <span class="nav-text">概述</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用"><span class="nav-number">2.</span> <span class="nav-text">使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#作用范围"><span class="nav-number">3.</span> <span class="nav-text">作用范围</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#请求处理"><span class="nav-number">4.</span> <span class="nav-text">请求处理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#请求转发"><span class="nav-number">4.1.</span> <span class="nav-text">请求转发</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#重定向"><span class="nav-number">4.2.</span> <span class="nav-text">重定向</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#原理图"><span class="nav-number">4.3.</span> <span class="nav-text">原理图</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#区别"><span class="nav-number">4.4.</span> <span class="nav-text">区别</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#路径问题-—–"><span class="nav-number">5.</span> <span class="nav-text">路径问题 ## —–</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#BeanUtils-——–反射"><span class="nav-number">6.</span> <span class="nav-text">BeanUtils ## ——–反射</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#使用-1"><span class="nav-number">6.1.</span> <span class="nav-text">使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#代码"><span class="nav-number">6.2.</span> <span class="nav-text">代码</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#案例"><span class="nav-number">7.</span> <span class="nav-text">案例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#需求"><span class="nav-number">7.1.</span> <span class="nav-text">需求</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实现步骤"><span class="nav-number">7.2.</span> <span class="nav-text">实现步骤</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-导入jar包及配置文件"><span class="nav-number">7.2.1.</span> <span class="nav-text">1.导入jar包及配置文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-创建数据库-表"><span class="nav-number">7.2.2.</span> <span class="nav-text">2.创建数据库,表</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-注册界面"><span class="nav-number">7.2.3.</span> <span class="nav-text">3.注册界面</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-构建代码结构"><span class="nav-number">7.2.4.</span> <span class="nav-text">4.构建代码结构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-domain"><span class="nav-number">7.2.5.</span> <span class="nav-text">5.domain</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#6-servlet"><span class="nav-number">7.2.6.</span> <span class="nav-text">6.servlet</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-service"><span class="nav-number">7.2.7.</span> <span class="nav-text">7.service</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#8-dao"><span class="nav-number">7.2.8.</span> <span class="nav-text">8.dao</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#9-utils"><span class="nav-number">7.2.9.</span> <span class="nav-text">9.utils</span></a></li></ol></li></ol></li></ol></div>
672+
<div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#概述"><span class="nav-number">1.</span> <span class="nav-text">概述</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用"><span class="nav-number">2.</span> <span class="nav-text">使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#作用范围"><span class="nav-number">3.</span> <span class="nav-text">作用范围</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#请求处理"><span class="nav-number">4.</span> <span class="nav-text">请求处理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#请求转发"><span class="nav-number">4.1.</span> <span class="nav-text">请求转发</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#重定向"><span class="nav-number">4.2.</span> <span class="nav-text">重定向</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#原理图"><span class="nav-number">4.3.</span> <span class="nav-text">原理图</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#区别"><span class="nav-number">4.4.</span> <span class="nav-text">区别</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#路径问题-—–"><span class="nav-number">5.</span> <span class="nav-text">路径问题 ## —–</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#BeanUtils-——–反射"><span class="nav-number">6.</span> <span class="nav-text">BeanUtils ## ——–反射</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#使用-1"><span class="nav-number">6.1.</span> <span class="nav-text">使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#代码"><span class="nav-number">6.2.</span> <span class="nav-text">代码</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#案例"><span class="nav-number">7.</span> <span class="nav-text">案例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#需求"><span class="nav-number">7.1.</span> <span class="nav-text">需求</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实现步骤"><span class="nav-number">7.2.</span> <span class="nav-text">实现步骤</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-导入jar包及配置文件"><span class="nav-number">7.2.1.</span> <span class="nav-text">1.导入jar包及配置文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-创建数据库-表"><span class="nav-number">7.2.2.</span> <span class="nav-text">2.创建数据库,表</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-注册界面"><span class="nav-number">7.2.3.</span> <span class="nav-text">3.注册界面</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-构建代码结构"><span class="nav-number">7.2.4.</span> <span class="nav-text">4.构建代码结构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-domain"><span class="nav-number">7.2.5.</span> <span class="nav-text">5.domain</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#6-servlet"><span class="nav-number">7.2.6.</span> <span class="nav-text">6.servlet</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-service"><span class="nav-number">7.2.7.</span> <span class="nav-text">7.service</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#8-dao"><span class="nav-number">7.2.8.</span> <span class="nav-text">8.dao</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#9-utils"><span class="nav-number">7.2.9.</span> <span class="nav-text">9.utils</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#补充重要内容"><span class="nav-number">8.</span> <span class="nav-text">补充重要内容</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#域对象"><span class="nav-number">8.1.</span> <span class="nav-text">域对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#请求转发和重定向举例"><span class="nav-number">8.2.</span> <span class="nav-text">请求转发和重定向举例</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#请求转发和重定向如何选择"><span class="nav-number">8.3.</span> <span class="nav-text">请求转发和重定向如何选择</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用重定向如何传递参数"><span class="nav-number">8.4.</span> <span class="nav-text">使用重定向如何传递参数</span></a></li></ol></li></ol></div>
666673

667674
</div>
668675
</section>

0 commit comments

Comments
 (0)