﻿<?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>C++博客-Gattaca-随笔分类-java</title><link>http://www.cppblog.com/kava12/category/4870.html</link><description>标题是记忆非常深刻的一部电影，《太空梦》，很好的励志片。自己一个人在电视上看的，那种感觉现在还记得。</description><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 00:44:11 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 00:44:11 GMT</pubDate><ttl>60</ttl><item><title>struts 加 velocity 解决 validate 不通过后，返回页面无法保留值的问题</title><link>http://www.cppblog.com/kava12/archive/2007/08/09/29630.html</link><dc:creator>Gattaca</dc:creator><author>Gattaca</author><pubDate>Thu, 09 Aug 2007 03:04:00 GMT</pubDate><guid>http://www.cppblog.com/kava12/archive/2007/08/09/29630.html</guid><wfw:comment>http://www.cppblog.com/kava12/comments/29630.html</wfw:comment><comments>http://www.cppblog.com/kava12/archive/2007/08/09/29630.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/kava12/comments/commentRss/29630.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kava12/services/trackbacks/29630.html</trackback:ping><description><![CDATA[自己也原创一下<br><br>项目做了一段时间了，该做的都做了，可以休整几天了。利用这几天，看了看自己做的项目，发现一个问题，从头到尾都没有用 actionForm。呵呵。<br><br>原因了也是因为以前一个从网上查到的让大家都很头疼的经典的问题，就是struts 的 actionForm 执行 validate 返回原来页面后原来的值无法保存的问题。今天写了个测试试了一下，发现 struts 并没有变什么魔术。一切都是这么容易，这个问题根本不是 struts 的问题了。<br><br>关键的地方在于， 页面提交后 struts 会将表单的值填进 actionForm，然后执行 validate 方法，不通过就返回源页面。 这时 表单对象是存放在 request 对象里的，与我们平时用的 request.setAttribute("xx")没有任何区别，返回原页面后这个对象当然还在 ，所以页面可以用 request.getAttribute("xx") （&#8220;xx&#8221;是struts action 映射时的 name，如果配了 attribute 就是 attribute了）， 得到之前填写的值。<br><br>我们的工程用 velocity ，更容易了，直接 $xx.fieldname ,搞定。<br>所以，以后还是这样用吧。<br> <img src ="http://www.cppblog.com/kava12/aggbug/29630.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kava12/" target="_blank">Gattaca</a> 2007-08-09 11:04 <a href="http://www.cppblog.com/kava12/archive/2007/08/09/29630.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>