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

<channel>
	<title>Neeke &#187; struts</title>
	<atom:link href="http://www.ineeke.com/tag/struts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ineeke.com</link>
	<description>(function f(a){if(a == &#039;堕落&#039;){return f(&#039;上进&#039;);}else{alert( &#039;保持&#039;+a+&#039;！加油！！！&#039;);}})(&#039;上进&#039;)</description>
	<lastBuildDate>Tue, 07 Sep 2010 11:23:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>3步配置Struts2</title>
		<link>http://www.ineeke.com/archives/settingmystruts2/</link>
		<comments>http://www.ineeke.com/archives/settingmystruts2/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 12:36:10 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[Struts2]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/3%e6%ad%a5%e9%85%8d%e7%bd%aestruts2/</guid>
		<description><![CDATA[<p>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。先从struts.apache.org上下载了最新的struts2-2.1.6，由于目前还没有什么IDE支持Struts2，所以只能自己手工配置了。不过我也喜欢手工配置，什么东西都由工具来生成没有什么意思，脱离了工具就成白痴了。</p>
]]></description>
			<content:encoded><![CDATA[<p>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。先从struts.apache.org上下载了最新的struts2-2.1.6，由于目前还没有什么IDE支持Struts2，所以只能自己手工配置了。不过我也喜欢手工配置，什么东西都由工具来生成没有什么意思，脱离了工具就成白痴了。</p>
<p>第一步，导包。下载下来的jar包并不是全都要，只需要下面这6个包即可。</p>
<p>1.commons-logging-1.0.4.jar</p>
<p>2.commons-fileupload-1.2.1.jar</p>
<p>3.freemarker-2.3.13.jar</p>
<p>4.ognl-2.6.11.jar</p>
<p>5.struts2-core-2.1.6.jar</p>
<p>6.xwork-2.1.2.jar</p>
<p>以上6个包，缺一不可。</p>
<p>第二步，修改web.xml。增加如下配置：</p>
<p>[xml]<br />
&lt;filter&gt;<br />
&lt;filter-name&gt;struts2&lt;/filter-name&gt;<br />
&lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher&lt;/filter-class&gt;<br />
&lt;/filter&gt;<br />
&lt;filter-mapping&gt;<br />
&lt;filter-name&gt;struts2&lt;/filter-name&gt;<br />
&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br />
&lt;/filter-mapping&gt;<br />
[/xml]</p>
<p>第三步，增加struts.xml文件。在struts1中，我们配置ActionForm及Action时是在strust-config.xml中，而在struts2中则是在struts.xml中，且该文件必须位于WEB-INF\classes目录下。</p>
<p>[xml]<br />
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;<br />
&lt;!DOCTYPE struts PUBLIC<br />
&quot;-//Apache Software Foundation//DTD Struts Configuration 2.1//EN&quot;<br />
&quot;http://struts.apache.org/dtds/struts-2.1.dtd&quot;&gt;<br />
&lt;struts&gt;<br />
&lt;package name=&quot;struts2&quot; extends=&quot;struts-default&quot;&gt;<br />
&lt;/package&gt;<br />
&lt;/struts&gt;<br />
[/xml]</p>
<p>经过上面这三步，Struts2就已经基本配置完成了。</p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li><li>2008年12月20日 -- <a href="http://www.ineeke.com/archives/StrutsFileUpload/" title="Struts实现文件上传">Struts实现文件上传</a><br /><small>客户端浏览器向WEB服务器上传文件是件比较复杂的事，之前我们有[jsp实现文件上...</small></li><li>2008年12月19日 -- <a href="http://www.ineeke.com/archives/StrutsDynaActionForm/" title="Struts DynaActionForm配置">Struts DynaActionForm配置</a><br /><small>为什么要有动态ActionForm呢？若在一个大型项目中，我们的ActionFo...</small></li><li>2008年12月17日 -- <a href="http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/" title="Struts logic:iterate">Struts logic:iterate</a><br /><small>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的logi...</small></li><li>2008年12月14日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFormat/" title="Struts bean:write format">Struts bean:write format</a><br /><small>在[Struts bean:write filter] 一文中我们了解了Stru...</small></li><li>2008年12月13日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFilter/" title="Struts bean:write filter">Struts bean:write filter</a><br /><small>Struts中的&lt;bean:write name=&quot;neeke&...</small></li><li>2008年12月5日 -- <a href="http://www.ineeke.com/archives/XueXiStrutsDispatchAction/" title="学习Struts DispatchAction">学习Struts DispatchAction</a><br /><small>一般我们都是一个表单根据不同的业务提交给不同的Action去处理。可是如果一个项...</small></li><li>2008年11月24日 -- <a href="http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/" title="Struts的工作原理">Struts的工作原理</a><br /><small>昨天写了那个[struts工作流程分析] 感觉有点乱，今天整理了一下，当然不是我...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/settingmystruts2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Struts+Spring+Hibernate集成</title>
		<link>http://www.ineeke.com/archives/strutsspringhibernate/</link>
		<comments>http://www.ineeke.com/archives/strutsspringhibernate/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 12:59:30 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/strutsspringhibernate%e9%9b%86%e6%88%90/</guid>
		<description><![CDATA[<p>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺序。</p>
]]></description>
			<content:encoded><![CDATA[<p>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺序。</p>
<p>web.xml增加</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>contextConfigLocation<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>classpath*:applicationContext-*.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.springframework.web.context.ContextLoaderListener<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>修改Struts-config.xml中action的type属性为org.springframework.web.struts.DelegatingActionProxy</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE struts-config PUBLIC &quot;-//Apache Software Foundation//DTD Struts Configuration 1.3//EN&quot; &quot;http://struts.apache.org/dtds/struts-config_1_3.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;struts-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-beans</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userForm&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;cn.ineeke.ssh.web.form.UserForm&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global-exceptions</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global-forwards</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action-mappings</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span></span>
<span style="color: #009900;"><span style="color: #000066;">attribute</span>=<span style="color: #ff0000;">&quot;userForm&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;/index.jsp&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userForm&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">parameter</span>=<span style="color: #ff0000;">&quot;action&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/user&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">scope</span>=<span style="color: #ff0000;">&quot;request&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;org.springframework.web.struts.DelegatingActionProxy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forward</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userlist&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/list.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forward</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;toUpdate&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/user_info.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action-mappings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message-resources</span> <span style="color: #000066;">parameter</span>=<span style="color: #ff0000;">&quot;cn.ineeke.ssh.web.ApplicationResources&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/struts-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>对action进行注入，name属性必须与上面配置信息中action的path一致，class属性值为具体的action类。</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;/user&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;cn.ineeke.ssh.web.action.UserAction&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userBiz&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;userBiz&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>hibernate.cfg.xml的配置</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">'1.0'</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">'UTF-8'</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE hibernate-configuration PUBLIC</span>
<span style="color: #00bbdd;">&quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;</span>
<span style="color: #00bbdd;">&quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- Generated by MyEclipse Hibernate Tools.                   --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hibernate-configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session-factory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connection.username&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>root<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connection.url&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
jdbc:mysql://localhost:3306/ssh
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dialect&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
org.hibernate.dialect.MySQLDialect
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;myeclipse.connection.profile&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>mysql<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connection.password&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>www.ineeke.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connection.driver_class&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
com.mysql.jdbc.Driver
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;show_sql&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapping</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;cn/ineeke/ssh/entity/TUser.hbm.xml&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session-factory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hibernate-configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>配置AOP</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:tx</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/tx&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:aop</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/aop&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans</span>
<span style="color: #009900;">http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</span>
<span style="color: #009900;">http://www.springframework.org/schema/tx</span>
<span style="color: #009900;">http://www.springframework.org/schema/tx/spring-tx-2.5.xsd</span>
<span style="color: #009900;">http://www.springframework.org/schema/aop</span>
<span style="color: #009900;">http://www.springframework.org/schema/aop/spring-aop-2.5.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- 配置sessionFactory --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.hibernate3.LocalSessionFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;configLocation&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;classpath:hibernate.cfg.xml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- 配置事务管理器 --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.hibernate3.HibernateTransactionManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ref</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- 配置事务的传播性 --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tx:advice</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;txAdvice&quot;</span> <span style="color: #000066;">transaction-manager</span>=<span style="color: #ff0000;">&quot;transactionManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tx:attributes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tx:method</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;add*&quot;</span> <span style="color: #000066;">propagation</span>=<span style="color: #ff0000;">&quot;REQUIRED&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tx:method</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;del*&quot;</span> <span style="color: #000066;">propagation</span>=<span style="color: #ff0000;">&quot;REQUIRED&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tx:method</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;modify*&quot;</span> <span style="color: #000066;">propagation</span>=<span style="color: #ff0000;">&quot;REQUIRED&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tx:method</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">read-only</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tx:attributes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tx:advice<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- 配置哪些类及其哪些方法参与该事务 --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;aop:config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;aop:pointcut</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;allMethod&quot;</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;execution(* cn.ineeke.ssh.biz.impl.*.*(..))&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;aop:advisor</span> <span style="color: #000066;">advice-ref</span>=<span style="color: #ff0000;">&quot;txAdvice&quot;</span> <span style="color: #000066;">pointcut-ref</span>=<span style="color: #ff0000;">&quot;allMethod&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/aop:config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2009年12月9日 -- <a href="http://www.ineeke.com/archives/hibernate-executefind/" title="Hibernate executeFind()">Hibernate executeFind()</a><br /><small>继承了HibernateDaoSupport的DAO类中，一般的增删改会直接使用...</small></li><li>2009年11月21日 -- <a href="http://www.ineeke.com/archives/spring-mvc/" title="Spring MVC">Spring MVC</a><br /><small>公司项目的框架基本上已经定下来了，前台UI使用ExtJS，后台使用Spring ...</small></li><li>2009年01月25日 -- <a href="http://www.ineeke.com/archives/springdependencyinjection/" title="Spring依赖注入">Spring依赖注入</a><br /><small>O(&cap;_&cap;)O哈哈~过新年了，我的Hibernate学习也至此告...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li><li>2009年11月26日 -- <a href="http://www.ineeke.com/archives/spring-mvc-file-upload/" title="Spring MVC 文件上传">Spring MVC 文件上传</a><br /><small>突然之间很痛恨那些用采集程序做的垃圾站，遇到个问题搜索一下出来几百个网页，打开一...</small></li><li>2009年11月25日 -- <a href="http://www.ineeke.com/archives/simpleformcontroller-initbinder/" title="SimpleFormController initBinder()">SimpleFormController initBinder()</a><br /><small>其实问题还是关于SimpleFormController onSubmit()不...</small></li><li>2009年11月23日 -- <a href="http://www.ineeke.com/archives/simpleformcontroller-onsubmit-does-not-perform/" title="SimpleFormController onSubmit()不执行">SimpleFormController onSubmit()不执行</a><br /><small>Spring MVC中的Controller还真多，它的Controller类似...</small></li><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年01月29日 -- <a href="http://www.ineeke.com/archives/applicationcontext-aop/" title="配置applicationContext.xml实现AOP">配置applicationContext.xml实现AOP</a><br /><small>昨天是使用Annotation注解的方式实现的AOP，今天再将其改为使用配置文件...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/strutsspringhibernate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>疏忽下BeanUtils.copyProperties()引发的问题</title>
		<link>http://www.ineeke.com/archives/beanutilscopyproperties/</link>
		<comments>http://www.ineeke.com/archives/beanutilscopyproperties/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 17:12:45 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/%e7%96%8f%e5%bf%bd%e4%b8%8bbeanutilscopyproperties%e5%bc%95%e5%8f%91%e7%9a%84%e9%97%ae%e9%a2%98/</guid>
		<description><![CDATA[<p>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报。经过仔细而又认真的再三查找，终于被我找到问题所在了。</p>
]]></description>
			<content:encoded><![CDATA[<p>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报。经过仔细而又认真的再三查找，终于被我找到问题所在了。</p>
<p>先来说说查错过程。首先从更新失败与不报任何错误来看，我们的代码肯定是没有错的，错误应该是出在DAO层的SQL语句中。经查证，SQL语句也是正确的。给出SQL语句具体来看看。</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> sql <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UPDATE tb_member SET name=?,password=?,reallyName=?,age=?,profession=?,email=?,question=?,result=? WHERE id=? &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">boolean</span> ok <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
conn <span style="color: #339933;">=</span> DB.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pstmt <span style="color: #339933;">=</span> conn.<span style="color: #006633;">prepareStatement</span><span style="color: #009900;">&#40;</span>sql<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pstmt.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, mbr.<span style="color: #006633;">getMbrName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pstmt.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, mbr.<span style="color: #006633;">getMbrPassword</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pstmt.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>, mbr.<span style="color: #006633;">getMbrReallyName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pstmt.<span style="color: #006633;">setInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span>, mbr.<span style="color: #006633;">getAge</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pstmt.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span>, mbr.<span style="color: #006633;">getMbrProfession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pstmt.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">6</span>, mbr.<span style="color: #006633;">getMbrEmail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pstmt.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">7</span>, mbr.<span style="color: #006633;">getMbrQuestion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pstmt.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span>, mbr.<span style="color: #006633;">getMbrResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pstmt.<span style="color: #006633;">setInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9</span>, mbr.<span style="color: #006633;">getMbrId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> pstmt.<span style="color: #006633;">executeUpdate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
ok <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>如上SQL语句，可以看到它是一个带更新条件的SQL语句（废话啊⊙﹏⊙b），那么在什么情况下这条语句可以正常执行而又返回的更新行数i又小于或等于0呢？答案就是，这里id的值在这张表中并不存在！</p>
<p>从上面的代码可以看到，这里的id是由pstmt.setInt(9, mbr.getMbrId())来赋值的。使用System.out.println(mbr.getMbrId())打印输出得到结果为0，其他属性值都存在。那就是说我们可能在Action中对mbr进行赋值时忘记了id属性。再检查一下Action中的方法。</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> ActionForward doUpdate<span style="color: #009900;">&#40;</span>ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#123;</span>
MemberForm memberForm <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>MemberForm<span style="color: #009900;">&#41;</span> form<span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
HttpSession session <span style="color: #339933;">=</span> request.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> forwardName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;failure&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//获得当前会员信息</span>
<span style="color: #003399;">Member</span> mbr <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Member</span><span style="color: #009900;">&#41;</span>session.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;member&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//判断是否已经登录</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mbr <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//赋值</span>
BeanUtils.<span style="color: #006633;">copyProperties</span><span style="color: #009900;">&#40;</span>mbr, memberForm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//更新会员信息</span>
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>mbrBiz.<span style="color: #006633;">updateMember</span><span style="color: #009900;">&#40;</span>mbr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
forwardName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">return</span> mapping.<span style="color: #006633;">findForward</span><span style="color: #009900;">&#40;</span>forwardName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>打眼一看好像也没错啊！起初我也认为绝对没错，我还以为是Tomcat的问题呢。后来仔细琢磨了一下BeanUtils.copyProperties(mbr, memberForm)这行代码。memberForm是前端控制器ActionServlet自动填充的，它封装了JSP页面中的表单数据。我使用BeanUtils.copyProperties()将memberForm中的各属性值逐一赋给mbr中的各个属性。这时我才突然明白了，我的JSP页面的表单中并不存在id这一数据！我将memberForm的id属性打印出来为null，由于BeanUtils.copyProperties()的内部实现机制的问题，这里它自动将mbr的id属性改为了0，于是就造成了更新不成功也不报错的结果。</p>
<p>那么，该怎么改好呢？很简单！在使用BeanUtils.copyProperties()方法之前先执行一下memberForm.setMbrId(mbr.getMbrId())即可。如此简单的一个问题花了我半个多小时，再加上分析整理写出来就更多了，O(∩_∩)O哈哈~。</p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li><li>2009年12月9日 -- <a href="http://www.ineeke.com/archives/hibernate-executefind/" title="Hibernate executeFind()">Hibernate executeFind()</a><br /><small>继承了HibernateDaoSupport的DAO类中，一般的增删改会直接使用...</small></li><li>2009年11月21日 -- <a href="http://www.ineeke.com/archives/spring-mvc/" title="Spring MVC">Spring MVC</a><br /><small>公司项目的框架基本上已经定下来了，前台UI使用ExtJS，后台使用Spring ...</small></li><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年01月25日 -- <a href="http://www.ineeke.com/archives/springdependencyinjection/" title="Spring依赖注入">Spring依赖注入</a><br /><small>O(&cap;_&cap;)O哈哈~过新年了，我的Hibernate学习也至此告...</small></li><li>2009年01月24日 -- <a href="http://www.ineeke.com/archives/hibernatecacheleveltwo/" title="配置Hibernate二级缓存">配置Hibernate二级缓存</a><br /><small>Hibernate二级缓存也称为进程级的缓存或SessionFactory级的缓...</small></li><li>2009年01月23日 -- <a href="http://www.ineeke.com/archives/HibernateCacheLevelOne/" title="Hibernate一级缓存">Hibernate一级缓存</a><br /><small>Hibernate的一级缓存时间很短，其生命周期和session的一样，所以一级...</small></li><li>2009年01月21日 -- <a href="http://www.ineeke.com/archives/hibernatepagerquery/" title="Hibernate分页查询">Hibernate分页查询</a><br /><small>在[jsp中实现分页显示数据] 一文中，为了分页写了很长的SQL语句，很麻烦！使...</small></li><li>2009年01月21日 -- <a href="http://www.ineeke.com/archives/hibernatefilterquery/" title="Hibernate查询过滤器">Hibernate查询过滤器</a><br /><small>在Hibernate映射文件中User.hbm.xml使用&lt;filter-...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/beanutilscopyproperties/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>log4j.properties配置文件</title>
		<link>http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/</link>
		<comments>http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 11:41:40 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[log4j配置文件]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/log4jproperties%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6/</guid>
		<description><![CDATA[<p>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意就是log4j没有配置，检查了一下发现果然没有配置。第一次用，哪会配置这东西啊！我以为这个MyEclipse也会自动生成呢！百度吧~</p>
]]></description>
			<content:encoded><![CDATA[<p>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意就是log4j没有配置，检查了一下发现果然没有配置。第一次用，哪会配置这东西啊！我以为这个MyEclipse也会自动生成呢！百度吧~</p>
<p>#错误的级别是info级别 那么warm,error,fatal级别的信息都回输出</p>
<p>#另外有两个名字为CONSOLE和FILE的存放器</p>
<p>log4j.rootLogger=info,CONSOLE,FILE</p>
<p>#定义一个CONSOLE的存放器</p>
<p>log4j.addivity.org.apache=true</p>
<p>log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender</p>
<p>log4j.appender.Threshold=ERROR</p>
<p>log4j.appender.CONSOLE.Target=System.out</p>
<p>log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout</p>
<p>log4j.appender.CONSOLE.layout.ConversionPattern=[framework] %d &#8211; %c -%-4r [%t] %-5p %c %x &#8211; %m%n</p>
<p>#log4j.appender.CONSOLE.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD] n%c[CATEGORY]%n%m[MESSAGE]%n%n</p>
<p>#设置一个到文件的存放器,该文件可以追加</p>
<p>log4j.appender.FILE=org.apache.log4j.FileAppender</p>
<p>#文件名字</p>
<p>log4j.appender.FILE.File=file.log</p>
<p>#可以追加内容</p>
<p>log4j.appender.FILE.Append=true</p>
<p>log4j.appender.FILE.layout=org.apache.log4j.PatternLayout</p>
<p>log4j.appender.FILE.layout.ConversionPattern=[framework] %d &#8211; %c -%-4r [%t] %-5p %c %x &#8211; %m%n</p>
<p>log4j有三种主要的组件：</p>
<p>? \u00C8\u00D5\u00D6\u00BE\u00D0\u00C5\u00CF\u00A2\u00B5\u00C4\u00D3\u00C5\u00CF\u00C8\u00BC\u00B6\:\u00C8\u00D5\u00D6\u00BE\u00D0\u00C5\u00CF\u00A2\u00B5\u00C4\u00D3\u00C5\u00CF\u00C8\u00BC\u00B6\u00B4\u00D3\u00B8\u00DF\u00B5\u00BD\u00B5\u00CD\u00D3\u00D0FATAL\u00A1\u00A2 ERROR\u00A1\u00A2WARN\u00A1\u00A2INFO\u00A1\u00A2DEBUG\u00A3\u00AC\u00B7\u00D6\u00B1\u00F0\u00D3\u00C3\u00C0\u00B4\u00D6\u00B8\u00B6\u00A8\u00D5\u00E2\u00CC\u00F5\u00C8\u00D5\u00D6\u00BE\u00D0\u00C5\u00CF\u00A2\u00B5\u00C4\u00D6\u00D8\u00D2\u00AA\u00B3\u00CC\u00B6\u00C8</p>
<p>u debug\u00CF\u00B5\u00CD\u00B3\u00C1\u00F7\u00B3\u00CC\u00D6\u00D0\u00B5\u00C4\u00CF\u00B8\u00BD\u00DA\u00D0\u00C5\u00CF\u00A2</p>
<p>将以上配置信息保存为log4j.properties文件到你项目中的src目录下即可。如果不希望日志记录哪些信息，只要在其前面加上&ldquo;#&rdquo;即可。由于这个文件中日志的定义是可以自由配置的，所以上面的配置信息不一定是最全的。不过至少现在不会出现那几行红字了。</p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2009年12月9日 -- <a href="http://www.ineeke.com/archives/hibernate-executefind/" title="Hibernate executeFind()">Hibernate executeFind()</a><br /><small>继承了HibernateDaoSupport的DAO类中，一般的增删改会直接使用...</small></li><li>2009年11月21日 -- <a href="http://www.ineeke.com/archives/spring-mvc/" title="Spring MVC">Spring MVC</a><br /><small>公司项目的框架基本上已经定下来了，前台UI使用ExtJS，后台使用Spring ...</small></li><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年01月25日 -- <a href="http://www.ineeke.com/archives/springdependencyinjection/" title="Spring依赖注入">Spring依赖注入</a><br /><small>O(&cap;_&cap;)O哈哈~过新年了，我的Hibernate学习也至此告...</small></li><li>2009年01月24日 -- <a href="http://www.ineeke.com/archives/hibernatecacheleveltwo/" title="配置Hibernate二级缓存">配置Hibernate二级缓存</a><br /><small>Hibernate二级缓存也称为进程级的缓存或SessionFactory级的缓...</small></li><li>2009年01月23日 -- <a href="http://www.ineeke.com/archives/HibernateCacheLevelOne/" title="Hibernate一级缓存">Hibernate一级缓存</a><br /><small>Hibernate的一级缓存时间很短，其生命周期和session的一样，所以一级...</small></li><li>2009年01月21日 -- <a href="http://www.ineeke.com/archives/hibernatepagerquery/" title="Hibernate分页查询">Hibernate分页查询</a><br /><small>在[jsp中实现分页显示数据] 一文中，为了分页写了很长的SQL语句，很麻烦！使...</small></li><li>2009年01月21日 -- <a href="http://www.ineeke.com/archives/hibernatefilterquery/" title="Hibernate查询过滤器">Hibernate查询过滤器</a><br /><small>在Hibernate映射文件中User.hbm.xml使用&lt;filter-...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Struts实现文件上传</title>
		<link>http://www.ineeke.com/archives/StrutsFileUpload/</link>
		<comments>http://www.ineeke.com/archives/StrutsFileUpload/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 07:32:02 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[java文件上传]]></category>
		<category><![CDATA[jsp实现文件上传]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/struts%e5%ae%9e%e7%8e%b0%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0/</guid>
		<description><![CDATA[<p>客户端浏览器向WEB服务器上传文件是件比较复杂的事，之前我们有[<a target="_blank" href="../../../archives/372/">jsp实现文件上传</a>]和[<a target="_blank" href="../../../archives/ServletShiXianWenJianShangChuan/">Servlet中实现文件上传</a>] 这两种方式，我们发现那都需要写很多代码，而使用Struts为我们提供的文件上传机制就简单容易的多了。</p>
]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript" src="http://www.ineeke.com/PLUGIN/Codelight/Jssc4/jssc4.js"></script></p>
<p>客户端浏览器向WEB服务器上传文件是件比较复杂的事，之前我们有[<a target="_blank" href="../../../archives/372/">jsp实现文件上传</a>]和[<a target="_blank" href="../../../archives/ServletShiXianWenJianShangChuan/">Servlet中实现文件上传</a>] 这两种方式，我们发现那都需要写很多代码，而使用Struts为我们提供的文件上传机制就简单容易的多了。</p>
<p>首先我们创建一个用于上传文件的JSP表单页。</p>
<pre class="html" style="border-right: rgb(204,204,204) thin ridge; border-top: rgb(204,204,204) thin ridge; border-left: rgb(204,204,204) thin ridge; border-bottom: rgb(204,204,204) thin ridge; background-color: rgb(240,240,240)" width="500" name="CodeLight_code" height="400">
&lt;%@ page language=&quot;java&quot; import=&quot;java.util.*&quot; pageEncoding=&quot;UTF-8&quot;%&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Struts文件上传&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;upload.do&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
文件名：&lt;input type=&quot;text&quot; name=&quot;fileName&quot;&gt;&lt;br&gt;
文件：&lt;input type=&quot;file&quot; name=&quot;myfile&quot;&gt;&lt;br&gt;
&lt;input type=&quot;submit&quot;&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>注意一定要有enctype=&quot;multipart/form-data&quot;这个属性，否则无法上传的。</p>
<p>接着是ActionForm。</p>
<pre class="java" style="border-right: rgb(204,204,204) thin ridge; border-top: rgb(204,204,204) thin ridge; border-left: rgb(204,204,204) thin ridge; border-bottom: rgb(204,204,204) thin ridge; background-color: rgb(240,240,240)" width="500" name="CodeLight_code" height="400">
package cn.ineeke.fileupload.form;
import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;
/**
* 作用：测试学习Struts文件上传
* 作者：Neeke
* BLOG：http://www.ineeke.com
*/
public class UploadActionForm extends ActionForm {
private String fileName;
private FormFile myfile;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public FormFile getMyfile() {
return myfile;
}
public void setMyfile(FormFile myfile) {
this.myfile = myfile;
}
}
</pre>
<p>这里我们所上传的文件的类型必须使用FormFile！接下来就是Action了。</p>
<pre class="java" style="border-right: rgb(204,204,204) thin ridge; border-top: rgb(204,204,204) thin ridge; border-left: rgb(204,204,204) thin ridge; border-bottom: rgb(204,204,204) thin ridge; background-color: rgb(240,240,240)" width="500" name="CodeLight_code" height="400">
package cn.ineeke.fileupload.action;
import java.io.FileOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import cn.ineeke.fileupload.form.UploadActionForm;
/**
* 作用：测试学习Struts文件上传
* 作者：Neeke
* BLOG：http://www.ineeke.com
*/
public class UploadAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
UploadActionForm upActForm = (UploadActionForm)form;
System.out.println(upActForm.getFileName());//打印出表单中所填写的文件名
FormFile formFile = upActForm.getMyfile();//获取FormFile
if(formFile != null){
System.out.println(formFile.getFileName());//打印出实际上传时所选文件的文件名
FileOutputStream fos = new FileOutputStream(&quot;c:\\&quot;+formFile.getFileName());//获取文件流对象
fos.write(formFile.getFileData());//开始写入
fos.flush();
fos.close();
}
return null;
}
}
</pre>
<p>具体的看旁边的注释应该就够了，万事俱备，只欠配置struts-config.xml了。</p>
<pre class="xml" style="border-right: rgb(204,204,204) thin ridge; border-top: rgb(204,204,204) thin ridge; border-left: rgb(204,204,204) thin ridge; border-bottom: rgb(204,204,204) thin ridge; background-color: rgb(240,240,240)" width="500" name="CodeLight_code" height="400">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE struts-config PUBLIC &quot;-//Apache Software Foundation//DTD Struts Configuration 1.3//EN&quot; &quot;http://struts.apache.org/dtds/struts-config_1_3.dtd&quot;&gt;
&lt;struts-config&gt;
&lt;form-beans&gt;
&lt;form-bean name=&quot;uploadActionForm&quot; type=&quot;cn.ineeke.fileupload.form.UploadActionForm&quot;&gt;&lt;/form-bean&gt;
&lt;/form-beans&gt;
&lt;global-exceptions /&gt;
&lt;global-forwards /&gt;
&lt;action-mappings&gt;
&lt;action path=&quot;/upload&quot;
type=&quot;cn.ineeke.fileupload.action.UploadAction&quot;
name=&quot;uploadActionForm&quot;
scope=&quot;request&quot;
&gt;
&lt;/action&gt;
&lt;/action-mappings&gt;
&lt;message-resources parameter=&quot;cn.ineeke.struts.ApplicationResources&quot; /&gt;
&lt;/struts-config&gt;
</pre>
<p>好了，所有的配置都结束了，可以正常上传文件了。不过，Struts默认的允许上传的文件最大为250M，如果我们只需要10M呢？怎么改？很简单！在struts-config.xml中&lt;/action-mappings&gt;标签后增加一句&lt;controller maxFileSize=&quot;10M&quot; /&gt;即可。</p>
<p><object id="jssc4" height="1" align="middle" width="1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="sameDomain" name="allowScriptAccess" /><param value="false" name="allowFullScreen" /><param value="http://www.ineeke.com/PLUGIN/Codelight/Jssc4/jssc4.swf" name="movie" /><param value="high" name="quality" /><param value="#ffffff" name="bgcolor" /><embed name="jssc4" height="1" align="middle" width="1" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" bgcolor="#ffffff" quality="high" src="http://www.ineeke.com/PLUGIN/Codelight/Jssc4/jssc4.swf" allowscriptaccess="sameDomain" allowfullscreen="false"></embed></object></p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li><li>2008年12月19日 -- <a href="http://www.ineeke.com/archives/StrutsDynaActionForm/" title="Struts DynaActionForm配置">Struts DynaActionForm配置</a><br /><small>为什么要有动态ActionForm呢？若在一个大型项目中，我们的ActionFo...</small></li><li>2008年12月17日 -- <a href="http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/" title="Struts logic:iterate">Struts logic:iterate</a><br /><small>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的logi...</small></li><li>2008年12月14日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFormat/" title="Struts bean:write format">Struts bean:write format</a><br /><small>在[Struts bean:write filter] 一文中我们了解了Stru...</small></li><li>2008年12月13日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFilter/" title="Struts bean:write filter">Struts bean:write filter</a><br /><small>Struts中的&lt;bean:write name=&quot;neeke&...</small></li><li>2008年12月5日 -- <a href="http://www.ineeke.com/archives/XueXiStrutsDispatchAction/" title="学习Struts DispatchAction">学习Struts DispatchAction</a><br /><small>一般我们都是一个表单根据不同的业务提交给不同的Action去处理。可是如果一个项...</small></li><li>2008年11月24日 -- <a href="http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/" title="Struts的工作原理">Struts的工作原理</a><br /><small>昨天写了那个[struts工作流程分析] 感觉有点乱，今天整理了一下，当然不是我...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/StrutsFileUpload/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Struts DynaActionForm配置</title>
		<link>http://www.ineeke.com/archives/StrutsDynaActionForm/</link>
		<comments>http://www.ineeke.com/archives/StrutsDynaActionForm/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 11:22:39 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[dynaactionform]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[struts教程]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/struts-dynaactionform%e9%85%8d%e7%bd%ae/</guid>
		<description><![CDATA[<p>为什么要有动态ActionForm呢？若在一个大型项目中，我们的ActionForm可能会很多，而使用动态ActionForm的话，我们就不需要去写那么多类文件了，我们可以直接在配置文件中配置所需要的ActionForm。</p>
]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript" src="http://www.ineeke.com/PLUGIN/Codelight/Jssc4/jssc4.js"></script></p>
<p>为什么要有动态ActionForm呢？若在一个大型项目中，我们的ActionForm可能会很多，而使用动态ActionForm的话，我们就不需要去写那么多类文件了，我们可以直接在配置文件中配置所需要的ActionForm。<br />
下面我们来看看如何配置动态ActionForm。首先我们创建一个JSP页面用于提交数据和显示数据。</p>
<pre class="html" style="border-right: #333333 thin ridge; border-top: #333333 thin ridge; border-left: #333333 thin ridge; border-bottom: #333333 thin ridge; background-color: #cccccc" width="500" height="400" name="CodeLight_code">
&lt;%@ page language=&quot;java&quot; import=&quot;java.util.*&quot; pageEncoding=&quot;utf-8&quot;%&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;动态ActionForm测试&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;dynaactionform.do&quot; method=&quot;post&quot;&gt;
用户名：&lt;input type=&quot;text&quot; name=&quot;userName&quot;&gt;&lt;br&gt;
密码：&lt;input type=&quot;password&quot; name=&quot;password&quot;&gt;&lt;br&gt;
&lt;input type=&quot;submit&quot; value=&quot;登录&quot;&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>上面的代码中我们创建一个form表单，表单中有userName和password两项提交给dynaactionform.do进行处理。<br />
接着创建我们的Action，其代码如下：</p>
<pre class="java" style="border-right: #333333 thin ridge; border-top: #333333 thin ridge; border-left: #333333 thin ridge; border-bottom: #333333 thin ridge; background-color: #cccccc" width="500" height="400" name="CodeLight_code">
package cn.ineeke.dynamicactionform.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
public class DynaFormAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaActionForm dynaForm = (DynaActionForm)form;
System.out.println(dynaForm.get(&quot;userName&quot;));
System.out.println(dynaForm.get(&quot;password&quot;));
return mapping.findForward(&quot;success&quot;);
}
}
</pre>
<p>上面的DynaFormAction同样也是继承自Action这个类，而在execute方法中我们将前端控制器传给我们的form强制转换成DynaActionForm（动态ActionForm）类型，并调用其get方法输出各属性值，之后进行跳转。<br />
接下来配置struts-config.xml文件，其内容如下：</p>
<pre class="xml" style="border-right: #333333 thin ridge; border-top: #333333 thin ridge; border-left: #333333 thin ridge; border-bottom: #333333 thin ridge; background-color: #cccccc" width="500" height="400" name="CodeLight_code">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE struts-config PUBLIC &quot;-//Apache Software Foundation//DTD Struts Configuration 1.3//EN&quot; &quot;http://struts.apache.org/dtds/struts-config_1_3.dtd&quot;&gt;
&lt;struts-config&gt;
&lt;form-beans&gt;
&lt;form-bean name=&quot;dynaForm&quot; type=&quot;org.apache.struts.action.DynaActionForm&quot;&gt;
&lt;form-property name=&quot;userName&quot; type=&quot;java.lang.String&quot;&gt;&lt;/form-property&gt;
&lt;form-property name=&quot;password&quot; type=&quot;java.lang.String&quot;&gt;&lt;/form-property&gt;
&lt;/form-bean&gt;
&lt;/form-beans&gt;
&lt;global-exceptions /&gt;
&lt;global-forwards /&gt;
&lt;action-mappings&gt;
&lt;action path=&quot;/dynaactionform&quot;
type=&quot;cn.ineeke.dynamicactionform.action.DynaFormAction&quot;
name=&quot;dynaForm&quot;
scope=&quot;request&quot;
&gt;
&lt;forward name=&quot;success&quot; path=&quot;/dynaform.jsp&quot;&gt;&lt;/forward&gt;
&lt;/action&gt;
&lt;/action-mappings&gt;
&lt;message-resources parameter=&quot;cn.ineeke.struts.ApplicationResources&quot; /&gt;
&lt;/struts-config&gt;
</pre>
<p>在struts-config.xml中我们配置了一个ActionForm和一个Action，这个ActionForm有两个属性，分别是userName和password以及其数据类型。其中org.apache.struts.action.DynaActionForm这个类是Struts所为我们提供的，我们就是使用它实现动态ActionForm的。<br />
动态ActionForm动在何处呢？就动在form-bean的配置中。我们可以使用&lt;form-property&gt;动态的配置ActionForm的各个属性。</p>
<p><object id="jssc4" height="1" align="middle" width="1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="sameDomain" name="allowScriptAccess" /><param value="false" name="allowFullScreen" /><param value="http://www.ineeke.com/PLUGIN/Codelight/Jssc4/jssc4.swf" name="movie" /><param value="high" name="quality" /><param value="#ffffff" name="bgcolor" /><embed height="1" name="jssc4" align="middle" width="1" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="false" allowscriptaccess="sameDomain" bgcolor="#ffffff" quality="high" src="http://www.ineeke.com/PLUGIN/Codelight/Jssc4/jssc4.swf"></embed></object></p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2008年08月20日 -- <a href="http://www.ineeke.com/archives/shenmeshi-struts/" title="什么是Struts">什么是Struts</a><br /><small>Struts是骨架、支柱的意思。Struts框架的目的也是提供一个实现MVC模式...</small></li><li>2008年08月19日 -- <a href="http://www.ineeke.com/archives/weishenme-shiyong-struts/" title="为什么使用Struts">为什么使用Struts</a><br /><small>古语有云“没有绳子的世界是乱世”。JSP、Servlet和JavaBean技术的...</small></li><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li><li>2008年12月20日 -- <a href="http://www.ineeke.com/archives/StrutsFileUpload/" title="Struts实现文件上传">Struts实现文件上传</a><br /><small>客户端浏览器向WEB服务器上传文件是件比较复杂的事，之前我们有[jsp实现文件上...</small></li><li>2008年12月17日 -- <a href="http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/" title="Struts logic:iterate">Struts logic:iterate</a><br /><small>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的logi...</small></li><li>2008年12月14日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFormat/" title="Struts bean:write format">Struts bean:write format</a><br /><small>在[Struts bean:write filter] 一文中我们了解了Stru...</small></li><li>2008年12月13日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFilter/" title="Struts bean:write filter">Struts bean:write filter</a><br /><small>Struts中的&lt;bean:write name=&quot;neeke&...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/StrutsDynaActionForm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Struts logic:iterate</title>
		<link>http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/</link>
		<comments>http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 05:52:36 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[logic iterate用法]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[struts iterate]]></category>
		<category><![CDATA[struts 标签]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/struts-logiciterate/</guid>
		<description><![CDATA[<p>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的login:iterate标签来帮你吧！这里有一个简单的实例，你是否能够学会呢？</p>
]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript" src="http://www.ineeke.com/PLUGIN/Codelight/Jssc4/jssc4.js"></script></p>
<p>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的login:iterate标签来帮你吧！这里有一个简单的实例，你是否能够学会呢？</p>
<p>首先我们创建一个IterateAction，在execute方法中存入一组数据，然后放在request中，最后使用mapping.findForward进行跳转。</p>
<pre class="java" style="border-right: #333333 thin ridge; border-top: #333333 thin ridge; border-left: #333333 thin ridge; border-bottom: #333333 thin ridge; background-color: #cccccc" width="500" name="CodeLight_code" height="400">
package cn.ineeke.struts;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class IterateAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List userList = new ArrayList();
for(int i=0;i&lt;10;i++){
User user = new User();
user.setUid(i);
user.setUserName(&quot;neeke&quot;+i);
user.setPassword(&quot;neeke&quot;+i);
userList.add(user);
}
request.setAttribute(&quot;userList&quot;, userList);
return mapping.findForward(&quot;success&quot;);
}
}
</pre>
<p>Struts-config.xml是这样配置的：</p>
<pre class="xml" style="border-right: #333333 thin ridge; border-top: #333333 thin ridge; border-left: #333333 thin ridge; border-bottom: #333333 thin ridge; background-color: #cccccc" width="500" name="CodeLight_code" height="400">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE struts-config PUBLIC &quot;-//Apache Software Foundation//DTD Struts Configuration 1.3//EN&quot; &quot;http://struts.apache.org/dtds/struts-config_1_3.dtd&quot;&gt;
&lt;struts-config&gt;
&lt;form-beans /&gt;
&lt;global-exceptions /&gt;
&lt;global-forwards /&gt;
&lt;action-mappings&gt;
&lt;action path=&quot;/iterate&quot; type=&quot;cn.ineeke.struts.IterateAction&quot;&gt;
&lt;forward name=&quot;success&quot; path=&quot;/iterate.jsp&quot;&gt;&lt;/forward&gt;
&lt;/action&gt;
&lt;/action-mappings&gt;
&lt;message-resources parameter=&quot;cn.ineeke.struts.ApplicationResources&quot; /&gt;
&lt;/struts-config&gt;
</pre>
<p>上面只是为了为我们提供一组数据，当然你也可以使用其他方式。接下来才是重点了。</p>
<pre class="html" style="border-right: #333333 thin ridge; border-top: #333333 thin ridge; border-left: #333333 thin ridge; border-bottom: #333333 thin ridge; background-color: #cccccc" width="500" name="CodeLight_code" height="400">
&lt;%@ page language=&quot;java&quot; import=&quot;java.util.*&quot; pageEncoding=&quot;UTF-8&quot;%&gt;
&lt;%@ taglib prefix=&quot;logic&quot; uri=&quot;http://struts.apache.org/tags-logic&quot;%&gt;
&lt;%@ taglib prefix=&quot;bean&quot; uri=&quot;http://struts.apache.org/tags-bean&quot; %&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;logic iterate学习&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;iterate.do&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;测试iterate&quot;&gt;
&lt;/form&gt;
&lt;logic:empty name=&quot;userList&quot; scope=&quot;request&quot;&gt;
没有符合条件的数据
&lt;/logic:empty&gt;
&lt;logic:notEmpty name=&quot;userList&quot; scope=&quot;request&quot;&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;logic:iterate id=&quot;user&quot; name=&quot;userList&quot;&gt;
&lt;tr&gt;
&lt;td&gt;&lt;bean:write name=&quot;user&quot; property=&quot;uid&quot; /&gt;&lt;/td&gt;
&lt;td&gt;&lt;bean:write name=&quot;user&quot; property=&quot;userName&quot; /&gt;&lt;/td&gt;
&lt;td&gt;&lt;bean:write name=&quot;user&quot; property=&quot;password&quot; /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/logic:iterate&gt;
&lt;/table&gt;
&lt;/logic:notEmpty&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>上面的代码我们一一进行一下解说。<br />
&lt;logic:empty&gt;若scope中的userList为空则输出&ldquo;没有符合条件的数据&rdquo;。<br />
&lt;logic:notEmpty&gt;上面的你都知道了，这个还用说吗？O(&cap;_&cap;)O~<br />
重点&lt;logic:iterate&gt;出现了！其name属性就是使用request.setAttribute(&quot;userList&quot;, userList)存在request中的userList，id属性代表userList中的每一个user对象，确切的说应该是当前循环到的user对象。<br />
至于&lt;bean:write&gt;嘛，可以先看看[<a target="_blank" href="http://www.ineeke.com/archives/StrutsBeanWriteFilter/">Struts bean:write filter</a>] 一文。这里要说的是其property属性，这里我们要输出的是当前user的某一属性，而不是user这个对象，所以我们需要加上property。类似于&lt;%=user.getUserName()%&gt;。<br />
最后我们再来看看这里用Java代码如何实现。</p>
<pre class="html" style="border-right: #333333 thin ridge; border-top: #333333 thin ridge; border-left: #333333 thin ridge; border-bottom: #333333 thin ridge; background-color: #cccccc" width="500" name="CodeLight_code" height="400">
&lt;%@ page language=&quot;java&quot; import=&quot;java.util.*,cn.ineeke.struts.*&quot; pageEncoding=&quot;UTF-8&quot;%&gt;
&lt;%@ taglib prefix=&quot;logic&quot; uri=&quot;http://struts.apache.org/tags-logic&quot;%&gt;
&lt;%@ taglib prefix=&quot;bean&quot; uri=&quot;http://struts.apache.org/tags-bean&quot; %&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;logic iterate学习&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;iterate.do&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;测试iterate&quot;&gt;
&lt;/form&gt;
&lt;%
List userList = (List)request.getAttribute(&quot;userList&quot;);
if(userList == null || userList.size() == 0){
%&gt;
没有符合条件的数据
&lt;%
}else{
%&gt;
&lt;table border=&quot;1&quot;&gt;
&lt;%
for(int i=0;i&lt;userList.size();i++){
User user = (User)userList.get(i);
%&gt;
&lt;tr&gt;
&lt;td&gt;&lt;%=user.getUid() %&gt;&lt;/td&gt;&lt;td&gt;&lt;%=user.getUserName() %&gt;&lt;/td&gt;&lt;td&gt;&lt;%=user.getPassword() %&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;%
}
%&gt;
&lt;/table&gt;
&lt;%
}
%&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>怎么样？如果我前面那几个标签解释的不太清楚的话，对比之下你应该能够明白了吧？标签是多么的整洁，Java代码方式多么的乱&#8230;O(&cap;_&cap;)O哈哈~</p>
<p><object id="jssc4" height="1" align="middle" width="1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="sameDomain" name="allowScriptAccess" /><param value="false" name="allowFullScreen" /><param value="http://www.ineeke.com/PLUGIN/Codelight/Jssc4/jssc4.swf" name="movie" /><param value="high" name="quality" /><param value="#ffffff" name="bgcolor" /><embed name="jssc4" height="1" align="middle" width="1" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="false" allowscriptaccess="sameDomain" bgcolor="#ffffff" quality="high" src="http://www.ineeke.com/PLUGIN/Codelight/Jssc4/jssc4.swf"></embed></object></p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2008年12月14日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFormat/" title="Struts bean:write format">Struts bean:write format</a><br /><small>在[Struts bean:write filter] 一文中我们了解了Stru...</small></li><li>2008年12月13日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFilter/" title="Struts bean:write filter">Struts bean:write filter</a><br /><small>Struts中的&lt;bean:write name=&quot;neeke&...</small></li><li>2008年11月24日 -- <a href="http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/" title="Struts的工作原理">Struts的工作原理</a><br /><small>昨天写了那个[struts工作流程分析] 感觉有点乱，今天整理了一下，当然不是我...</small></li><li>2008年08月20日 -- <a href="http://www.ineeke.com/archives/shenmeshi-struts/" title="什么是Struts">什么是Struts</a><br /><small>Struts是骨架、支柱的意思。Struts框架的目的也是提供一个实现MVC模式...</small></li><li>2008年08月19日 -- <a href="http://www.ineeke.com/archives/weishenme-shiyong-struts/" title="为什么使用Struts">为什么使用Struts</a><br /><small>古语有云“没有绳子的世界是乱世”。JSP、Servlet和JavaBean技术的...</small></li><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li><li>2008年12月20日 -- <a href="http://www.ineeke.com/archives/StrutsFileUpload/" title="Struts实现文件上传">Struts实现文件上传</a><br /><small>客户端浏览器向WEB服务器上传文件是件比较复杂的事，之前我们有[jsp实现文件上...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Struts bean:write format</title>
		<link>http://www.ineeke.com/archives/StrutsBeanWriteFormat/</link>
		<comments>http://www.ineeke.com/archives/StrutsBeanWriteFormat/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 08:02:42 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[struts bean format]]></category>
		<category><![CDATA[struts bean标签]]></category>
		<category><![CDATA[struts 标签]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/struts-beanwrite-format/</guid>
		<description><![CDATA[<p>在[<a href="../../../../archives/StrutsBeanWriteFilter/" target="_blank">Struts bean:write filter</a>] 一文中我们了解了Struts中bean:write标签的filter属性。接下来我们来看看如何使用Struts中bean:write的format属性。</p>
]]></description>
			<content:encoded><![CDATA[<p>在[</p>
<p><a href="../../../archives/StrutsBeanWriteFilter/" target="_blank">Struts bean:write filter</a>
<p>] 一文中我们了解了Struts中bean:write标签的filter属性。接下来我们来看看如何使用Struts中bean:write的format属性。<br />首先我们来看看如何使用format属性进行格式化输出。我们在request中放入当前时间。<br />request.setAttribute(&quot;time&quot;, new Date());<br />在JSP页面中，倘若我们不使用format属性进行格式化，而直接使用&lt;bean:write name=&quot;time&quot; scope=&quot;request&quot;/&gt;进行输出，其输出结果将是：<br />Sun Dec 14 15:38:51 CST 2008 <br />然而我们通常不习惯于使用这种格式，如果我们希望输出这种格式2008-12-14 15:41:12呢？很简单！我们将其代码修改成这样：<br />&lt;bean:write name=&quot;time&quot; scope=&quot;request&quot; format=&quot;yyyy-MM-dd HH:mm:ss&quot;/&gt;<br />这里format属性中的内容我想不需要解释吧？O(&cap;_&cap;)O~<br />时间可以格式化，那么数字呢？<br />我们向request中放入圆周率request.setAttribute(&quot;n&quot;, 3.14159265358979323846)。若直接使用&lt;bean:write name=&quot;n&quot; scope=&quot;request&quot;/&gt;进行输出，那结果肯定是原封不动的3.14159265358979323846了。如果我们希望小数点后保留4位呢？也很简单！代码修改为：<br />&lt;bean:write name=&quot;n&quot; scope=&quot;request&quot; format=&quot;#.####&quot; /&gt;<br />再想想，如果我们放进去的是3.14呢？我们输出却要小数点后保留4位，不足4位用0补上呢？用上面的方式我们得到将还是3.14，这又该怎么改呢？<br />It&#8217;s very easy!!一个非常小的改动：<br />&lt;bean:write name=&quot;n&quot; scope=&quot;request&quot; format=&quot;0.0000&quot; /&gt;或者&lt;bean:write name=&quot;n&quot; scope=&quot;request&quot; format=&quot;#.0000&quot; /&gt;<br />有人会发现这里的&ldquo;#&rdquo;与&ldquo;0&rdquo;好像通用，于是写成&lt;bean:write name=&quot;n&quot; scope=&quot;request&quot; format=&quot;#.##00&quot; /&gt;，认为这样也可以，究竟行不行自己动手试试吧。&nbsp;</p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2008年12月17日 -- <a href="http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/" title="Struts logic:iterate">Struts logic:iterate</a><br /><small>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的logi...</small></li><li>2008年12月13日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFilter/" title="Struts bean:write filter">Struts bean:write filter</a><br /><small>Struts中的&lt;bean:write name=&quot;neeke&...</small></li><li>2008年11月24日 -- <a href="http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/" title="Struts的工作原理">Struts的工作原理</a><br /><small>昨天写了那个[struts工作流程分析] 感觉有点乱，今天整理了一下，当然不是我...</small></li><li>2008年08月20日 -- <a href="http://www.ineeke.com/archives/shenmeshi-struts/" title="什么是Struts">什么是Struts</a><br /><small>Struts是骨架、支柱的意思。Struts框架的目的也是提供一个实现MVC模式...</small></li><li>2008年08月19日 -- <a href="http://www.ineeke.com/archives/weishenme-shiyong-struts/" title="为什么使用Struts">为什么使用Struts</a><br /><small>古语有云“没有绳子的世界是乱世”。JSP、Servlet和JavaBean技术的...</small></li><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li><li>2008年12月20日 -- <a href="http://www.ineeke.com/archives/StrutsFileUpload/" title="Struts实现文件上传">Struts实现文件上传</a><br /><small>客户端浏览器向WEB服务器上传文件是件比较复杂的事，之前我们有[jsp实现文件上...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/StrutsBeanWriteFormat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Struts bean:write filter</title>
		<link>http://www.ineeke.com/archives/StrutsBeanWriteFilter/</link>
		<comments>http://www.ineeke.com/archives/StrutsBeanWriteFilter/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 07:19:48 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[struts 标签]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/struts-beanwrite-filter/</guid>
		<description><![CDATA[<p>Struts中的&#60;bean:write name=&#34;neeke&#34; scope=&#34;request&#34; /&#62;标签相当于&#60;%=request.getAttribute(&#34;neeke&#34;)%&#62;,当然这里也不一定是request,也可能是session等，其中neeke是属性的名字。</p>
]]></description>
			<content:encoded><![CDATA[<p>Struts中的&lt;bean:write name=&quot;neeke&quot; scope=&quot;request&quot; /&gt;标签相当于&lt;%=request.getAttribute(&quot;neeke&quot;)%&gt;,当然这里也不一定是request,也可能是session等，其中neeke是属性的名字。</p>
<p>首先我们来看一看action中的代码。</p>
<div class="HighLighter" contenteditable="false">
<div class="dp-highlighter" contenteditable="false">
<div class="bar">&nbsp;</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">package</span><span>&nbsp;cn.ineeke.struts; </span></span></li>
<li>&nbsp;</li>
<li class="alt"><span class="keyword">import</span><span>&nbsp;javax.servlet.http.HttpServletRequest; </span></li>
<li><span class="keyword">import</span><span>&nbsp;javax.servlet.http.HttpServletResponse; </span></li>
<li class="alt">&nbsp;</li>
<li><span class="keyword">import</span><span>&nbsp;org.apache.struts.action.Action; </span></li>
<li class="alt"><span class="keyword">import</span><span>&nbsp;org.apache.struts.action.ActionForm; </span></li>
<li><span class="keyword">import</span><span>&nbsp;org.apache.struts.action.ActionForward; </span></li>
<li class="alt"><span class="keyword">import</span><span>&nbsp;org.apache.struts.action.ActionMapping; </span></li>
<li>&nbsp;</li>
<li class="alt"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;BeanWriteAction&nbsp;</span><span class="keyword">extends</span><span>&nbsp;Action&nbsp;{ </span></li>
<li>&nbsp;</li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="annotation">@Override</span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;ActionForward&nbsp;execute(ActionMapping&nbsp;mapping,&nbsp;ActionForm&nbsp;form, </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response) </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">throws</span><span>&nbsp;Exception&nbsp;{ </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.setAttribute(</span><span class="string">&quot;myblog&quot;</span><span>,&nbsp;</span><span class="string">&quot;&lt;a&nbsp;href=&#8217;http://www.ineeke.com&#8217;&gt;http://www.ineeke.com&lt;/a&gt;&quot;</span><span>); </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span>&nbsp;mapping.findForward(</span><span class="string">&quot;success&quot;</span><span>); </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;} </span></li>
<li>&nbsp;</li>
<li class="alt"><span>}</span></li>
</ol>
</div>
<div class="java" contenteditable="false" style="display: none">
<pre>package cn.ineeke.struts;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;public class BeanWriteAction extends Action {	@Override	public ActionForward execute(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {			request.setAttribute(&quot;myblog&quot;, &quot;&lt;a href='http://www.ineeke.com'&gt;http://www.ineeke.com&lt;/a&gt;&quot;);			return mapping.findForward(&quot;success&quot;);	}}</pre>
</div>
<div contenteditable="false">
<link href="http://www.ineeke.com/admin/FCKeditor/editor/plugins/highlighter/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css" type="text/css" rel="stylesheet" /></div>
</div>
<p>上面这段代码的作用很简单，就是向request中存值，接着跳转到成功页面。再来看看成功页的代码是什么样的。</p>
<div class="HighLighter" contenteditable="false">
<div class="dp-highlighter" contenteditable="false">
<div class="bar">&nbsp;</div>
<ol class="dp-j">
<li class="alt"><span><span>&lt;%@&nbsp;page&nbsp;language=</span><span class="string">&quot;java&quot;</span><span>&nbsp;</span><span class="keyword">import</span><span>=</span><span class="string">&quot;java.util.*&quot;</span><span>&nbsp;pageEncoding=</span><span class="string">&quot;UTF-8&quot;</span><span>%&gt; </span></span></li>
<li><span>&lt;%@&nbsp;taglib&nbsp;prefix=</span><span class="string">&quot;bean&quot;</span><span>&nbsp;uri=</span><span class="string">&quot;http://struts.apache.org/tags-bean&quot;</span><span>&nbsp;%&gt; </span></li>
<li class="alt"><span>&lt;!DOCTYPE&nbsp;HTML&nbsp;PUBLIC&nbsp;</span><span class="string">&quot;-//W3C//DTD&nbsp;HTML&nbsp;4.01&nbsp;Transitional//EN&quot;</span><span>&gt; </span></li>
<li><span>&lt;html&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&lt;head&gt;&nbsp; </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Struts标签BeanWrite学习&lt;/title&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&lt;/head&gt; </span></li>
<li><span>&nbsp;&nbsp;&lt;body&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;bean:write&nbsp;name=</span><span class="string">&quot;myblog&quot;</span><span>&nbsp;scope=</span><span class="string">&quot;request&quot;</span><span>/&gt; </span></li>
<li><span>&nbsp;&nbsp;&lt;/body&gt; </span></li>
<li class="alt"><span>&lt;/html&gt;</span></li>
</ol>
</div>
<div class="java" contenteditable="false" style="display: none">
<pre>&lt;%@ page language=&quot;java&quot; import=&quot;java.util.*&quot; pageEncoding=&quot;UTF-8&quot;%&gt;&lt;%@ taglib prefix=&quot;bean&quot; uri=&quot;http://struts.apache.org/tags-bean&quot; %&gt;&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;&lt;html&gt;  &lt;head&gt;     &lt;title&gt;Struts标签BeanWrite学习&lt;/title&gt;  &lt;/head&gt;  &lt;body&gt;    &lt;bean:write name=&quot;myblog&quot; scope=&quot;request&quot;/&gt;  &lt;/body&gt;&lt;/html&gt;</pre>
</div>
<div contenteditable="false">
<link href="http://www.ineeke.com/admin/FCKeditor/editor/plugins/highlighter/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css" type="text/css" rel="stylesheet" /></div>
</div>
<p>在上面的代码中，我们使用&lt;bean:write&gt;标签从request中将myblog取出并显示在网页上。此时是按照文本格式直接输出的，而我们存放的时候是带HTML代码的，如果我们想让它以超级链接的形式显示在网页中呢？<br />其实这很简单，此标签有一个filter属性，其意在于是否以文本格式输出，默认情况下其值为true，所以我们只需将其改为如下所示即可。<br />&lt;bean:write name=&quot;myblog&quot; scope=&quot;request&quot; filter=&quot;false&quot;/&gt;</p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2008年12月17日 -- <a href="http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/" title="Struts logic:iterate">Struts logic:iterate</a><br /><small>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的logi...</small></li><li>2008年12月14日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFormat/" title="Struts bean:write format">Struts bean:write format</a><br /><small>在[Struts bean:write filter] 一文中我们了解了Stru...</small></li><li>2008年11月24日 -- <a href="http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/" title="Struts的工作原理">Struts的工作原理</a><br /><small>昨天写了那个[struts工作流程分析] 感觉有点乱，今天整理了一下，当然不是我...</small></li><li>2008年08月20日 -- <a href="http://www.ineeke.com/archives/shenmeshi-struts/" title="什么是Struts">什么是Struts</a><br /><small>Struts是骨架、支柱的意思。Struts框架的目的也是提供一个实现MVC模式...</small></li><li>2008年08月19日 -- <a href="http://www.ineeke.com/archives/weishenme-shiyong-struts/" title="为什么使用Struts">为什么使用Struts</a><br /><small>古语有云“没有绳子的世界是乱世”。JSP、Servlet和JavaBean技术的...</small></li><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li><li>2008年12月20日 -- <a href="http://www.ineeke.com/archives/StrutsFileUpload/" title="Struts实现文件上传">Struts实现文件上传</a><br /><small>客户端浏览器向WEB服务器上传文件是件比较复杂的事，之前我们有[jsp实现文件上...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/StrutsBeanWriteFilter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>学习Struts DispatchAction</title>
		<link>http://www.ineeke.com/archives/XueXiStrutsDispatchAction/</link>
		<comments>http://www.ineeke.com/archives/XueXiStrutsDispatchAction/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 03:47:52 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[dispatchaction用法]]></category>
		<category><![CDATA[dispatchaction配置]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/%e5%ad%a6%e4%b9%a0struts-dispatchaction/</guid>
		<description><![CDATA[<p>一般我们都是一个表单根据不同的业务提交给不同的Action去处理。可是如果一个项目很大，那么我需要编写的Action就暴增了，这样容易发生混乱。如何才能使用一个Action来处理这些操作呢？那就需要DispatchAction了。</p>
]]></description>
			<content:encoded><![CDATA[<p>一般我们都是一个表单根据不同的业务提交给不同的Action去处理。可是如果一个项目很大，那么我需要编写的Action就暴增了，这样容易发生混乱。如何才能使用一个Action来处理这些操作呢？那就需要DispatchAction了。<br />通常，一个Actio中只能完成一种业务操作，通过扩展org.apache.struts.actions.DispatchAction实现的Action类可以完成一组相关的几种业务操作。扩展自DispatchAction的Action类中不必定义execute方法，而是创建一些实现实际业务操作的方法，如doAdd()、doSubtract()等，但是这些业务方法的传入参数和返回值要和普通的Action中的execute方法相同。下面我们以一个简单的计算器为例来讲解。</p>
<p>JSP页面上我们编写这样的代码：</p>
<div class="HighLighter" contenteditable="false">
<div class="dp-highlighter" contenteditable="false">
<div class="bar">&nbsp;</div>
<ol class="dp-j">
<li class="alt"><span><span>&lt;%@&nbsp;page&nbsp;language=</span><span class="string">&quot;java&quot;</span><span>&nbsp;</span><span class="keyword">import</span><span>=</span><span class="string">&quot;java.util.*&quot;</span><span>&nbsp;pageEncoding=</span><span class="string">&quot;UTF-8&quot;</span><span>%&gt; </span></span></li>
<li><span>&lt;!DOCTYPE&nbsp;HTML&nbsp;PUBLIC&nbsp;</span><span class="string">&quot;-//W3C//DTD&nbsp;HTML&nbsp;4.01&nbsp;Transitional//EN&quot;</span><span>&gt; </span></li>
<li class="alt"><span>&lt;html&gt; </span></li>
<li><span>&nbsp;&nbsp;&lt;head&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;计算器&lt;/title&gt; </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;script&nbsp;type=</span><span class="string">&quot;text/javascript&quot;</span><span>&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;changeSubmit(operate){ </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(</span><span class="string">&quot;operate&quot;</span><span>).value&nbsp;=&nbsp;operate; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/script&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&lt;/head&gt; </span></li>
<li><span>&nbsp;&nbsp;&lt;body&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;form&nbsp;action=</span><span class="string">&quot;calc.do&quot;</span><span>&nbsp;method=</span><span class="string">&quot;post&quot;</span><span>&gt; </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=</span><span class="string">&quot;text&quot;</span><span>&nbsp;name=</span><span class="string">&quot;firstNumber&quot;</span><span>&gt;&lt;br&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=</span><span class="string">&quot;text&quot;</span><span>&nbsp;name=</span><span class="string">&quot;secondNumber&quot;</span><span>&gt;&lt;br&gt; </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=</span><span class="string">&quot;hidden&quot;</span><span>&nbsp;name=</span><span class="string">&quot;operate&quot;</span><span>&nbsp;id=</span><span class="string">&quot;operate&quot;</span><span>&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=</span><span class="string">&quot;submit&quot;</span><span>&nbsp;value=</span><span class="string">&quot;doAdd&quot;</span><span>&nbsp;onclick=</span><span class="string">&quot;changeSubmit(&#8216;doAdd&#8217;)&quot;</span><span>&gt; </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=</span><span class="string">&quot;submit&quot;</span><span>&nbsp;value=</span><span class="string">&quot;doSubtract&quot;</span><span>&nbsp;onclick=</span><span class="string">&quot;changeSubmit(&#8216;doSubtract&#8217;)&quot;</span><span>&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=</span><span class="string">&quot;submit&quot;</span><span>&nbsp;value=</span><span class="string">&quot;doMultiply&quot;</span><span>&nbsp;onclick=</span><span class="string">&quot;changeSubmit(&#8216;doMultiply&#8217;)&quot;</span><span>&gt; </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type=</span><span class="string">&quot;submit&quot;</span><span>&nbsp;value=</span><span class="string">&quot;doDivide&quot;</span><span>&nbsp;onclick=</span><span class="string">&quot;changeSubmit(&#8216;doDivide&#8217;)&quot;</span><span>&gt; </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt; </span></li>
<li><span>&nbsp;&nbsp;&lt;/body&gt; </span></li>
<li class="alt"><span>&lt;/html&gt;</span></li>
</ol>
</div>
<div class="java" contenteditable="false" style="display: none">
<pre>&lt;%@ page language=&quot;java&quot; import=&quot;java.util.*&quot; pageEncoding=&quot;UTF-8&quot;%&gt;&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;&lt;html&gt;  &lt;head&gt;    &lt;title&gt;计算器&lt;/title&gt;    &lt;script type=&quot;text/javascript&quot;&gt;    	function changeSubmit(operate){    		document.getElementById(&quot;operate&quot;).value = operate;    	}    &lt;/script&gt;  &lt;/head&gt;  &lt;body&gt;    &lt;form action=&quot;calc.do&quot; method=&quot;post&quot;&gt;    &lt;input type=&quot;text&quot; name=&quot;firstNumber&quot;&gt;&lt;br&gt;    &lt;input type=&quot;text&quot; name=&quot;secondNumber&quot;&gt;&lt;br&gt;    &lt;input type=&quot;hidden&quot; name=&quot;operate&quot; id=&quot;operate&quot;&gt;    &lt;input type=&quot;submit&quot; value=&quot;doAdd&quot; onclick=&quot;changeSubmit('doAdd')&quot;&gt;    &lt;input type=&quot;submit&quot; value=&quot;doSubtract&quot; onclick=&quot;changeSubmit('doSubtract')&quot;&gt;    &lt;input type=&quot;submit&quot; value=&quot;doMultiply&quot; onclick=&quot;changeSubmit('doMultiply')&quot;&gt;    &lt;input type=&quot;submit&quot; value=&quot;doDivide&quot; onclick=&quot;changeSubmit('doDivide')&quot;&gt;    &lt;/form&gt;  &lt;/body&gt;&lt;/html&gt;</pre>
</div>
<div contenteditable="false">
<link href="http://www.ineeke.com/admin/FCKeditor/editor/plugins/highlighter/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css" type="text/css" rel="stylesheet" /></div>
</div>
<p>而处理这些请求的Action的代码如下：</p>
<div class="HighLighter" contenteditable="false">
<div class="dp-highlighter" contenteditable="false">
<div class="bar">&nbsp;</div>
<ol class="dp-j">
<li class="alt"><span><span class="comment">/* </span></span></li>
<li><span>&nbsp;*&nbsp;Generated&nbsp;by&nbsp;MyEclipse&nbsp;Struts </span></li>
<li class="alt"><span>&nbsp;*&nbsp;Template&nbsp;path:&nbsp;templates/java/JavaClass.vtl </span></li>
<li><span>&nbsp;*/</span></li>
<li class="alt"><span class="keyword">package</span><span>&nbsp;cn.ineeke.struts.action; </span></li>
<li>&nbsp;</li>
<li class="alt"><span class="keyword">import</span><span>&nbsp;javax.servlet.http.HttpServletRequest; </span></li>
<li><span class="keyword">import</span><span>&nbsp;javax.servlet.http.HttpServletResponse; </span></li>
<li class="alt">&nbsp;</li>
<li><span class="keyword">import</span><span>&nbsp;org.apache.struts.action.ActionForm; </span></li>
<li class="alt"><span class="keyword">import</span><span>&nbsp;org.apache.struts.action.ActionMapping; </span></li>
<li><span class="keyword">import</span><span>&nbsp;org.apache.struts.actions.DispatchAction; </span></li>
<li class="alt">&nbsp;</li>
<li><span class="keyword">import</span><span>&nbsp;cn.ineeke.struts.form.CalcForm; </span></li>
<li class="alt">&nbsp;</li>
<li><span class="comment">/**&nbsp; </span></li>
<li class="alt"><span>&nbsp;*&nbsp;MyEclipse&nbsp;Struts </span></li>
<li><span>&nbsp;*&nbsp;Creation&nbsp;date:&nbsp;12-03-2008 </span></li>
<li class="alt"><span>&nbsp;*&nbsp; </span></li>
<li><span>&nbsp;*&nbsp;XDoclet&nbsp;definition: </span></li>
<li class="alt"><span>&nbsp;*&nbsp;@struts.action&nbsp;path=&quot;/calc&quot;&nbsp;name=&quot;CalcForm&quot;&nbsp;parameter=&quot;operate&quot;&nbsp;scope=&quot;requ<br />
est&quot; </span></li>
<li><span>&nbsp;*&nbsp;@author&nbsp;Neeke&nbsp;http://www.ineeke.com </span></li>
<li class="alt"><span>&nbsp;*/</span></li>
<li><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;CalcAction&nbsp;</span><span class="keyword">extends</span><span>&nbsp;DispatchAction&nbsp;{ </span></li>
<li class="alt">&nbsp;</li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;doAdd(ActionMapping&nbsp;mapping,&nbsp;ActionForm&nbsp;form, </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response) </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">throws</span><span>&nbsp;Exception&nbsp;{ </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CalcForm&nbsp;calcForm&nbsp;=&nbsp;(CalcForm)form; </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(calcForm.getFirstNumber()+calcForm.getSecondNumber()); </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;} </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;doSubtract(ActionMapping&nbsp;mapping,&nbsp;ActionForm&nbsp;form, </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response) </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">throws</span><span>&nbsp;Exception&nbsp;{ </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CalcForm&nbsp;calcForm&nbsp;=&nbsp;(CalcForm)form; </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(calcForm.getFirstNumber()-calcForm.getSecondNumber()); </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;} </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;doMultiply(ActionMapping&nbsp;mapping,&nbsp;ActionForm&nbsp;form, </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response) </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">throws</span><span>&nbsp;Exception&nbsp;{ </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CalcForm&nbsp;calcForm&nbsp;=&nbsp;(CalcForm)form; </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(calcForm.getFirstNumber()*calcForm.getSecondNumber()); </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;} </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;doDivide(ActionMapping&nbsp;mapping,&nbsp;ActionForm&nbsp;form, </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response) </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">throws</span><span>&nbsp;Exception&nbsp;{ </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CalcForm&nbsp;calcForm&nbsp;=&nbsp;(CalcForm)form; </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(calcForm.getFirstNumber()/calcForm.getSecondNumber()); </span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;} </span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp; </span></li>
<li class="alt"><span>}</span></li>
</ol>
</div>
<div class="java" contenteditable="false" style="display: none">
<pre>/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package cn.ineeke.struts.action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.DispatchAction;import cn.ineeke.struts.form.CalcForm;/**  * MyEclipse Struts * Creation date: 12-03-2008 *  * XDoclet definition: * @struts.action path=&quot;/calc&quot; name=&quot;CalcForm&quot; parameter=&quot;operate&quot; scope=&quot;request&quot; * @author Neeke http://www.ineeke.com */public class CalcAction extends DispatchAction {	public void doAdd(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)			throws Exception {		CalcForm calcForm = (CalcForm)form;		System.out.println(calcForm.getFirstNumber()+calcForm.getSecondNumber());	}	public void doSubtract(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)	throws Exception {		CalcForm calcForm = (CalcForm)form;		System.out.println(calcForm.getFirstNumber()-calcForm.getSecondNumber());	}	public void doMultiply(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)	throws Exception {		CalcForm calcForm = (CalcForm)form;		System.out.println(calcForm.getFirstNumber()*calcForm.getSecondNumber());	}	public void doDivide(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response)	throws Exception {		CalcForm calcForm = (CalcForm)form;		System.out.println(calcForm.getFirstNumber()/calcForm.getSecondNumber());	}	}</pre>
</div>
<div contenteditable="false">
<link href="http://www.ineeke.com/admin/FCKeditor/editor/plugins/highlighter/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css" type="text/css" rel="stylesheet" /></div>
</div>
<p>&nbsp;</p>
<p>接下来具体分析。首先定义CalcAction继承自DispatchAction。正如上面所说的，这里没有execute方法，而是直接定义相关业务操作的方法，CalcAction的配置如下：</p>
<div class="HighLighter" contenteditable="false">
<div class="dp-highlighter" contenteditable="false">
<div class="bar">&nbsp;</div>
<ol class="dp-xml">
<li class="alt"><span><span class="tag">&lt;</span><span class="tag-name">action-mappings</span><span>&nbsp;</span><span class="tag">&gt;</span></span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="tag">&lt;</span><span class="tag-name">action</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">attribute</span><span>=</span><span class="attribute-value">&quot;CalcForm&quot;</span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">&quot;CalcForm&quot;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">parameter</span><span>=</span><span class="attribute-value">&quot;operate&quot;</span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">path</span><span>=</span><span class="attribute-value">&quot;/calc&quot;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">scope</span><span>=</span><span class="attribute-value">&quot;request&quot;</span></li>
<li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">type</span><span>=</span><span class="attribute-value">&quot;cn.ineeke.struts.action.CalcAction&quot;</span></li>
<li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">validate</span><span>=</span><span class="attribute-value">&quot;false&quot;</span><span>&nbsp;</span><span class="tag">/&gt;</span></li>
<li><span class="tag">&lt;/</span><span class="tag-name">action-mappings</span><span class="tag">&gt;</span></li>
</ol>
</div>
<div class="xml" contenteditable="false" style="display: none">
<pre>&lt;action-mappings &gt;    &lt;act
ion      attribute=&quot;CalcForm&quot;      name=&quot;CalcForm&quot;      parameter=&quot;operate&quot;      path=&quot;/calc&quot;      scope=&quot;request&quot;      type=&quot;cn.ineeke.struts.action.CalcAction&quot;      validate=&quot;false&quot; /&gt;&lt;/action-mappings&gt;</pre>
</div>
<div contenteditable="false">
<link href="http://www.ineeke.com/admin/FCKeditor/editor/plugins/highlighter/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css" type="text/css" rel="stylesheet" /></div>
</div>
<p>与普通的Action唯一不同之处就是多了一个parameter属性。这个属性告诉Struts从请求对象中找名称为operate的参数值，参数值是什么就到CalcAction中执行与之同名的方法。在表单提交时，使用JavaScript将隐藏表单域operate的值修改为想要执行的CalcAction中的方法名。<br />最后，在DispatchAction中，方法名的前缀也常常遵循一定的规则：转到编辑页面的方法常命名为toEdit;执行编辑操作的方法常命名为doEdit;以此类推。通过这样的命名、可以使程序逻辑更清晰，减少出错几率。</p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li><li>2008年12月20日 -- <a href="http://www.ineeke.com/archives/StrutsFileUpload/" title="Struts实现文件上传">Struts实现文件上传</a><br /><small>客户端浏览器向WEB服务器上传文件是件比较复杂的事，之前我们有[jsp实现文件上...</small></li><li>2008年12月19日 -- <a href="http://www.ineeke.com/archives/StrutsDynaActionForm/" title="Struts DynaActionForm配置">Struts DynaActionForm配置</a><br /><small>为什么要有动态ActionForm呢？若在一个大型项目中，我们的ActionFo...</small></li><li>2008年12月17日 -- <a href="http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/" title="Struts logic:iterate">Struts logic:iterate</a><br /><small>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的logi...</small></li><li>2008年12月14日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFormat/" title="Struts bean:write format">Struts bean:write format</a><br /><small>在[Struts bean:write filter] 一文中我们了解了Stru...</small></li><li>2008年12月13日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFilter/" title="Struts bean:write filter">Struts bean:write filter</a><br /><small>Struts中的&lt;bean:write name=&quot;neeke&...</small></li><li>2008年11月24日 -- <a href="http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/" title="Struts的工作原理">Struts的工作原理</a><br /><small>昨天写了那个[struts工作流程分析] 感觉有点乱，今天整理了一下，当然不是我...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/XueXiStrutsDispatchAction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Struts的工作原理</title>
		<link>http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/</link>
		<comments>http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 04:16:04 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[struts 标签]]></category>
		<category><![CDATA[struts工作流程]]></category>
		<category><![CDATA[struts流程]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/struts%e7%9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86/</guid>
		<description><![CDATA[<p>昨天写了那个[<a href="http://www.ineeke.com/archives/StrutsGongZuoLiuChengFenXi/" target="_blank">struts工作流程分析</a>] 感觉有点乱，今天整理了一下，当然不是我自己研究出来的，我喜欢看完技术资料后用自己所理解的意思去表述一遍，当然我有时也会原文转来。今天又增加了一个栏目《<a target="_blank" href="http://www.ineeke.com/archives/XiTongLouDong/">系统漏洞</a>》，这里的漏洞就更不可能是我发现的了，都是直接转来的。博客是不是必须纯原创我才不去管它，我只关注和学习我所感兴趣的。</p>
]]></description>
			<content:encoded><![CDATA[<p>昨天写了那个[<a href="http://www.ineeke.com/archives/StrutsGongZuoLiuChengFenXi/" target="_blank">struts工作流程分析</a>] 感觉有点乱，今天整理了一下，当然不是我自己研究出来的，我喜欢看完技术资料后用自己所理解的意思去表述一遍，当然我有时也会原文转来。今天又增加了一个栏目《<a target="_blank" href="http://www.ineeke.com/archives/XiTongLouDong/">系统漏洞</a>》，这里的漏洞就更不可能是我发现的了，都是直接转来的。博客是不是必须纯原创我才不去管它，我只关注和学习我所感兴趣的。</p>
<p>struts的工作原理可分为如下8步。</p>
<p>1.读取配置（初始化ModuleConfig对象）<br />Struts框架总控制器（ActionServlet）是一个Servlet，在web.xml中被配置成一个自动启动的Servlet。读取配置文件struts-config.xml的配置信息，为不同的Struts模块初始化相应的ModuleConfig对象。</p>
<p>2.用户请求<br />用户提交表单或调用URL向WEB应用程序服务器提交一个请求，请求的数据用HTTP协议上传给WEB服务器。</p>
<p>3.填充FormBean<br />（*.do请求）从ActionConfig中找出对应该请求的Action子类，如有对应的Action且这个Action又一个相应的ActionForm，ActionForm被实例化并用HTTP请求的数据填充其属性，并保存在ServletContext中，这样他们就可以被其它Action对象或JSP调用。如果没有对应的Action，控制器则直接转发给JSP或静态页面。</p>
<p>4.派发请求<br />控制器根据配置信息ActionConfig将请求派发到具体的Action，相应的FormBean一并传给这个Action的execute()方法。</p>
<p>5.处理业务<br />Action一般只包含一个execute方法，它负责执行相应的业务逻辑。执行完毕后返回一个ActionFoward对象，控制器通过该ActionFoward对象来进行转发工作。</p>
<p>6.返回响应<br />Action根据业务处理的不同结果返回一个响应对象给总控制器，该目标响应对相对应一个具体的JSP页面或另一个Action。</p>
<p>7.查找响应<br />总控制器根据业务功能Action返回的目标响应对象找到对应的资源对象，通常是一个具体的JSP页面。</p>
<p>8.响应用户<br />JSP将结果展现给用户。</p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2008年12月17日 -- <a href="http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/" title="Struts logic:iterate">Struts logic:iterate</a><br /><small>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的logi...</small></li><li>2008年12月14日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFormat/" title="Struts bean:write format">Struts bean:write format</a><br /><small>在[Struts bean:write filter] 一文中我们了解了Stru...</small></li><li>2008年12月13日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFilter/" title="Struts bean:write filter">Struts bean:write filter</a><br /><small>Struts中的&lt;bean:write name=&quot;neeke&...</small></li><li>2008年11月23日 -- <a href="http://www.ineeke.com/archives/StrutsGongZuoLiuChengFenXi/" title="struts工作流程分析">struts工作流程分析</a><br /><small>技术关键在于学习其原理，而不是浅浅淡淡的会用，免得别人问起的时候什么也不知道，尤...</small></li><li>2008年08月20日 -- <a href="http://www.ineeke.com/archives/shenmeshi-struts/" title="什么是Struts">什么是Struts</a><br /><small>Struts是骨架、支柱的意思。Struts框架的目的也是提供一个实现MVC模式...</small></li><li>2008年08月19日 -- <a href="http://www.ineeke.com/archives/weishenme-shiyong-struts/" title="为什么使用Struts">为什么使用Struts</a><br /><small>古语有云“没有绳子的世界是乱世”。JSP、Servlet和JavaBean技术的...</small></li><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>什么是Struts</title>
		<link>http://www.ineeke.com/archives/shenmeshi-struts/</link>
		<comments>http://www.ineeke.com/archives/shenmeshi-struts/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 16:02:11 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[struts 标签]]></category>
		<category><![CDATA[struts2是什么]]></category>
		<category><![CDATA[struts教程]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/%e4%bb%80%e4%b9%88%e6%98%afstruts/</guid>
		<description><![CDATA[Struts是骨架、支柱的意思。Struts框架的目的也是提供一个实现MVC模式的应用程序骨架。
它出身显赫，来自Apache。Apache是一个著名的开源组织，其下有很多广泛应用的开源项目。我们一直在使用的Tomcat就是他们的一个子项目。Apache在Java世界具有举足轻重的地位。
基于Struts开发的应用由3类组建构成：控制器组件、模型组件和试图组件。
控制器组件包括ActionServlet，是Struts的核心控制器，还包括自定义的Action类，代表客户的一个操作，自定义的Action类继承自Struts提供的org.apache.struts.action.Action。
...
]]></description>
			<content:encoded><![CDATA[<p>Struts是骨架、支柱的意思。Struts框架的目的也是提供一个实现MVC模式的应用程序骨架。<br />
它出身显赫，来自Apache。Apache是一个著名的开源组织，其下有很多广泛应用的开源项目。我们一直在使用的Tomcat就是他们的一个子项目。Apache在Java世界具有举足轻重的地位。<br />
基于Struts开发的应用由3类组建构成：控制器组件、模型组件和试图组件。<br />
控制器组件包括ActionServlet，是Struts的核心控制器，还包括自定义的Action类，代表客户的一个操作，自定义的Action类继承自Struts提供的org.apache.struts.action.Action。<br />
模型组件并不是由Struts提供的，一般由普通的接口和JavaBean充当，需要我们自己编码实现。<br />
试图组件一般由JSP实现，还包括自定义的ActionForm类和Struts标签。自定义的ActionForm类用于封装request中的数据，Struts可以将request中的数据自动填充到ActionForm类中，以避免繁琐的request.getParameter()和类型转换代码。自定义的ActionForm类继承自Struts提供的org.apache.struts.action.ActionForm。Struts还提供了一系列自定义标签以简化页面的编码。<br />
ActionForm在系统启动的时候加载struts-config.xml配置文件。struts-config.xml配置文件中包含与Action、ActionForm、页面转发等相关的配置信息。<br />
可见，Struts只是一个应用程序的“半成品”，但已经约束了在其基础上构建应用程序的规则，并给我们的代码开发工作提供了便利。</p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2008年08月19日 -- <a href="http://www.ineeke.com/archives/weishenme-shiyong-struts/" title="为什么使用Struts">为什么使用Struts</a><br /><small>古语有云“没有绳子的世界是乱世”。JSP、Servlet和JavaBean技术的...</small></li><li>2008年12月19日 -- <a href="http://www.ineeke.com/archives/StrutsDynaActionForm/" title="Struts DynaActionForm配置">Struts DynaActionForm配置</a><br /><small>为什么要有动态ActionForm呢？若在一个大型项目中，我们的ActionFo...</small></li><li>2008年12月17日 -- <a href="http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/" title="Struts logic:iterate">Struts logic:iterate</a><br /><small>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的logi...</small></li><li>2008年12月14日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFormat/" title="Struts bean:write format">Struts bean:write format</a><br /><small>在[Struts bean:write filter] 一文中我们了解了Stru...</small></li><li>2008年12月13日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFilter/" title="Struts bean:write filter">Struts bean:write filter</a><br /><small>Struts中的&lt;bean:write name=&quot;neeke&...</small></li><li>2008年11月24日 -- <a href="http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/" title="Struts的工作原理">Struts的工作原理</a><br /><small>昨天写了那个[struts工作流程分析] 感觉有点乱，今天整理了一下，当然不是我...</small></li><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/shenmeshi-struts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>为什么使用Struts</title>
		<link>http://www.ineeke.com/archives/weishenme-shiyong-struts/</link>
		<comments>http://www.ineeke.com/archives/weishenme-shiyong-struts/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 16:53:20 +0000</pubDate>
		<dc:creator>Neeke</dc:creator>
				<category><![CDATA[J2EE技术]]></category>
		<category><![CDATA[struts]]></category>
		<category><![CDATA[struts 标签]]></category>
		<category><![CDATA[struts教程]]></category>

		<guid isPermaLink="false">http://ineeke.com/archives/%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bd%bf%e7%94%a8struts/</guid>
		<description><![CDATA[古语有云“没有绳子的世界是乱世”。JSP、Servlet和JavaBean技术的出现给我们构建强大的企业应用系统提供了可能。在此之上，我们还需要一个规则，一个把这些技术有效的组织起来，让系统繁而不乱的规则，这就是框架。Struts应运而生，是最早的开源框架之一，而且很快成为实际标准，是当前应用最广泛的Java Web应用开发框架。
在Struts中，可以通过struts-config.xml配置文件配置Action得访问路径，还提供了ActionForm，自动获取Request中的数据，不再需要反反复复的进行request.getParameter()，然后小心翼翼的转换类型。Struts还提供了标签库，可以方便的构建页面并获得额外的便利。作为一个成熟而完整的框架，Struts几乎处处都帮我们做好了贴心安排。...
]]></description>
			<content:encoded><![CDATA[<p>古语有云“没有绳子的世界是乱世”。JSP、Servlet和JavaBean技术的出现给我们构建强大的企业应用系统提供了可能。在此之上，我们还需要一个规则，一个把这些技术有效的组织起来，让系统繁而不乱的规则，这就是框架。Struts应运而生，是最早的开源框架之一，而且很快成为实际标准，是当前应用最广泛的Java Web应用开发框架。<br />
在Struts中，可以通过struts-config.xml配置文件配置Action得访问路径，还提供了ActionForm，自动获取Request中的数据，不再需要反反复复的进行request.getParameter()，然后小心翼翼的转换类型。Struts还提供了标签库，可以方便的构建页面并获得额外的便利。作为一个成熟而完整的框架，Struts几乎处处都帮我们做好了贴心安排。</p>
<h2  class="related_post_title">或许你会对下面这些文章感兴趣：</h2><ul class="related_post"><li>2008年08月20日 -- <a href="http://www.ineeke.com/archives/shenmeshi-struts/" title="什么是Struts">什么是Struts</a><br /><small>Struts是骨架、支柱的意思。Struts框架的目的也是提供一个实现MVC模式...</small></li><li>2008年12月19日 -- <a href="http://www.ineeke.com/archives/StrutsDynaActionForm/" title="Struts DynaActionForm配置">Struts DynaActionForm配置</a><br /><small>为什么要有动态ActionForm呢？若在一个大型项目中，我们的ActionFo...</small></li><li>2008年12月17日 -- <a href="http://www.ineeke.com/archives/StrutsLogicIterateBiaoQian/" title="Struts logic:iterate">Struts logic:iterate</a><br /><small>不想写Java中的for循环？还想用标签进行数据迭代？让Struts中的logi...</small></li><li>2008年12月14日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFormat/" title="Struts bean:write format">Struts bean:write format</a><br /><small>在[Struts bean:write filter] 一文中我们了解了Stru...</small></li><li>2008年12月13日 -- <a href="http://www.ineeke.com/archives/StrutsBeanWriteFilter/" title="Struts bean:write filter">Struts bean:write filter</a><br /><small>Struts中的&lt;bean:write name=&quot;neeke&...</small></li><li>2008年11月24日 -- <a href="http://www.ineeke.com/archives/StrutsDeGongZuoYuanLi/" title="Struts的工作原理">Struts的工作原理</a><br /><small>昨天写了那个[struts工作流程分析] 感觉有点乱，今天整理了一下，当然不是我...</small></li><li>2009年03月3日 -- <a href="http://www.ineeke.com/archives/settingmystruts2/" title="3步配置Struts2">3步配置Struts2</a><br /><small>开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。...</small></li><li>2009年02月12日 -- <a href="http://www.ineeke.com/archives/strutsspringhibernate/" title="Struts+Spring+Hibernate集成">Struts+Spring+Hibernate集成</a><br /><small>SSH集成的一个样例，放到这里方便自己以后使用。其实就是一些配置，也没什么先后顺...</small></li><li>2009年01月3日 -- <a href="http://www.ineeke.com/archives/beanutilscopyproperties/" title="疏忽下BeanUtils.copyProperties()引发的问题">疏忽下BeanUtils.copyProperties()引发的问题</a><br /><small>昨天在Action中完成某一个更新功能的时候总是无法更新成功，而且什么错误都不报...</small></li><li>2008年12月23日 -- <a href="http://www.ineeke.com/archives/Log4jPropertiesPeiZhiWenJian/" title="log4j.properties配置文件">log4j.properties配置文件</a><br /><small>在MyEclipse中配置好了Hibernate，运行的时候出现了两行红字，其意...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ineeke.com/archives/weishenme-shiyong-struts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
