﻿<?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-jialisoftw</title><link>http://www.blogjava.net/jialisoftw/</link><description /><language>zh-cn</language><lastBuildDate>Sat, 02 May 2026 04:52:09 GMT</lastBuildDate><pubDate>Sat, 02 May 2026 04:52:09 GMT</pubDate><ttl>60</ttl><item><title>为什么总是缺人</title><link>http://www.blogjava.net/jialisoftw/archive/2013/05/11/399139.html</link><dc:creator>飞猪一号</dc:creator><author>飞猪一号</author><pubDate>Sat, 11 May 2013 02:40:00 GMT</pubDate><guid>http://www.blogjava.net/jialisoftw/archive/2013/05/11/399139.html</guid><wfw:comment>http://www.blogjava.net/jialisoftw/comments/399139.html</wfw:comment><comments>http://www.blogjava.net/jialisoftw/archive/2013/05/11/399139.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/jialisoftw/comments/commentRss/399139.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jialisoftw/services/trackbacks/399139.html</trackback:ping><description><![CDATA[<div>为什么总是缺人，不管什么时候，都是一堆的任务等着人去做，人手总是紧张，难得偷得半日闲。知识密集型人才搞成了苦力密集型人才了。大家每天都在忙，难得抽出时间来培训，思考，反思，因为屁股坐在了火炉子上面，时刻都在煎熬着，跑的慢点了，就烤糊了。</div><div></div><div>中国有句老话，铁打的营盘流水的兵。说的很有道理，但是对于一个高速增长的企业，部门来说这个就成了问题，人员不稳定就会造成很多问题。</div><div></div><div>1.再培养</div><div></div><div>新招来的员工，需要熟悉很多东西，环境，人事，代码风格，框架代码，旧有代码阅读等等。这其中的浪费往往需要很多时间来弥补，可是任务不等人，事情还要做，只能靠人堆。以前可能一个人一个小时可以搞定的事情，变成了3个人一个星期的事。</div><div></div><div>2.知识断层</div><div></div><div>新员工到岗后，因为不熟悉原来的业务模型以及框架模型。导致设计，实现走的可能是复杂的路线，而不是最优的路线，并且由于新的设计可能导致模型的不匹配，导致返工或者桥接方式进行适配。这样平端增加出来的工作量可能是原来的2倍或者数倍以上，从而导致人手上的不足。每个行业后者领域都需要浸淫多年之后才能体会到其中的深奥之处，而这些都是无形的知识和经验，新员工到来后，这层知识就已经消失，只能从新来过。知识没有通过新老交接，逐步沉淀下来。</div><div></div><div>3.无人可用</div><div></div><div>老员工的频繁流失，当有新的业务或者领域开展之时，手下无人可用，手下皆是一年及以下左右的新手，现有的业务还未完全熟悉，此时委与重任又不放心，可是又无可用之才，缺人之感倍增。只能矬子里面拔将军，而此人的能力又将决定实现的难易以及复杂程度，往往又是造成劳动密集型的局面。</div><div></div><div>4.恶性循环</div><div></div><div>劳动密集型的局面，造成员工没有时间进行思考和进修学习，导致大家每天都是在疲劳工作，效率下降。效率变低之后，就会产生工作量过大的局面，从而又导致缺人的局面产生。当人员没有补充上来，大家继续疲劳工作，效率继续下降，工作量也就越显越大。即使新员工入岗，又会面临上面的问题。同时又因为疲劳工作，并且没有提升空间等原因，很多员工可能选择离职，而这些员工往往都是骨干员工。从而使缺人的现象产生了一种恶性循环。</div><div></div><div>5.招聘质量</div><div></div><div>因为对于招聘的漠视和一些种种限制导致了招聘进来的人员素质水平不是理想状态，大家往往只追求了量上的满足，而不是质上的满足。人员也没有呈现梯队化，导致培训成本的升高和后期提升速度较慢。这样也造成了工作效率不高的一个方面，从而导致工作在一段时间内产生积压。</div><div></div><div>铁打的营盘流水的兵，当流水的速度超过一定的限度的时候，就会造成很多不良效果，当然流水的速度如果继续上升的话，铁打的营盘也会落入湍急的漩涡之中。拥有知识密集型的人才，就应该做到让人才的知识密集起来，而不是让人密集起来。稳固流水的速度，提升员工的生产力和知识能力这样才能慢慢解决缺人的困局。</div><img src ="http://www.blogjava.net/jialisoftw/aggbug/399139.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jialisoftw/" target="_blank">飞猪一号</a> 2013-05-11 10:40 <a href="http://www.blogjava.net/jialisoftw/archive/2013/05/11/399139.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>外行谈码农</title><link>http://www.blogjava.net/jialisoftw/archive/2013/05/07/398919.html</link><dc:creator>飞猪一号</dc:creator><author>飞猪一号</author><pubDate>Tue, 07 May 2013 03:44:00 GMT</pubDate><guid>http://www.blogjava.net/jialisoftw/archive/2013/05/07/398919.html</guid><wfw:comment>http://www.blogjava.net/jialisoftw/comments/398919.html</wfw:comment><comments>http://www.blogjava.net/jialisoftw/archive/2013/05/07/398919.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jialisoftw/comments/commentRss/398919.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jialisoftw/services/trackbacks/398919.html</trackback:ping><description><![CDATA[<p style="margin-top: 14px; margin-bottom: 14px; font-family: verdana, Arial, Helvetica, sans-serif;"><span data-mce-style="color: #ff0000;" style="color: #ff0000;">如果您也是站长、创业者、程序员或者对上面的谷歌广告感兴趣，希望可以帮忙点下，谢 &nbsp; &nbsp;</span></p><p style="margin-top: 14px; margin-bottom: 14px; font-family: verdana, Arial, Helvetica, sans-serif;">在中国，程序员被称为&#8220;码农&#8221;，字面意思就是写代码的农民。<br />个人理解，码农者，以鼠标键盘为锄，代码为籽，日夜耕作于编译器的一亩三分田里，披星戴月熬红了眼圈，实为辛苦！<br />因此有人说，程序员是拿命来工作的。听说在国外，程序员工作并非这么辛苦，而且他们是很受尊重的，这可能与一些观念有关。国内对程序员工作量要求很高，而国外软件开发则更注重质量，据说国外一个程序员每月大概写三百行代码，而国内要求至少是每月六七百行。</p><p style="margin-top: 14px; margin-bottom: 14px; font-family: verdana, Arial, Helvetica, sans-serif;"><br />有的程序员写程序只是为了生活所需，老是重复去写一些没有任何新意的代码会让人感到厌烦，这时候为什么不把这些经常用到的部分归纳总结，打造出一套类库或者是编程框架呢，通过反思和总结，精益求精，方便自己惠及他人。或者也可以对现有的类库框架进行优化，这样可以提高以后的开发效率。</p><p style="margin-top: 14px; margin-bottom: 14px; font-family: verdana, Arial, Helvetica, sans-serif;"><br />为什么会沦为写代码的农民？程序员的视野不应该只局限于自己工作的部分，只一味的盘旋在某一个技术领域中，每天机械地敲代码，思维就会僵化受限，很难有创新和突破，可能就只能做一个螺丝钉。应该学习和培养架构师那样全局的思维和眼光，从全局出发思考自己的解决方案，并尝试自己主导做一些项目。</p><p style="margin-top: 14px; margin-bottom: 14px; font-family: verdana, Arial, Helvetica, sans-serif;"><br />个人觉得，程序员不仅要善于用计算机的思维编程，还应该懂市场、懂管理，通过分析理解用户需求，加上团队协作精神才能打造出优秀的产品。即使今天只是一个螺丝钉，也要用当顶梁柱的心态去思考问题，这样才能培养解决用户需求的独立思考能力，日后才能快速成长为软件工程师和架构师。</p><img src ="http://www.blogjava.net/jialisoftw/aggbug/398919.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jialisoftw/" target="_blank">飞猪一号</a> 2013-05-07 11:44 <a href="http://www.blogjava.net/jialisoftw/archive/2013/05/07/398919.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一步步开发 Spring MVC 应用</title><link>http://www.blogjava.net/jialisoftw/archive/2013/05/04/398785.html</link><dc:creator>飞猪一号</dc:creator><author>飞猪一号</author><pubDate>Sat, 04 May 2013 06:28:00 GMT</pubDate><guid>http://www.blogjava.net/jialisoftw/archive/2013/05/04/398785.html</guid><wfw:comment>http://www.blogjava.net/jialisoftw/comments/398785.html</wfw:comment><comments>http://www.blogjava.net/jialisoftw/archive/2013/05/04/398785.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jialisoftw/comments/commentRss/398785.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jialisoftw/services/trackbacks/398785.html</trackback:ping><description><![CDATA[<h2>Spring MVC 框架</h2><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块。使用 Spring 可插入的 MVC 架构，可以选择是使用内置的 Spring Web 框架还是 Struts 这样的 Web 框架。通过策略接口，Spring 框架是高度可配置的，而且包含多种视图技术，例如 JavaServer Pages（JSP）技术、Velocity、Tiles、iText 和 POI。Spring MVC 框架并不知道使用的视图，所以不会强迫您只使用 JSP 技术。Spring MVC 分离了控制器、模型对象、分派器以及处理程序对象的角色，这种分离让它们更容易进行定制。<img src="http://justjavac.iteye.com/blogs/digg?id=1812791" width="1" height="1" alt="" style="border: none;" /></p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">Spring 的 Web MVC 框架是围绕 DispatcherServlet 设计的，它把请求分派给处理程序，同时带有可配置的处理程序映射、视图解析、本地语言、主题解析以及上载文件支持。默认的处理程序是非常简单的 Controller 接口，只有一个方法 ModelAndView handleRequest(request, response)。Spring 提供了一个控制器层次结构，可以派生子类。如果应用程序需要处理用户输入表单，那么可以继承 AbstractFormController。如果需要把多页输入处理到一个表单，那么可以继承 AbstractWizardFormController。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">示例应用程序有助于直观地学习这些特性。银行应用程序允许用户检索他们的帐户信息。在构建银行应用程序的过程中，可以学到如何配置 Spring MVC 框架和实现框架的视图层，视图层包括 JSTL 标记（用于显示输出的数据）和JavaServer Pages 技术。</p><h2>配置 Spring MVC</h2><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">要开始构建示例应用程序，请配置 Spring MVC 的 DispatcherServlet。请在 web.xml 文件中注册所有配置。清单 1 显示了如何配置 sampleBankingServlet。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">清单 1. 配置 Spring MVC DispatcherServlet</p><pre style="white-space: pre-wrap; word-wrap: break-word; margin-top: 0px; margin-bottom: 9px; padding: 8.5px; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.025px; color: #333333; line-height: 18px; word-break: break-all; background-color: #f5f5f5;"><code style="padding: 0px; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border: 0px;">&lt;servlet&gt;    &lt;servlet-name&gt;sampleBankingServlet&lt;/servlet-name&gt;      &lt;servlet-class&gt;       org.springframework.we.servlet.DispatcherServlet    &lt;servlet-class&gt;    &lt;load-on-startup&gt;1&lt;load-on-startup&gt; &lt;servlet&gt;         </code></pre><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">DispatcherServlet 从一个 XML 文件装入 Spring 应用程序上下文，XML 文件的名称是 servlet 的名称后面加上 -servlet 。在这个示例中，DispatcherServlet 会从 sampleBankingServlet-servlet.xml 文件装入应用程序上下文。</p><h3>配置应用程序的 URL</h3><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">下一步是配置想让 sampleBankingServlet 处理的 URL。同样，还是要在 web.xml 中注册所有这些信息。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">清单 2. 配置想要处理的 URL</p><pre style="white-space: pre-wrap; word-wrap: break-word; margin-top: 0px; margin-bottom: 9px; padding: 8.5px; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.025px; color: #333333; line-height: 18px; word-break: break-all; background-color: #f5f5f5;"><code style="padding: 0px; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border: 0px;">&lt;servlet-mapping&gt; &lt;servlet-name&gt; sampleBankingServlet&lt;servlet-name&gt; &lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre><h3>装入配置文件</h3><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">下面，装入配置文件。为了做到这点，请为 Servlet 2.3 规范注册 ContextLoaderListener 或为 Servlet 2.2 及以下的容器注册 ContextLoaderServlet。为了保障后向兼容性，请用 ContextLoaderServlet。在启动 Web 应用程序时，ContextLoaderServlet 会装入 Spring 配置文件。清单 3 注册了 ContextLoaderServlet。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">清单 3. 注册 ContextLoaderServlet</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">context&gt;servlet-name&gt;&nbsp;org.springframework.web.context.ContextLoaderServlet&nbsp;1</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">contextConfigLocation 参数定义了要装入的 Spring 配置文件，如下面的 servlet 上下文所示。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">contextConfigLocation&nbsp;/WEB-INF/sampleBanking-services.xml</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">sampleBanking-services.xml 文件代表示例银行应用程序服务的配置和 bean 配置。如果想装入多个配置文件，可以在&nbsp;标记中用逗号作分隔符。</p><h2>Spring MVC 示例</h2><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">示例银行应用程序允许用户根据惟一的 ID 和口令查看帐户信息。虽然 Spring MVC 提供了其他选项，但是我将采用 JSP 技术作为视图页面。这个简单的应用程序包含一个视图页用于用户输入（ID 和口令），另一页显示用户的帐户信息。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">我从 LoginBankController 开始，它扩展了 Spring MVC 的 SimpleFormController。SimpleFormContoller 提供了显示从 HTTP GET 请求接收到的表单的功能，以及处理从 HTTP POST 接收到的相同表单数据的功能。LoginBankController 用 AuthenticationService 和 AccountServices 服务进行验证，并执行帐户活动。&#8220; 配置视图属性 &#8221;一节中的 清单 5 描述了如何把 AuthenticationService 和 AccountServices 连接到 LoginBankController。 清单 4 显示了 LoginBankController 的代码。</p><h3>配置视图属性</h3><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">下面，我必须注册在接收到 HTTP GET 请求时显示的页面。我在 Spring 配置中用 formView 属性注册这个页面，如清单 5 所示。sucessView 属性代表表单数据提交而且 doSubmitAction() 方法中的逻辑成功执行之后显示的页面。formView 和 sucessView 属性都代表被定义的视图的逻辑名称，逻辑名称映射到实际的视图页面。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">清单 5. 注册 LoginBankController</p><pre style="white-space: pre-wrap; word-wrap: break-word; margin-top: 0px; margin-bottom: 9px; padding: 8.5px; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.025px; color: #333333; line-height: 18px; word-break: break-all; background-color: #f5f5f5;"><code style="padding: 0px; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border: 0px;">&lt;bean id="loginBankController"      class="springexample.controller.LoginBankController"&gt;   &lt;property name="sessionForm"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt; &lt;property name="commandName"&gt;&lt;value&gt;loginCommand&lt;/value&gt;&lt;/property&gt; &lt;property name="commandClass"&gt;   &lt;value&gt;springexample.commands.LoginCommand&lt;/value&gt; &lt;/property&gt;   &lt;property name="authenticationService"&gt;      &lt;ref bean="authenticationService" /&gt;   &lt;/property&gt;   &lt;property name="accountServices"&gt;      &lt;ref bean="accountServices" /&gt;   &lt;/property&gt;   &lt;property name="formView"&gt;      &lt;value&gt;login&lt;/value&gt;   &lt;/property&gt;   &lt;property name="successView"&gt;      &lt;value&gt;accountdetail&lt;/value&gt;   &lt;/property&gt; &lt;/bean&gt; </code></pre><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">commandClass 和 commandName 标记决定将在视图页面中活动的 bean。例如，可以通过 login.jsp 页面访问 loginCommand bean，这个页面是应用程序的登录页面。一旦用户提交了登录页面，应用程序就可以从 LoginBankController 的 onSubmit() 方法中的命令对象检索出表单数据。</p><h3>视图解析器</h3><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">Spring MVC 的 视图解析器 把每个逻辑名称解析成实际的资源，即包含帐户信息的 JSP 文件。我用的是 Spring 的 InternalResourceViewResolver，如 清单 6 所示。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">因为我在 JSP 页面中使用了 JSTL 标记，所以用户的登录名称解析成资源 /jsp/login.jsp，而 viewClass 成为 JstlView。</p><h3>验证和帐户服务</h3><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">就像前面提到的，LoginBankController 内部连接了 Spring 的 AccountServices 和 AuthenticationService。AuthenticationService 类处理银行应用程序的验证。AccountServices 类处理典型的银行服务，例如查找交易和电汇。清单 7 显示了银行应用程序的验证和帐户服务的配置。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">清单 7. 配置验证和帐户服务</p><pre style="white-space: pre-wrap; word-wrap: break-word; margin-top: 0px; margin-bottom: 9px; padding: 8.5px; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.025px; color: #333333; line-height: 18px; word-break: break-all; background-color: #f5f5f5;"><code style="padding: 0px; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border: 0px;">&lt;beans&gt;    &lt;bean id="accountServices"        class="springexample.services.AccountServices"&gt;    &lt;/bean&gt;    &lt;bean id="authenticationService"        class="springexample.services.AuthenticationService"&gt;    &lt;/bean&gt; &lt;/beans&gt; </code></pre><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">以上服务在 sampleBanking-services.xml 中注册，然后装入 web.xml 文件中，就像 前面讨论的那样。控制器和服务配置好后，这个简单的应用程序就完成了。现在我们来看看部署和测试它时会发生什么!</p><h2>部署应用程序</h2><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">我把示例应用程序部署在 Tomcat servlet 容器中。Tomcat 是 Java Servlet 和 Java ServerPagest 技术的官方参考实现中使用的 servlet 容器。如果以前没这么做过，请<a href="http://jakarta.apache.org/site/downloads/downloads_tomcat-5.cgi" target="_blank" style="color: #0088cc; text-decoration: initial; margin: 0px; padding: 0px;">下载 jakarta-tomcat-5.0.28.exe</a>&nbsp;并运行它把 Tomcat 安装到自己喜欢的任何位置，例如 c:\tomcat5.0。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">接下来，<a href="http://download.csdn.net/detail/justjavac/5082102" target="_blank" style="color: #0088cc; text-decoration: initial; margin: 0px; padding: 0px;">下载示例代码</a>&nbsp;并释放到驱动器（例如 c:\ ）上。创建了 Spring 项目的文件夹之后，打开它并把 spring-banking 子文件夹拷贝到 c:\tomvat5.0\webapps。spring-banking 文件夹是一个 Web 档案，里面包含 Spring MVC 示例应用程序。lib 文件夹包含应用程序需要的 Spring 框架、与Spring 相关的 MVC 库以及 JSTL 标记库和 jar 文件。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">要启动 Tomcat 服务器，请使用以下命令：</p><pre style="white-space: pre-wrap; word-wrap: break-word; margin-top: 0px; margin-bottom: 9px; padding: 8.5px; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 12.025px; color: #333333; line-height: 18px; word-break: break-all; background-color: #f5f5f5;"><code style="padding: 0px; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border: 0px;">cd bin C:\Tomcat 5.0\bin&gt; catalina.bat start </code></pre><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">Tomcat 应当启动并部署 Spring MVC 示例应用程序。</p><h2>测试应用程序</h2><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">要测试应用程序，请打开 Web 浏览器，指向&nbsp;<a href="http://localhost:tomcatport/springbanking" style="color: #0088cc; text-decoration: initial; margin: 0px; padding: 0px;">http://localhost:tomcatport/springbanking</a>&nbsp;并用 Tomcat 服务器实际运行的端口替换 tomcatport。应当看到图 1 所示的登录屏幕。输入用户 ID &#8220;admin&#8221;和口令&#8220;password&#8221;，并按下登录按钮。其他用户 ID 或口令会造成来自验证服务的错误。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">图 1. Spring MVC 示例登录屏幕</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;"><img src="http://www.ibm.com/developerworks/cn/java/wa-spring3/image1.jpg" alt="登录屏幕" title="" style="border: 0px; margin: 0px; padding: 0px; max-width: 100%; vertical-align: middle;" /></p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">登录成功之后，会看到图 2 所示的帐户细节页面。</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">图 2. Spring MVC 示例帐户细节页面</p><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;"><img src="http://www.ibm.com/developerworks/cn/java/wa-spring3/image2.jpg" alt="帐户细节页面" title="" style="border: 0px; margin: 0px; padding: 0px; max-width: 100%; vertical-align: middle;" /></p><h2>结束语</h2><p style="background-color: #ffffff; margin-top: 0px; margin-bottom: 9px; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px;">我演示了如何配置和开发 Spring MVC 应用程序、如何配置 Spring MVC 控制器和向其中插入依赖项、如何用 JavaServer Pages 技术开发应用程序视图，以及如何把自己的页面与 Spring MVC 的视图层集成。总结这篇文章时，我演示了如何在 Tomcat servlet 容器中部署应用程序以及如何在浏览器中测试它。</p><img src ="http://www.blogjava.net/jialisoftw/aggbug/398785.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jialisoftw/" target="_blank">飞猪一号</a> 2013-05-04 14:28 <a href="http://www.blogjava.net/jialisoftw/archive/2013/05/04/398785.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA中的内存溢出</title><link>http://www.blogjava.net/jialisoftw/archive/2013/05/03/398717.html</link><dc:creator>飞猪一号</dc:creator><author>飞猪一号</author><pubDate>Fri, 03 May 2013 02:26:00 GMT</pubDate><guid>http://www.blogjava.net/jialisoftw/archive/2013/05/03/398717.html</guid><wfw:comment>http://www.blogjava.net/jialisoftw/comments/398717.html</wfw:comment><comments>http://www.blogjava.net/jialisoftw/archive/2013/05/03/398717.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jialisoftw/comments/commentRss/398717.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jialisoftw/services/trackbacks/398717.html</trackback:ping><description><![CDATA[<div>一、概述</div><div>内存溢出与数据库锁表的问题，可以说是开发人员的噩梦，一般的程序异常，总是可以知道在什么时候或是在什么操作步骤上出现了异常，而且根据堆栈信息也很容易定位到程序中是某处出现了问题。内存溢出与锁表则不然，一般现象是操作一般时间后系统越来越慢，直到死机，但并不能明确是在什么操作上出现的，发生的时间点也没有规律，查看日志或查看数据库也不能定位出问题的代码。</div><div>更严重的是内存溢出与数据库锁表在系统开发和单元测试阶段并不容易被发现，当系统正式上线一般时间后，操作的并发量上来了，数据也积累了一些，系统就容易出现内存溢出或是锁表的现象，而此时系统又不能随意停机或重启，为修正BUG带来很大的困难。本文以笔者开发和支持的多个项目为例，与大家分享在开发过程中遇到的Java内存溢出和数据库锁表的检测和处理解决过程。</div><div></div><div>二、内存溢出的分析</div><div>内存溢出是指应用系统中存在无法回收的内存或使用的内存过多，最终使得程序运行要用到的内存大于虚拟机能提供的最大内存。为了解决Java中内存溢出问题，首先必须了解Java是如何管理内存的。Java的内存管理就是对象的分配和释放问题。</div><div>在Java中，内存的分配是由程序完成的，而内存的释放是由垃圾收集器(Garbage Collection，GC)完成的，程序员不需要通过调用GC函数来释放内存，因为不同的JVM实现者可能使用不同的算法管理GC，有的是内存使用到达一定程度时，GC才开始工作，也有定时执行的，有的是中断式执行GC。但GC只能回收无用并且不再被其它对象引用的那些对象所占用的空间。Java的内存垃圾回收机制是从程序的主要运行对象开始检查引用链，当遍历一遍后发现没有被引用的孤立对象就作为垃圾回收。引起内存溢出的原因有很多种，常见的有以下几种：</div><div></div><div>1 内存中加载的数据量过于庞大，如一次从数据库取出过多数据；</div><div>2 集合类中有对对象的引用，使用完后未清空，使得JVM不能回收；</div><div>3 代码中存在死循环或循环产生过多重复的对象实体；</div><div>4 使用的第三方软件中的BUG；</div><div>5 启动参数内存值设定的过小；</div><div></div><div>三、内存溢出的解决</div><div>内存溢出虽然很棘手，但也有相应的解决办法，可以按照从易到难，一步步的解决。</div><div>第一步，就是修改JVM启动参数，直接增加内存。这一点看上去似乎很简单，但很容易被忽略。JVM默认可以使用的内存为64M，Tomcat默认可以使用的内存为128MB，对于稍复杂一点的系统就会不够用。在某项目中，就因为启动参数使用的默认值，经常报&#8220;OutOfMemory&#8221;错误。因此，-Xms，-Xmx参数一定不要忘记加。</div><div></div><div>第二步，检查错误日志，查看&#8220;OutOfMemory&#8221;错误前是否有其它异常或错误。在一个项目中，使用两个数据库连接，其中专用于发送短信的数据库连接使用DBCP连接池管理，用户为不将短信发出，有意将数据库连接用户名改错，使得日志中有许多数据库连接异常的日志，一段时间后，就出现 &#8220;OutOfMemory&#8221;错误。经分析，这是由于DBCP连接池BUG引起的，数据库连接不上后，没有将连接释放，最终使得DBCP报 &#8220;OutOfMemory&#8221;错误。经过修改正确数据库连接参数后，就没有再出现内存溢出的错误。查看日志对于分析内存溢出是非常重要的，通过仔细查看日志，分析内存溢出前做过哪些操作，可以大致定位有问题的模块。</div><div></div><div>第三步，安排有经验的编程人员对代码进行走查和分析，找出可能发生内存溢出的位置。重点排查以下几点：</div><div>(1) 检查代码中是否有死循环或递归调用。</div><div>(2) 检查是否有大循环重复产生新对象实体。</div><div>(3) 检查对数据库查询中，是否有一次获得全部数据的查询。一般来说，如果一次取十万条记录到内存，就可能引起内存溢出。这个问题比较隐蔽，在上线前，数据库中数据较少，不容易出问题，上线后，数据库中数据多了，一次查询就有可能引起内存溢出。因此对于数据库查询尽量采用分页的方式查询。</div><div>(4) 检查List、MAP等集合对象是否有使用完后，未清除的问题。List、MAP等集合对象会始终存有对对象的引用，使得这些对象不能被GC回收。</div><div>这里引用一个常看到的例子，在下面的代码中，循环申请Object对象，并将所申请的对象放入一个Vector中，如果仅仅释放对象本身，但因为Vector仍然引用该对象，所以这个对象对GC来说是不可回收的。因此如果对象加入到Vector后，还必须从Vector中删除，最简单的方法就是将Vector对象设置为null。实际上这些对象已经是无用的，但还被引用，GC就无能为力了(事实上GC认为它还有用)，这一点是导致内存泄漏最重要的原因。</div><div>Vector v = new Vector(10); &nbsp; &nbsp;&nbsp;</div><div>for (int i = 1; i &lt; 100; i++) &nbsp; &nbsp;&nbsp;</div><div>{ &nbsp; &nbsp;&nbsp;</div><div>Object o = new Object(); &nbsp; &nbsp;&nbsp;</div><div>v.add(o); &nbsp; &nbsp;&nbsp;</div><div>o = null; &nbsp; &nbsp;&nbsp;</div><div>} // 此时所有的Object对象都没有被释放，因为变量v引用这些对象</div><div>再引用另一个例子来说明Java的内存泄漏。假设有一个日志类Logger，其提供一个静态的log(String msg)，任何其它类都可以调用Logger.Log(message)来将message的内容记录到系统的日志文件中。Logger类有一个类型为HashMap的静态变量temp，每次在执行log(message)的时候，都首先将message的值写入temp中(以当前线程+当前时间为键)，在退出之前再从temp中将以当前线程和当前时间为键的条目删除。注意，这里当前时间是不断变化的，所以log在退出之前执行删除条目的操作并不能删除执行之初写入的条目。这样，任何一个作为参数传给log的字符串最终由于被Logger的静态变量temp引用，而无法得到回收，这种对象保持就是我们所说的Java内存泄漏。总的来说，内存管理中的内存泄漏产生的主要原因：保留下来却永远不再使用的对象引用。</div><div></div><div>第四步，使用内存查看工具动态查看内存使用情况。某个项目上线后，每次系统启动两天后，就会出现内存溢出的错误。这种情况一般是代码中出现了缓慢的内存泄漏，用上面三个步骤解决不了，这就需要使用内存查看工具了。</div><div>内存查看工具有许多，比较有名的有：Optimizeit Profiler、JProbe Profiler、JinSight和Java1.5的Jconsole等。它们的基本工作原理大同小异，都是监测Java程序运行时所有对象的申请、释放等动作，将内存管理的所有信息进行统计、分析、可视化。开发人员可以根据这些信息判断程序是否有内存泄漏问题。一般来说，一个正常的系统在其启动完成后其内存的占用量是基本稳定的，而不应该是无限制的增长的。持续地观察系统运行时使用的内存的大小，可以看到在内存使用监控窗口中是基本规则的锯齿形的图线，如果内存的大小持续地增长，则说明系统存在内存泄漏问题。通过间隔一段时间取一次内存快照，然后对内存快照中对象的使用与引用等信息进行比对与分析，可以找出是哪个类的对象在泄漏。</div><div></div><div>四、总结</div><div>通过以上四个步骤的分析与处理，基本能处理内存溢出的问题。当然，在这些过程中也需要相当的经验与敏感度，需要在实际的开发与调试过程中不断积累。总体上来说，产生内存溢出是由于代码写的不好造成的，因此提高代码的质量是最根本的解决办法。有的人认为先把功能实现，有BUG时再在测试阶段进行修正，这种想法是错误的。正如一件产品的质量是在生产制造的过程中决定的，而不是质量检测时决定的，软件的质量在设计与编码阶段就已经决定了，测试只是对软件质量的一个验证，因为测试不可能找出软件中所有的BUG。</div><img src ="http://www.blogjava.net/jialisoftw/aggbug/398717.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jialisoftw/" target="_blank">飞猪一号</a> 2013-05-03 10:26 <a href="http://www.blogjava.net/jialisoftw/archive/2013/05/03/398717.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>大道至简与博大精深</title><link>http://www.blogjava.net/jialisoftw/archive/2013/04/27/398494.html</link><dc:creator>飞猪一号</dc:creator><author>飞猪一号</author><pubDate>Sat, 27 Apr 2013 03:19:00 GMT</pubDate><guid>http://www.blogjava.net/jialisoftw/archive/2013/04/27/398494.html</guid><wfw:comment>http://www.blogjava.net/jialisoftw/comments/398494.html</wfw:comment><comments>http://www.blogjava.net/jialisoftw/archive/2013/04/27/398494.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jialisoftw/comments/commentRss/398494.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jialisoftw/services/trackbacks/398494.html</trackback:ping><description><![CDATA[<span style="color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;">简。</span><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;">是简单吗？不是，哪里有最简单就是最有道理的逻辑。但是常常有人这么看，而且这些人还总觉得有理。更加可怕的是，他们觉得有道理，就应该是最简单的；你的看法比别人不简单，所以你没道理。</span><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;">是简便吗？不是，这样的话就更加没有道理了。不过常人也总是这么看，拿他们没办法。</span><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;">那就只能是简洁了。是。</span><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;">所谓多一份不可，少一份不如。既不是最少，也不是最多，而是刚刚好，恰恰足。其中的博大精深，全在乎于知道何处为这个刚刚和恰恰得机巧。而就因为是简洁，而不是简单和简便，所以总是有可能不是唯一，既所谓条条大路通罗马。这里的关键是大路，而不是小路。</span><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;">人唯有博大精深后，才能知道大道至简。也唯有博大精深后，才能达到大道至简。不去单独的追求简单，才能知道什么是精深。不单独追求简便，才能知道什么是博大。天然的，简单和简便就是博大精深的天敌。可以说看起来，简洁在博大精深与简单简便中间。而实际如果你不先去博大精深那里转一圈，就不可能到底。</span><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;">而所谓博大精深到底，往往便是简单和简便。因为真的简单简便，往往就是博大精深作到头。</span><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;">然而，暮然回首，简洁才是我们最应该追求的，也是终极的目标。</span><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><br style="padding: 0px; margin: 0px; color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;" /><span style="color: #222222; font-family: Arial, 宋体; line-height: 25px; background-color: #ffffff;">关于代码究竟应该写的多，还是应该写的少；是应该写到明白，是应该写的更有效率；答案就在此。</span><img src ="http://www.blogjava.net/jialisoftw/aggbug/398494.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jialisoftw/" target="_blank">飞猪一号</a> 2013-04-27 11:19 <a href="http://www.blogjava.net/jialisoftw/archive/2013/04/27/398494.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JSON与JAVA的数据转换</title><link>http://www.blogjava.net/jialisoftw/archive/2013/03/04/396013.html</link><dc:creator>飞猪一号</dc:creator><author>飞猪一号</author><pubDate>Mon, 04 Mar 2013 00:42:00 GMT</pubDate><guid>http://www.blogjava.net/jialisoftw/archive/2013/03/04/396013.html</guid><wfw:comment>http://www.blogjava.net/jialisoftw/comments/396013.html</wfw:comment><comments>http://www.blogjava.net/jialisoftw/archive/2013/03/04/396013.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/jialisoftw/comments/commentRss/396013.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jialisoftw/services/trackbacks/396013.html</trackback:ping><description><![CDATA[<p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">本文介绍如何使用JSON-lib这个Java类包实现Java的数据转换。通过此类包可以把bean，map和XML转换成JSON并能够把JSON转回成bean和DynaBean。</p><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">JSON-lib这个Java类包用于把bean,map和XML转换成JSON并能够把JSON转回成bean和DynaBean。</p><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">下载地址:</p><div style="margin: 0px; border: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">http://sourceforge.net/projects/json-lib/</div><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">还要需要的第3方包:<br style="padding: 0px; margin: 0px;" />org.apache.commons</p><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">包括：</p><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">commons-beanutils.jar<br style="padding: 0px; margin: 0px;" />commons-collections-3.2.jar<br style="padding: 0px; margin: 0px;" />commons-lang-2.6.jar<br style="padding: 0px; margin: 0px;" />commons-logging-1.1.1.jar</p><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">net.sf.ezmorph(ezmorph-1.0.6.jar)</p><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp;</p><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">1. 对List类型的解析：</p><div style="margin: 0px; border: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><strong style="padding: 0px; margin: 0px;">Java代码: &nbsp;</strong></div><div id="" style="padding-right: 1px; padding-bottom: 1px; padding-left: 1px; margin-top: 0px; margin-bottom: 0px; margin-left: 9px; border: 0px; font-size: 14px; background-color: #f8fcff; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><ol start="1" style="padding-top: 2px; padding-bottom: 2px; margin-left: 0px; font-size: 1em; line-height: 1.4em; border: 1px solid #d1d7dc; color: #2b91af;"><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">boolean</span>[]&nbsp;boolArray&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;<span style="color: #7f0055;">boolean</span>[]{<span style="color: #7f0055;">true</span>,<span style="color: #7f0055;">false</span>,<span style="color: #7f0055;">true</span>};&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JSONArray&nbsp;jsonArray1&nbsp;=&nbsp;JSONArray.fromObject(&nbsp;boolArray&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&nbsp;jsonArray1&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;prints&nbsp;[true,false,true]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;list&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;ArrayList();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add(&nbsp;"first"&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add(&nbsp;"second"&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JSONArray&nbsp;jsonArray2&nbsp;=&nbsp;JSONArray.fromObject(&nbsp;list&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&nbsp;jsonArray2&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;prints&nbsp;["first","second"]&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JSONArray&nbsp;jsonArray3&nbsp;=&nbsp;JSONArray.fromObject(&nbsp;"['json','is','easy']"&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&nbsp;jsonArray3&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;prints&nbsp;["json","is","easy"]</span>&nbsp;</li></ol></div><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">2. 对Map类型的解析</p><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp;原文参考自站长网：<span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 20px;">http://www.software8.co/wzjs/java/3165.html</span></p><div style="margin: 0px; border: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><strong style="padding: 0px; margin: 0px;">Java代码: &nbsp;</strong></div><div id="" style="padding-right: 1px; padding-bottom: 1px; padding-left: 1px; margin-top: 0px; margin-bottom: 0px; margin-left: 9px; border: 0px; font-size: 14px; background-color: #f8fcff; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><ol start="1" style="padding-top: 2px; padding-bottom: 2px; margin-left: 0px; font-size: 1em; line-height: 1.4em; border: 1px solid #d1d7dc; color: #2b91af;"><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">Map&nbsp;map&nbsp;=&nbsp;<span style="color: #7f0055;">new</span>&nbsp;HashMap();&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">map.put("name",&nbsp;"json");&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">map.put("bool",&nbsp;Boolean.TRUE);&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">map.put("int",&nbsp;<span style="color: #7f0055;">new</span>&nbsp;Integer(<span style="color: #c00000;">1</span>));&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">map.put("arr",&nbsp;<span style="color: #7f0055;">new</span>&nbsp;String[]&nbsp;{&nbsp;"a",&nbsp;"b"&nbsp;});&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">map.put("func",&nbsp;"function(i){&nbsp;return&nbsp;this.arr[i];&nbsp;}");&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">JSONObject&nbsp;json&nbsp;=&nbsp;JSONObject.fromObject(map);&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">System.out.println(json);&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//&nbsp;{"arr":["a","b"],"int":1,"name":"json","func":function(i){&nbsp;return&nbsp;this.arr[i];&nbsp;},"bool":true}</span>&nbsp;&nbsp;</li></ol></div><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">3、对JavaBEAN的解析</p><div style="margin: 0px; border: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><strong style="padding: 0px; margin: 0px;">Java代码: &nbsp;</strong></div><div id="" style="padding-right: 1px; padding-bottom: 1px; padding-left: 1px; margin-top: 0px; margin-bottom: 0px; margin-left: 9px; border: 0px; font-size: 14px; background-color: #f8fcff; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><ol start="1" style="padding-top: 2px; padding-bottom: 2px; margin-left: 0px; font-size: 1em; line-height: 1.4em; border: 1px solid #d1d7dc; color: #2b91af;"><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span>&nbsp;net.sf.json.*;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;Test&nbsp;{&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">static</span>&nbsp;<span style="color: #7f0055;">class</span>&nbsp;JsonBean{&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">private</span>&nbsp;String&nbsp;name="json";&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">private</span>&nbsp;<span style="color: #7f0055;">int</span>&nbsp;pojoId&nbsp;=&nbsp;<span style="color: #c00000;">1</span>;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;String&nbsp;getName()&nbsp;{&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">return</span>&nbsp;name;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;setName(String&nbsp;name)&nbsp;{&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">this</span>.name&nbsp;=&nbsp;name;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">int</span>&nbsp;getPojoId()&nbsp;{&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">return</span>&nbsp;pojoId;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;setPojoId(<span style="color: #7f0055;">int</span>&nbsp;pojoId)&nbsp;{&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">this</span>.pojoId&nbsp;=&nbsp;pojoId;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">/**</span>&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;args</span>&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/</span>&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055;">public</span>&nbsp;<span style="color: #7f0055;">static</span>&nbsp;<span style="color: #7f0055;">void</span>&nbsp;main(String[]&nbsp;args)&nbsp;{&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JSONObject&nbsp;jsonObject&nbsp;=&nbsp;JSONObject.fromObject(<span style="color: #7f0055;">new</span>&nbsp;JsonBean());&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(jsonObject);&nbsp;&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="width: auto; border-width: 0px;">//&nbsp;{"name":"json","pojoId":1}</span>&nbsp;&nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</li><li style="padding-right: 0px; margin-left: 38px; list-style-type: none; list-style-position: initial; font-size: 1em; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><p style="padding: 0px; margin: 0px; list-style: none; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp;说明apache json-lib可以满足各种json的解析。</p><img src ="http://www.blogjava.net/jialisoftw/aggbug/396013.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jialisoftw/" target="_blank">飞猪一号</a> 2013-03-04 08:42 <a href="http://www.blogjava.net/jialisoftw/archive/2013/03/04/396013.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>没有总结就没有进步之开天辟地</title><link>http://www.blogjava.net/jialisoftw/archive/2013/02/26/395746.html</link><dc:creator>飞猪一号</dc:creator><author>飞猪一号</author><pubDate>Tue, 26 Feb 2013 05:44:00 GMT</pubDate><guid>http://www.blogjava.net/jialisoftw/archive/2013/02/26/395746.html</guid><wfw:comment>http://www.blogjava.net/jialisoftw/comments/395746.html</wfw:comment><comments>http://www.blogjava.net/jialisoftw/archive/2013/02/26/395746.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jialisoftw/comments/commentRss/395746.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jialisoftw/services/trackbacks/395746.html</trackback:ping><description><![CDATA[<span style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">--本篇内容纯非技术内容&nbsp;</span><br style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;" /><span style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp;&nbsp;&nbsp; 著名的成功学定律&#8220;细节决定成败&#8221;，说的没错，日常工作中，生活中也是一样的道理，细节即是习惯，而时长回头看一下自己走过的路，想一想走过的路，再想想前面的路，一定会有很多很多踩过的坑，下次会再踩到，如果不去总结和思考，一定是再很多&#8230;&#8230;，扯的有点远之所以表达弄这么大是给自己一个惊醒，你需要总结了版主，还答应老婆每周至少2篇博客，多写一些总结性的，那就从今天开始吧，习惯性的总结吧，即使不能指数型，也要做到线性向目标靠拢，超越&nbsp;</span><br style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;" /><span style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp;&nbsp;&nbsp; 说了这么多到底要写点什么呢，今天是年后的第一个周末，把老板推荐的书看了一半，书里写的好多就是我生活中的缩影，有些情况比书中案例还要糟糕（剧情回顾，去年底工作review，老板的评价是工作没什么问题，就是学生气十足），想想也是，工作1年有余，把工作还当学校实验室一样，感觉理职业，专业，这些词关联不够大,很多细节是需要注意的。&nbsp;</span><br style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;" /><span style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp;&nbsp;&nbsp; 1、桌如其人：挺大的办公桌但是却感觉不到空间感，是桌子还不够大吗，还要要紧的东西太多，分不出重要程度来，办公桌就是第二张脸，一个人性格的体现，就像自如其人一样。&nbsp;</span><br style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;" /><span style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp;&nbsp;&nbsp; 2、看上去比你的职位高才会有发展：工作可以有不同的理解，可以理解成工作，也可以当事业去做，既然不能摆脱工作，那就当事业去做，就要有职业的范，很多时候我的做事方式过于谦逊，过于卑微，这样反而带来对方的误解，或者是不信任不靠谱，这个我深有体会，因为很多时候业务方找到开发要，一个很简单问题，要的只是一个肯定，你很确定的回答是就可以了，准确明了，会觉得你是个靠谱的开发。相反你如果担心他有种种疑惑，想用他能理解的语言去解释，东扯西扯的，说说业务，说说技术的，西路又不清晰的话，会让人觉得你不专业。&nbsp;</span><br style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;" /><span style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp;&nbsp;&nbsp; 3、改掉不专业的小动作：作为一个职场打拼的人就需要遵守很多规则，除非你是一个个人魅力很强，能另辟蹊径的人，作为一个办公室白领，就需要注意很多细节，也许你的一个转笔动作也会被误解为无视可做。与人沟通要坦诚，交流不但需要语言交流，眼神很是很重要的，比如2人眼神的对视会给人感觉你有很认真的在听。&nbsp;</span><br style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;" /><span style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp;&nbsp;&nbsp; 4、对事不对人：这方面工作中遇到的比较少，只有一次发生点冲突，自认为做的还不错，对事不对人真的不是简单的说说而已，这是一种态度，一种胸怀。&nbsp;</span><br style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;" /><span style="padding: 0px; margin: 0px; font-size: 14px; background-color: #f8fcff; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px;">&nbsp;&nbsp;&nbsp; 5、城府：很多时候这是一个贬义词，但是作为职业白领是必备的技能，有城府才能挡更大的责任，解决好问题，有句名言&#8220;如果在同事眼里你不像经理，那老板眼里也不是&#8221;，说的额太好了，经理就应该有经理样子<br /></span>原文链接：<span style="font-size: 14px;">http://www.software8.co/wzjs/cxyyg/3048.html</span><img src ="http://www.blogjava.net/jialisoftw/aggbug/395746.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jialisoftw/" target="_blank">飞猪一号</a> 2013-02-26 13:44 <a href="http://www.blogjava.net/jialisoftw/archive/2013/02/26/395746.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>程序员转变草根站长后,做了网站后如何快速提高百度网站收录和流量</title><link>http://www.blogjava.net/jialisoftw/archive/2013/02/20/395452.html</link><dc:creator>飞猪一号</dc:creator><author>飞猪一号</author><pubDate>Wed, 20 Feb 2013 05:09:00 GMT</pubDate><guid>http://www.blogjava.net/jialisoftw/archive/2013/02/20/395452.html</guid><wfw:comment>http://www.blogjava.net/jialisoftw/comments/395452.html</wfw:comment><comments>http://www.blogjava.net/jialisoftw/archive/2013/02/20/395452.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/jialisoftw/comments/commentRss/395452.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jialisoftw/services/trackbacks/395452.html</trackback:ping><description><![CDATA[<div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">很多程序员都经营了自己的网站来赚取外快。都希望做了一个新站后，头疼的是如何能快速让百度收录网站信息?越快越好，最好能快速冲上百度首页呵呵。这是草根<a href="http://www.software8.co/" target="_blank" style="color: #000000; text-decoration: initial; font-size: 14px;"><u>站长</u></a>一直都在研究的问题，结合以往网站的经验现在分享给大家！&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">　　很多人说网站的权重高才能快速收录，但是新站开始哪里会有权重呢 所以但就这点站长们就不要去理会了 ，既然是新站那么就要增加网站权重，然而一个新的网站，增加网站权重是一件很难的事，但新的站长不可能在建站后就有很高的权重，这就需要各位站长去优化网站，如何优化网站？重要的是我们做站要&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">站在进入你网站的用户角度考虑。下面我们来看几点&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">　　首先，网站最初建站时，首页和导航的标签写好，标题是非常重要，如果网站是网名相关的.你可以写标题：好听的游戏名字|qq个性情侣名字|小清新网名|网名吧.网名是一个很大量的词，最后带上网名吧，这样用户就知道了 这个网站是给网民提供各种各样的网名的.所以在网站建设时就注定了以后的网站经营的内容。&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">　　第二，每天给网站注入新鲜的血液 及时更新，一个新站在内容方面很重要，不要老是复制粘贴别人的，就算是，也要做一些更改，至少要在标题和内容的第一段做一些更改,还有结尾。建议大家一个新的网站做出来后，站长要老老实实的做前三月的网站更新，每天定时定量的更新网站，注意是定时定量，当然本人还是很希望大家能够 注重原创的好。垃圾站就不要做了，没前途的！&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp; &nbsp;&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp; &nbsp; 第三 不建议大家去贴吧发帖子链接上自己的网站信息 ，尤其不要用欺诈的手段 骗取大家进去你的网站浏览信息 这样你的帖子一旦被删除 ，会直接影响你的网站权重的哦&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">　　第四，友情链接是很关键，外链质量是网站的权重高不高的重要指标，如何增加网站的外链?。做站后要加几个站长群，但只要百度收录正常，友情链接还是能找到的，那么我还要提醒大家的是 千万不要相信别人说的购买外链来提高自己的权重 这个是禁忌哦！！！你可能一时得逞 ，但是这样风险很大，百度一发现那么你的站就面临被K的 时间不远了。&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp; &nbsp; 第五 关键词要贴近和反应网站的内容，不要挂羊头卖狗肉，不要在开始的主页 满页面的堆关键词 这样用户体验不要 进来后找不到实质的内容。概括来说就是你的网站不做针对搜索引擎而非用户的处理以获得不恰当排名，导致用户受到欺骗。&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp; &nbsp; 第六 不要经常更改网站的标题和关键字，这样的话百度不知道你的站到底定位是什么，所以这是大忌&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">　　第七 还有 大家的网站要有 一个稳定的服务器 ，及时查出站内死链，确保网站持续性和稳定性，试想如果你访问一个网站　你要等很长时间，才能打开网站，或者一打开是个４０４　／５００报错　。你会继续访问这样的网站吗，更不要说百度来收录你了，还有网站的页面质量，不存在多次跳转、广告与弹窗过多等问题&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">　　第八　就是做一个网站地图　。让用户能快速找到他想要的内容很关键！保证符合用户的搜索体验&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">　　最后就是希望广大的草根站长们 ，要有信心恒心持之以恒 ，大家要相信只要我们努力坚持。我们的baidu大哥是会给我们回报的，如果你能坚持以上这些　那么你的网站离百度的快速收录已经不远了哦。&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">还有不要亲信网上的人说用什么程序快速收录　，都是忽悠你的　，做网站还是需要　恒心和吃苦勤奋&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">希望　大家的网站能越做越好　流量高高高　！！！&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">　　上文是我做站多年的经验!奉上我的供参考。本文由：<span style="font-size: 14px;">http://www.software8.co/wzjs/cxyyg/2967.html</span><span style="font-size: 14px;">&nbsp;提供，转载要标明出处，原创内容本人拥有最终解释权!希望大家能尊重知识　尊重原创</span></div><img src ="http://www.blogjava.net/jialisoftw/aggbug/395452.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jialisoftw/" target="_blank">飞猪一号</a> 2013-02-20 13:09 <a href="http://www.blogjava.net/jialisoftw/archive/2013/02/20/395452.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>spring mvc3中的addFlashAttribute方法</title><link>http://www.blogjava.net/jialisoftw/archive/2013/02/19/395407.html</link><dc:creator>飞猪一号</dc:creator><author>飞猪一号</author><pubDate>Tue, 19 Feb 2013 06:42:00 GMT</pubDate><guid>http://www.blogjava.net/jialisoftw/archive/2013/02/19/395407.html</guid><wfw:comment>http://www.blogjava.net/jialisoftw/comments/395407.html</wfw:comment><comments>http://www.blogjava.net/jialisoftw/archive/2013/02/19/395407.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/jialisoftw/comments/commentRss/395407.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jialisoftw/services/trackbacks/395407.html</trackback:ping><description><![CDATA[<div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">记得在spring mvc2中，当保存POJO到数据库后,要返回成功页面，如果这个时候要带点信息，&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">则要这样：&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><strong>Java代码: &nbsp;</strong></div><ol style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; //第三个参数（UserModel user）默认为绑定对象 &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; @RequestMapping(value = "/user/save", method = RequestMethod.POST) &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; public ModelAndView saveUser(HttpServletRequest request, HttpServletResponse response,UserModel user) throws Exception { &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp; ModelAndView mv = new ModelAndView("/user/save/result");//默认为forward模式 &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">// &nbsp; &nbsp; &nbsp;ModelAndView mv = new ModelAndView("redirect:/user/save/result");//redirect模式 &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp; mv.addObject("message","保存用户成功！"); &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp; return mv; &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; } &nbsp;</li></ol><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">而在spring mvc 3.1后，可以这样&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><strong>Java代码: &nbsp;</strong></div><ol style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><li style="margin: 0px; padding: 0px; list-style: none;">@RequestMapping(value = "/user/save", method = RequestMethod.POST) &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">public ModelAndView saveUser(UserModel user, RedirectAttributes redirectAttributes) throws Exception { &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; redirectAttributes.addFlashAttribute("message", "保存用户成功！");//使用addFlashAttribute,参数不会出现在url地址栏中 &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; return "redirect:/user/save/result"; &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">} &nbsp;</li></ol><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp; 来个稍微完整点的例子，首先是一个表单，在其中填入一些信息：&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><strong>Java代码:&nbsp;</strong></div><ol style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><li style="margin: 0px; padding: 0px; list-style: none;">&lt;form:form id="myform" action="saveUserDetails.action" method="POST" commandName="user"&gt; &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp;&lt;form:input type="text" name="firstName" path="firstName"/&gt; &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp;&lt;form:input type="text" name="lastName" path="lastName"/&gt; &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp;&lt;form:input type="text" name="email" path="email"/&gt; &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp;&lt;input type="submit" value="submit"&gt; &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&lt;/form:form&gt; &nbsp;</li></ol><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp; &nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp; &nbsp;则在controller中，可以这样：&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><strong>Java代码: &nbsp;</strong></div><ol style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp;@RequestMapping(value="/saveUserDetails.action", method=RequestMethod.POST) &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">public String greetingsAction(@Validated User user,RedirectAttributes redirectAttributes){ &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;someUserdetailsService.save(user); &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;redirectAttributes.addFlashAttribute("firstName", user.getFirstName()); &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; redirectAttributes.addFlashAttribute("lastName", user.getLastName()) &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; return "redirect:success.html"; &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">} &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; success.html:&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&lt;div&gt;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&lt;h1&gt;Hello ${firstName} ${lastName}. Your details stored in our database.&lt;/h1&gt;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&lt;/div&gt;&lt;br&gt;&nbsp;</li></ol><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp; 但如果F5的时候，会发现参数丢失，因为flash scope其实只支持redirect的，所以可以判断下：&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">&nbsp;</div><div style="border: 0px; margin: 0px; font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><strong>Java代码:&nbsp;</strong></div><ol style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;"><li style="margin: 0px; padding: 0px; list-style: none;">@RequestMapping(value="/success.html", method=RequestMethod.GET) &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; public String successView(HttpServletRequest request){ &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String,?&gt; map = RequestContextUtils.getInputFlashMap(request); &nbsp;&nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp; if (map!=null) &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return "success"; &nbsp;</li><li style="margin: 0px; padding: 0px; list-style: none;">&nbsp; &nbsp; &nbsp; &nbsp; else return "redirect:someOtherView"; //給出其他提示信息 &nbsp;<br />原文地址：<span style="font-size: 14px;">http://www.software8.co/wzjs/java/2943.html</span></li></ol><img src ="http://www.blogjava.net/jialisoftw/aggbug/395407.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jialisoftw/" target="_blank">飞猪一号</a> 2013-02-19 14:42 <a href="http://www.blogjava.net/jialisoftw/archive/2013/02/19/395407.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP防SQL注入函数：mysql_real_escape_string</title><link>http://www.blogjava.net/jialisoftw/archive/2013/01/24/394692.html</link><dc:creator>飞猪一号</dc:creator><author>飞猪一号</author><pubDate>Thu, 24 Jan 2013 04:38:00 GMT</pubDate><guid>http://www.blogjava.net/jialisoftw/archive/2013/01/24/394692.html</guid><wfw:comment>http://www.blogjava.net/jialisoftw/comments/394692.html</wfw:comment><comments>http://www.blogjava.net/jialisoftw/archive/2013/01/24/394692.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jialisoftw/comments/commentRss/394692.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jialisoftw/services/trackbacks/394692.html</trackback:ping><description><![CDATA[<span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">我们在使用php+mysql时，一般情况下都要接受用户输入的数据，这就意味着很大的风险，因为用户可能输入正常数据，也可能输入恶意的代码。作为developer，必须严格过滤用户的数据，来保护我们的网站安全。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.software8.co/">PHP</a>中可以使用&nbsp;mysql_real_escape_string&nbsp;函数来过滤非法字符。本函数将&nbsp;string&nbsp;中的特殊字符转义，并考虑到连接的当前字符集，因此可以安全用于&nbsp;mysql_query()。</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;mysql_real_escape_string()&nbsp;函数转义&nbsp;SQL&nbsp;语句中使用的字符串中的特殊字符。下列字符受影响：</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><div id="yy" style="border: 1px dotted #e4e4e4; margin: 0px auto; padding: 4px 10px; font-size: 14px; line-height: 21px; color: #559944; background-color: #efefef; overflow: hidden; font-family: Tahoma, Arial, Verdana, sans-serif;">\x00<br />\n<br />\r<br />\<br />'<br />"<br />\x1a</div><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">如果成功，则该函数返回被转义的字符串。如果失败，则返回&nbsp;false。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;飘易利用下面的这个函数，就可以有效过滤了。</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><div id="yy" style="border: 1px dotted #e4e4e4; margin: 0px auto; padding: 4px 10px; font-size: 14px; line-height: 21px; color: #559944; background-color: #efefef; overflow: hidden; font-family: Tahoma, Arial, Verdana, sans-serif;">function&nbsp;safe($s){&nbsp;//安全过滤函数<br />if(get_magic_quotes_gpc()){&nbsp;$s=stripslashes($s);&nbsp;}<br />$s=mysql_real_escape_string($s);<br />return&nbsp;$s;<br />}</div><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;或者在conn公共连接文件里加入，这样就无需修改代码了：</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><div id="yy" style="border: 1px dotted #e4e4e4; margin: 0px auto; padding: 4px 10px; font-size: 14px; line-height: 21px; color: #559944; background-color: #efefef; overflow: hidden; font-family: Tahoma, Arial, Verdana, sans-serif;">if(get_magic_quotes_gpc())&nbsp;{&nbsp;$_REQUEST&nbsp;=&nbsp;array_map(&nbsp;'stripslashes',&nbsp;$_REQUEST);&nbsp;}<br />$_REQUEST&nbsp;=&nbsp;array_map(&nbsp;'mysql_real_escape_string',&nbsp;$_REQUEST);</div><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;</span><strong style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;mysql_real_escape_string语法</strong><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><u style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">mysql_real_escape_string(string,connection)</u><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">参数 描述</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">string 必需。规定要转义的字符串。</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">connection 可选。规定&nbsp;MySQL&nbsp;连接。如果未规定，则使用上一个连接。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;其实，一般的还可以利用这个函数&nbsp;addslashes&nbsp;进行转义。作用同样为对GET、POST、COOKIE过来的字符串进行转义处理，通常与&nbsp;magic_quotes_gpc&nbsp;结合使用。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;下面讲述下addslashes&nbsp;&nbsp;、magic_quotes_gpc、mysql_real_escape_string&nbsp;三者之间的区别：</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;1、addslashes&nbsp;&nbsp;与&nbsp;mysql_real_escape_string，同样的作用是经过转义后，可直接插入数据库，&nbsp;国内很多PHP&nbsp;coder是使用addslashes函数防止SQL注入，但是建议大家使用后者转义数据。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;举例说明：addslashes的问题在于黑客可以用0xbf27来代替单引号，而addslashes只是将0xbf27修改为0xbf5c27，成为一个有效的多字节字符，其中的0xbf5c仍会被看作是单引号，所以addslashes无法成功拦截。</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;两者何时用：addslashes也不是毫无用处，它是用于单字节字符串的处理，多字节字符还是用mysql_real_escape_string更加安全。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;2、magic_quotes_gpc的说明，在首次客户端运行时，可用第一条的举例，对&nbsp;magic_quotes_gpc&nbsp;进行&nbsp;$_['name']&nbsp;判断，可转义处理。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;3、&nbsp;mysql_real_escape_string和&nbsp;mysql_escape_string&nbsp;这2个函数的区别：</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;mysql_real_escape_string&nbsp;必须在(PHP&nbsp;5以上、PHP&nbsp;4&nbsp;&gt;=&nbsp;4.3.0)版本的情况下才能使用。否则只能用&nbsp;mysql_escape_string&nbsp;。</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;两者的区别是：mysql_real_escape_string&nbsp;考虑到连接的当前字符集，而&nbsp;mysql_escape_string&nbsp;不考虑。&nbsp;</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;4、实际开发中，正确的逻辑处理，如下：</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;</span>首先，检查&nbsp;magic_quotes_gpc&nbsp;是否配置为自动转义斜线，若为on，应该调用stripslashes去掉$_REQUEST、$_GET,$_POST、$_COOKIE的转义斜线；然后，查询/写入/更新数据至mysql时，再使用mysql_real_escape_string进行字符转义<span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">[参考]：</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><span style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;">1、讨论magic_quotes_gpc、mysql_real_escape_string、addslashes的区别及用法</span><br style="font-size: 14px; line-height: 25px; background-color: #f8fcff; color: #111111; font-family: Tahoma, Arial, Verdana, sans-serif;" /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 25px; background-color: #f8fcff;">http://blog.unvs.cn/archives/magic_quotes_gpc-mysql_real_escape_string-addslashes.html</span><img src ="http://www.blogjava.net/jialisoftw/aggbug/394692.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jialisoftw/" target="_blank">飞猪一号</a> 2013-01-24 12:38 <a href="http://www.blogjava.net/jialisoftw/archive/2013/01/24/394692.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>