<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>struts2 &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/struts2/</link>
	<description>Feed of posts on WordPress.com tagged "struts2"</description>
	<pubDate>Thu, 24 Dec 2009 03:39:41 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Struts 2.1.8 : New Plug-ins]]></title>
<link>http://igazga.wordpress.com/2009/11/20/struts-2-1-8-new-plug-ins/</link>
<pubDate>Fri, 20 Nov 2009 03:35:12 +0000</pubDate>
<dc:creator>igazga</dc:creator>
<guid>http://igazga.wordpress.com/2009/11/20/struts-2-1-8-new-plug-ins/</guid>
<description><![CDATA[ออกมาใหม่ซิงๆ ได้ไม่นาน มี Plug-ins ใหม่ OVal Plugin OSGi Plugin JSON Plugin Embedded JSP Plugin เท่]]></description>
<content:encoded><![CDATA[ออกมาใหม่ซิงๆ ได้ไม่นาน มี Plug-ins ใหม่ OVal Plugin OSGi Plugin JSON Plugin Embedded JSP Plugin เท่]]></content:encoded>
</item>
<item>
<title><![CDATA[struts 1.2 validation framework, tiles framework ...]]></title>
<link>http://struts2spring.wordpress.com/2009/11/06/struts-1-2-validation-framework-tiles-framework/</link>
<pubDate>Thu, 05 Nov 2009 18:38:01 +0000</pubDate>
<dc:creator>struts2spring</dc:creator>
<guid>http://struts2spring.wordpress.com/2009/11/06/struts-1-2-validation-framework-tiles-framework/</guid>
<description><![CDATA[This is a demo HR application in struts 1.2 to demonstrate validation framework, tiles framework . H]]></description>
<content:encoded><![CDATA[This is a demo HR application in struts 1.2 to demonstrate validation framework, tiles framework . H]]></content:encoded>
</item>
<item>
<title><![CDATA[Difference between Struts 1 &amp; Struts 2]]></title>
<link>http://allu.wordpress.com/2009/10/30/difference-between-struts-1-struts-2/</link>
<pubDate>Fri, 30 Oct 2009 19:30:46 +0000</pubDate>
<dc:creator>:)</dc:creator>
<guid>http://allu.wordpress.com/2009/10/30/difference-between-struts-1-struts-2/</guid>
<description><![CDATA[Struts 1 Struts 2 Action classes Struts 1 requires Action classes to extend an abstract base class. ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><strong></strong></td>
<td><strong>Struts 1</strong></td>
<td><strong>Struts 2</strong></td>
</tr>
<tr>
<td><strong>Action classes</strong></td>
<td>Struts 1 requires Action classes to extend an abstract base class. A common problem in Struts 1 is programming to abstract classes instead of interfaces.</td>
<td>An Struts 2 Action <em>may</em> implement an Action interface, along with other interfaces to enable optional and custom services. Struts 2 provide a base ActionSupport class to implement commonly used interfaces. Albeit, the Action interface is <strong>not</strong> required. Any POJO object with a execute signature can be used as an Struts 2 Action object.</td>
</tr>
<tr>
<td><strong>Threading Model</strong></td>
<td>Struts 1 Actions are singletons and must be thread-safe since there will only be one instance of a class to handle all requests for that Action. The singleton strategy places restrictions on what can be done with Struts 1 Actions and requires extra care to develop. Action resources must be thread-safe or synchronized.</td>
<td>Struts 2 Action objects are instantiated for each request, so there are no thread-safety issues. (In practice, servlet containers generate many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.)</td>
</tr>
<tr>
<td><strong>Servlet</strong><strong> Dependency</strong></td>
<td>Struts 1 Actions have dependencies on the servlet API since the HttpServletRequest and HttpServletResponse is passed to the execute method when an Action is invoked.</td>
<td>Struts 2 Actions are not coupled to a container. Most often the servlet contexts are represented as simple Maps, allowing Actions to be tested in isolation. Struts 2 Actions can still access the original request and response, if required. However, other architectural elements reduce or eliminate the need to access the HttpServetRequest or HttpServletResponse directly.</td>
</tr>
<tr>
<td><strong>Testability</strong></td>
<td>A major hurdle to testing Struts 1 Actions is that the execute method exposes the Servlet API. A third-party extension, Struts TestCase, offers a set of mock object for Struts 1.</td>
<td>Struts 2 Actions can be tested by instantiating the Action, setting properties, and invoking methods. Dependency Injection support also makes testing simpler.</td>
</tr>
<tr>
<td><strong>Harvesting Input</strong></td>
<td>Struts 1 uses an ActionForm object to capture input. Like Actions, all ActionForms must extend a base class. Since  other JavaBeans cannot be used as ActionForms, developers often create redundant classes to capture input. DynaBeans can used as an alternative to creating conventional ActionForm classes, but, here too, developers may be redescribing existing JavaBeans.</td>
<td>Struts 2 uses Action properties as input properties, eliminating the need for a second input object. Input properties may be rich object types which may have their own properties. The Action properties can be accessed from the web page via the taglibs. Struts 2 also support the ActionForm pattern, as well as POJO form objects and POJO Actions. Rich object types, including business or domain objects, can be used as input/output objects. The ModelDriven feature simplifies taglb references to POJO input objects.</td>
</tr>
<tr>
<td><strong>Expression Language</strong></td>
<td>Struts 1 integrates with JSTL, so it uses the JSTL EL. The EL has basic object graph traversal, but relatively weak collection and indexed property support.</td>
<td>Struts 2 can use JSTL, but the framework also supports a more powerful and flexible expression language called &#8220;Object Graph Notation Language&#8221; (OGNL).</td>
</tr>
<tr>
<td><strong>Binding values into views</strong></td>
<td>Struts 1 uses the standard JSP mechanism for binding objects into the page context for access.</td>
<td>Struts 2 uses a &#8220;ValueStack&#8221; technology so that the taglibs can access values without coupling your view to the object type it is rendering. The ValueStack strategy allows reuse of views across a range of types which may have the same property name but different property types.</td>
</tr>
<tr>
<td><strong>Type Conversion</strong></td>
<td>Struts 1 ActionForm properties are usually all Strings. Struts 1 uses Commons-Beanutils for type conversion. Converters are per-class, and not configurable per instance.</td>
<td>Struts 2 uses OGNL for type conversion. The framework includes converters for basic and common object types and primitives.</td>
</tr>
<tr>
<td><strong>Validation</strong></td>
<td>Struts 1 supports manual validation via a validate method on the ActionForm, or through an extension to the Commons Validator. Classes can have different validation contexts for the same class, but cannot chain to validations on sub-objects.</td>
<td>Struts 2 supports manual validation via the validate method and the XWork Validation framework. The Xwork Validation Framework supports chaining validation into sub-properties using the validations defined for the properties class type and the validation context.</td>
</tr>
<tr>
<td><strong>Control Of Action Execution</strong></td>
<td>Struts 1 supports separate Request Processors (lifecycles) for each module, but all the Actions in the module must share the same lifecycle.</td>
<td>Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks. Custom stacks can be created and used with different Actions, as needed.</td>
</tr>
</tbody>
</table>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Struts2+Spring plugin on Weblogic 8.1]]></title>
<link>http://emptylist.wordpress.com/2009/10/24/struts2spring-plugin-on-weblogic-8-1/</link>
<pubDate>Sat, 24 Oct 2009 07:15:54 +0000</pubDate>
<dc:creator>Andrea Cerisara</dc:creator>
<guid>http://emptylist.wordpress.com/2009/10/24/struts2spring-plugin-on-weblogic-8-1/</guid>
<description><![CDATA[Goal: to run Struts2+Spring plugin on a Weblogic 8.1 platform bundled with JDK 1.4.2_08, J2EE 1.3 (S]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:justify;"><em>Goal</em>: to run Struts2+Spring plugin on a Weblogic 8.1 platform bundled with JDK 1.4.2_08, J2EE 1.3 (Servlet 2.3 and JSP 1.2) using the backported 2.0.14 version.</p>
<p style="text-align:justify;"><em>Premise</em>: a J2EE 1.4 environment seems required to run Struts2, but some guys have successfully deployed it on a J2EE 1.3 application server like Weblogic 8.1.</p>
<p style="text-align:justify;"><a title="Struts 2.0.14 backport" href="http://apache.fis.uniroma2.it/struts/binaries/struts-2.0.14-backport.zip" target="_blank">Download</a> the backported version, the <a title="Struts 2.0.14" href="http://apache.fis.uniroma2.it/struts/library/struts-2.0.14-lib.zip" target="_blank">standard</a> version and deploy a simple Struts2 project with, at least, these dependencies:</p>
<pre class="brush: bash;">
backport-util-concurrent-3.1.jar # from backport package
commons-fileupload-1.2.1.jar # from standard package
commons-io-1.3.2.jar # from standard package
commons-logging-1.0.4.jar # from standard package
freemarker-2.3.15.jar # from standard package
ognl-2.6.11.jar # from standard package
retrotranslator-runtime-1.2.9.jar # from backport package
struts2-core-j4-2.0.14.jar # from backport package
xwork-j4-2.0.7.jar # from backport package
</pre>
<p style="text-align:justify;">You should be able to run the project without errors. You have to manually backport the plugin to use Spring as DI container (the reported error is the usual &#8220;<em>Unsupported major.minor version 49.0</em>&#8220;), typing the following command in a terminal:</p>
<pre class="brush: bash;">
java -jar retrotranslator-transformer-1.2.2.jar -advanced -srcjar $standard_package_path/lib/struts2-spring-plugin-2.0.14.jar -destjar struts2-spring-plugin-j4-2.0.14.jar
</pre>
<p style="text-align:justify;">You can find the <em>retrotranslator-transformer</em> jar in the backport package. As usual, you have to add the plugin to the classpath along with all the Spring stuff.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Optiontransferselect Tag (Form Tag) Example]]></title>
<link>http://knishe.wordpress.com/2009/10/16/optiontransferselect-tag-form-tag-example/</link>
<pubDate>Fri, 16 Oct 2009 05:55:49 +0000</pubDate>
<dc:creator>knishe</dc:creator>
<guid>http://knishe.wordpress.com/2009/10/16/optiontransferselect-tag-form-tag-example/</guid>
<description><![CDATA[JSP Pages: SampleAssignPage.jsp &lt;%&#8211; Document   : SampleAssignPage Created on : Oct 16, 2009]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>JSP Pages:</strong><span style="text-decoration:underline;"><br />
SampleAssignPage.jsp</span></p>
<blockquote><p>&#60;%&#8211;<br />
Document   : SampleAssignPage<br />
Created on : Oct 16, 2009, 8:54:48 AM<br />
Author     : Nishanthan<br />
&#8211;%&#62;</p>
<p>&#60;%@page contentType=&#8221;text/html&#8221; pageEncoding=&#8221;UTF-8&#8243;%&#62;<br />
&#60;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01 Transitional//EN&#8221;<br />
&#8220;http://www.w3.org/TR/html4/loose.dtd&#8221;&#62;<br />
&#60;%@ taglib prefix=&#8221;s&#8221; uri=&#8221;/struts-tags&#8221; %&#62;</p>
<p>&#60;html&#62;<br />
&#60;head&#62;<br />
&#60;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=UTF-8&#8243;&#62;<br />
&#60;title&#62;JSP Page&#60;/title&#62;<br />
&#60;!&#8211;  &#8211;&#62;<br />
&#60;s:head/&#62;<br />
&#60;/head&#62;<br />
&#60;body&#62;<br />
&#60;s:url id=&#8221;insert&#8221; action=&#8221;getAllDefault&#8221;/&#62;<br />
&#60;s:a href=&#8221;%{insert}&#8221;&#62;Click Here View all default values&#60;/s:a&#62;<br />
&#60;!&#8211; The above action could be automated &#8211;&#62;<br />
&#60;s:form action=&#8221;MyAssignAction&#8221;&#62;<br />
&#60;!&#8211; Dont forget to put s:head tag with in the jsp tag&#8211;&#62;<br />
&#60;s:optiontransferselect<br />
allowUpDownOnLeft=&#8221;false&#8221;<br />
allowUpDownOnRight=&#8221;false&#8221;<br />
name=&#8221;leftSide&#8221;<br />
list=&#8221;defaultLeft&#8221;<br />
doubleName=&#8221;rightSide&#8221;<br />
doubleList=&#8221;defaultRight&#8221;&#62;<br />
&#60;/s:optiontransferselect&#62;<br />
&#60;s:submit/&#62;<br />
&#60;/s:form&#62;<br />
&#60;/body&#62;<br />
&#60;/html&#62;</p></blockquote>
<p>SuccessPage.jsp</p>
<blockquote><p>&#60;%&#8211;<br />
Document   : SuccessPage<br />
Created on : Oct 16, 2009, 9:07:51 AM<br />
Author     : Nishanthan<br />
&#8211;%&#62;</p>
<p>&#60;%@page contentType=&#8221;text/html&#8221; pageEncoding=&#8221;UTF-8&#8243;%&#62;<br />
&#60;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01 Transitional//EN&#8221;<br />
&#8220;http://www.w3.org/TR/html4/loose.dtd&#8221;&#62;<br />
&#60;%@ taglib prefix=&#8221;s&#8221; uri=&#8221;/struts-tags&#8221; %&#62;</p>
<p>&#60;html&#62;<br />
&#60;head&#62;<br />
&#60;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=UTF-8&#8243;&#62;<br />
&#60;title&#62;JSP Page&#60;/title&#62;<br />
&#60;/head&#62;<br />
&#60;body&#62;<br />
&#60;h2&#62;Left List&#60;/h2&#62;<br />
&#60;table&#62;<br />
&#60;s:iterator value=&#8221;leftSide&#8221;&#62;<br />
&#60;tr&#62;<br />
&#60;td&#62;<br />
&#60;s:property/&#62;<br />
&#60;/td&#62;<br />
&#60;/tr&#62;<br />
&#60;/s:iterator&#62;<br />
&#60;/table&#62;</p>
<p>&#60;br/&#62;&#60;br/&#62;</p>
<p>&#60;h2&#62;Right List&#60;/h2&#62;<br />
&#60;table&#62;<br />
&#60;s:iterator value=&#8221;rightSide&#8221;&#62;<br />
&#60;tr&#62;<br />
&#60;td&#62;<br />
&#60;s:property/&#62;<br />
&#60;/td&#62;<br />
&#60;/tr&#62;<br />
&#60;/s:iterator&#62;<br />
&#60;/table&#62;<br />
&#60;/body&#62;<br />
&#60;/html&#62;</p></blockquote>
<p>struts.xml</p>
<blockquote><p>&#60;!DOCTYPE struts PUBLIC<br />
&#8220;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#8221;<br />
&#8220;http://struts.apache.org/dtds/struts-2.0.dtd&#8221;&#62;</p>
<p>&#60;struts&#62;<br />
&#60;include file=&#8221;example.xml&#8221;/&#62;<br />
&#60;!&#8211; Configuration for the default package. &#8211;&#62;<br />
&#60;package name=&#8221;default&#8221; extends=&#8221;struts-default&#8221;&#62;<br />
&#60;action name=&#8221;getAllDefault&#8221; method=&#8221;getAllDefault&#8221;&#62;<br />
&#60;result name=&#8221;success&#8221;&#62;/SampleAssignPage.jsp&#60;/result&#62;<br />
&#60;/action&#62;<br />
&#60;action name=&#8221;MyAssignAction&#8221;&#62;<br />
&#60;result name=&#8221;success&#8221;&#62;/SuccessPage.jsp&#60;/result&#62;<br />
&#60;/action&#62;<br />
&#60;/package&#62;<br />
&#60;/struts&#62;</p></blockquote>
<p>Action class:</p>
<p>place with in the com.mydemo.action</p>
<blockquote><p>/*<br />
* To change this template, choose Tools &#124; Templates<br />
* and open the template in the editor.<br />
*/</p>
<p>package com.mydemo.action;</p>
<p>import com.mydemo.manager.DataManager;<br />
import com.opensymphony.xwork2.ActionSupport;<br />
import java.util.List;</p>
<p>/**<br />
*<br />
* @author Nishanthan<br />
*/</p>
<p>public class AssignAction extends ActionSupport{</p>
<p>private List&#60;String&#62; leftSide;<br />
private List&#60;String&#62; rightSide;<br />
private List&#60;String&#62; defaultLeft;<br />
private List&#60;String&#62; defaultRight;</p>
<p>public AssignAction() {<br />
}</p>
<p>public List&#60;String&#62; getDefaultLeft() {<br />
return defaultLeft;<br />
}</p>
<p>public void setDefaultLeft(List&#60;String&#62; defaultLeft) {<br />
this.defaultLeft = defaultLeft;<br />
}</p>
<p>public List&#60;String&#62; getDefaultRight() {<br />
return defaultRight;<br />
}</p>
<p>public void setDefaultRight(List&#60;String&#62; defaultRight) {<br />
this.defaultRight = defaultRight;<br />
}</p>
<p>public List&#60;String&#62; getLeftSide() {<br />
return leftSide;<br />
}</p>
<p>public void setLeftSide(List&#60;String&#62; leftSide) {<br />
this.leftSide = leftSide;<br />
}</p>
<p>public List&#60;String&#62; getRightSide() {<br />
return rightSide;<br />
}</p>
<p>public void setRightSide(List&#60;String&#62; rightSide) {<br />
this.rightSide = rightSide;<br />
}</p>
<p>public String execute() throws Exception {<br />
if(this.getLeftSide()!=null){<br />
//Do some thing with left side list<br />
}else if(this.getRightSide()!=null){<br />
//Do some thing with right side list<br />
}<br />
return SUCCESS;<br />
}</p>
<p>public String getAllDefault(){<br />
this.setDefaultLeft(DataManager.getAllLeft());<br />
this.setDefaultRight(DataManager.getAllRight());<br />
return SUCCESS;<br />
}<br />
}</p></blockquote>
<p>DataManager class:</p>
<p>This class  is used to get example data.</p>
<p>place with in  com.mydemo.manager</p>
<blockquote><p>/*<br />
* To change this template, choose Tools &#124; Templates<br />
* and open the template in the editor.<br />
*/<br />
package com.mydemo.manager;</p>
<p>import java.util.ArrayList;<br />
import java.util.List;</p>
<p>/**<br />
*<br />
* @author Nishanthan<br />
*/<br />
public class DataManager {</p>
<p>private static List&#60;String&#62; defaultRight;<br />
private static List&#60;String&#62; defaultLeft;</p>
<p>public static List&#60;String&#62; getAllLeft(){<br />
defaultLeft = new ArrayList&#60;String&#62;();<br />
defaultLeft.add(&#8220;Nishanthan&#8221;);<br />
defaultLeft.add(&#8220;Jayanthan&#8221;);<br />
defaultLeft.add(&#8220;Theeepan&#8221;);<br />
return defaultLeft;<br />
}</p>
<p>public static List&#60;String&#62; getAllRight(){<br />
defaultRight = new ArrayList&#60;String&#62;();<br />
defaultRight.add(&#8220;Ragavan&#8221;);<br />
defaultRight.add(&#8220;Bharathi&#8221;);<br />
return defaultRight;<br />
}<br />
}</p></blockquote>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[1. TO-DO list: Getting started with hibernate]]></title>
<link>http://ruemarin.wordpress.com/2009/10/07/1-to-do-list-getting-started-with-hibernate/</link>
<pubDate>Wed, 07 Oct 2009 07:12:29 +0000</pubDate>
<dc:creator>ruemarin</dc:creator>
<guid>http://ruemarin.wordpress.com/2009/10/07/1-to-do-list-getting-started-with-hibernate/</guid>
<description><![CDATA[Introduction We will start the application by setting up the project. Here are the steps: Installing]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><h1>Introduction</h1>
<p>We will start the application by setting up the project. Here are the steps:</p>
<ol>
<li>Installing a database server</li>
<li>Downloading Hibernate jar files</li>
<li>Downloading the MySQL connector</li>
<li>Setting up the project and adding the references</li>
</ol>
<h1>Installing a database server</h1>
<p>I installed MySQL version 5.1 community edition.</p>
<h1>Hibernate and MySQL connector jar files</h1>
<p>You will need to download and add to your project several jar files relating to struts, hibernate, mysql &#8230;</p>
<ol>
<li>Hibernate: Download Hibernate core, annotation and validator from <a href="https://www.hibernate.org/30.html">https://www.hibernate.org/30.html</a></li>
<li>MySQL connector: <a href="http://dev.mysql.com/downloads/connector/j/3.1.html">http://dev.mysql.com/downloads/connector/j/3.1.html</a></li>
<li><a href="http://sourceforge.net/projects/hsqldb/files/">http://sourceforge.net/projects/hsqldb/files/</a></li>
<li><a href="http://code.google.com/p/full-hibernate-plugin-for-struts2/">http://code.google.com/p/full-hibernate-plugin-for-struts2/</a></li>
</ol>
<p>You can download and extract those files in a location that makes sense for you. For example in C:/Java/lib</p>
<h1>Setting up the project and adding the references</h1>
<p>Next, open Eclipse and create a new project. Create a New &#8220;Dynamic Web Project&#8221; and called it &#8220;Todo&#8221;.</p>
<p>Now we will need to add the those references.  You need to copy the following list of JAR files to the lib folder of your application (workspace$\Todo\WebContent\WEB-INF\lib).</p>
<p>Here is the list of the jar files that you can find in your lib folder of the struts2 folder:</p>
<ul>
<li>antlr-2.7.6.jar</li>
<li>commons-collections-3.2.jar, commons-fileupload-1.2.1.jar, commons-io-1.3.2.jar, commons-lang-2.3.jar, commons-logging-1.0.4.jar</li>
<li>dom4j-1.6.1.jar</li>
<li>ejb3-persistence.jar</li>
<li>freemarker-2.3.13.jar</li>
<li>hibernate3.jar, hibernate-annotations.jar, hibernate-commons-annotations.jar, hibernate-validator.jar</li>
<li>hsqldb.jar</li>
<li>javassist-3.9.0.GA.jar</li>
<li>jta-1.1.jar</li>
<li>log4j-1.2.9.jar</li>
<li>mysql-connector-java-5.1.10-bin.jar</li>
<li>ognl-2.6.11.jar</li>
<li>slf4j-api-1.5.8.jar</li>
<li>slf4j-api.jar</li>
<li>struts2-convention-plugin-2.1.6.jar</li>
<li>struts2-core-2.1.6.jar</li>
<li>xwork-2.1.2.jar</li>
</ul>
<p>Conclusion: At this point, you are ready to code your application.</p>
<p>Thoughts: Honestly, it is quite painful to go around the web to download all those jar files. RubyOnRails is a full stacked framework, meaning it has all of this and more already settup in your project.</p>
<p>Next, we will set up a simple website with a a view, a javabean and a data access object to persist our tasks.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Struts2 TO-DO List project outline]]></title>
<link>http://ruemarin.wordpress.com/2009/10/07/struts2-to-do-list-project-outline/</link>
<pubDate>Wed, 07 Oct 2009 00:03:54 +0000</pubDate>
<dc:creator>ruemarin</dc:creator>
<guid>http://ruemarin.wordpress.com/2009/10/07/struts2-to-do-list-project-outline/</guid>
<description><![CDATA[This is my attempt to create a small project using Struts2. I want to create a simple TO-DO list usi]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This is my attempt to create a small project using Struts2.</p>
<p>I want to create a simple TO-DO list using the following frameworks and technologies:</p>
<ul>
<li>Struts2</li>
<li>MySQL</li>
<li>Hibernate</li>
<li>REST</li>
<li>AJAX/jQuery/JSON</li>
<li>Tiles</li>
<li>Velocity</li>
<li>Internationalization</li>
<li>Testing</li>
<li>Maven</li>
</ul>
<p>I will do this progressively and enhancing the application 1 step at a time. This project will be divided in the following posts:</p>
<ol>
<li>Getting started with Hibernate</li>
<li>Setting up the REST plugin</li>
<li>Adding AJAX behavior</li>
<li>Adding internationalization</li>
<li>Adding Velocity templates</li>
<li>Testing</li>
<li>Using Tiles</li>
<li>Using Maven</li>
</ol>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Notes to myself]]></title>
<link>http://ruemarin.wordpress.com/2009/10/05/notes-to-myself/</link>
<pubDate>Mon, 05 Oct 2009 22:47:14 +0000</pubDate>
<dc:creator>ruemarin</dc:creator>
<guid>http://ruemarin.wordpress.com/2009/10/05/notes-to-myself/</guid>
<description><![CDATA[======================================================================= Goals: - Create an applicati]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">=======================================================================</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Goals:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>- Create an application to manage users and their cars</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>- Create a search features for users</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>- Use tiles</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>- use Hibernate</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>- use Json</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>- use jQuery</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>- use REST</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>- use internationalization</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Part 1: plain app: CRUD and search</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Part 2: using REST</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">part 3: using AJAX</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">part 4: using the internationalization</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">=======================================================================</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">web.xml:Used to configure the struts2 dispatcher</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">struts.xml: used to map action to classes and specify result pages for success or errors+</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Note: the class Controller class is not extending any particular class</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">We don&#8217;t have to use the struts.xml config file if we use the convention plugin.</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">We can use annotations instead</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">First way:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">===========</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">If we use the convention plugin:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">- the controller class must extend com.opensymphony.xwork2.ActionSupport</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">- The Convention plug-in uses the action class name to map the action URL. Example: the action name coulld be welcome-user and the class name will be</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">WelcomeUser. The plug-in converts the camel case class name to dashes to get the request URL.</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">- the Convention plug-in will look for result pages or templates in the WEB-INF/content directory. By convention, if the action returns success, the plugin</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">will look for a file named: welcome-user-success.jsp or welcome-user.jsp. If the result type is input, then: welcome-user-input.jsp or welcome-user-input.vm</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">or welcome-user-input.ftl</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Second way:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">=============</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">The controller shall import:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">import org.apache.struts2.convention.annotation.Action;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">import org.apache.struts2.convention.annotation.Result;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">The Controller name shall end with Action. Example: WelcomeUserAction</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">The url mapping to this Controller is welcome-user by convention</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">By using the following:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">@Action(value=&#8221;/welcome&#8221;,results={@Result(name=&#8221;success&#8221;,location=&#8221;/results/successPage.jsp&#8221;)}):</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">- we will call the WelcomeUserAction by calling the url /welcome and look for a success result view in the results folder and use the successpage.jsp file as</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">the result page.</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">TAGS</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">=====</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">UI tags</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">In the result, you display the property of the Action by using:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;s:property value=&#8221;gender&#8221; /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">OR</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;s:set name=&#8221;artistName&#8221; value=&#8221;artist.name&#8221; /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;b&#62;Artist Name :&#60;/b&#62; &#60;s:property value=&#8221;#artistName&#8221; /&#62; &#60;br /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">OR</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;s:set name=&#8221;artistName&#8221; value=&#8221;artist.name&#8221; scope=&#8221;session&#8221; /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;b&#62;Artist Name :&#60;/b&#62; &#60;s:property value=&#8221;#session['artistName']&#8221; /&#62; &#60;br /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">DispatchAction functionality in Struts 2</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">==========================================</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">You can have several actions in an Action class besides the execute()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">You then need to configure the strus.xml file to specify which method in the action class will be called. A separate action mapping needs to be created for</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">each method in the action class.</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Example:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">import com.opensymphony.xwork2.ActionSupport;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">public class UserAction extends ActionSupport{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>private String message;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>public String execute()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>message = &#8220;Inside execute method&#8221;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return SUCCESS;<span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>public String add()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>message = &#8220;Inside add method&#8221;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return SUCCESS;<span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>public String update()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>message = &#8220;Inside update method&#8221;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return SUCCESS;<span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>public String delete()</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>{</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>message = &#8220;Inside delete method&#8221;;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>return SUCCESS;<span style="white-space:pre;"> </span></div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;!DOCTYPE struts PUBLIC</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#8220;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#8221;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#8220;http://struts.apache.org/dtds/struts-2.0.dtd&#8221;&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;struts&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;package name=&#8221;default&#8221; extends=&#8221;struts-default&#8221;&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;action name=&#8221;User&#8221;&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;result name=&#8221;success&#8221;&#62;/success.jsp&#60;/result&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;/action&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;action name=&#8221;addUser&#8221; method=&#8221;add&#8221;&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;result name=&#8221;success&#8221;&#62;/success.jsp&#60;/result&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;/action&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;action name=&#8221;updateUser&#8221; method=&#8221;update&#8221;&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;result name=&#8221;success&#8221;&#62;/success.jsp&#60;/result&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;/action&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;action name=&#8221;deleteUser&#8221; method=&#8221;delete&#8221;&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;result name=&#8221;success&#8221;&#62;/success.jsp&#60;/result&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;/action&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;/package&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;/struts&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Here each action is mapped to a method of the action class</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">And here is how those methods are called:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;s:form action=&#8221;User&#8221; &#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;s:submit /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;s:submit action=&#8221;addUser&#8221; value=&#8221;Add&#8221; /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;s:submit action=&#8221;updateUser&#8221; value=&#8221;Update&#8221; /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;s:submit action=&#8221;deleteUser&#8221; value=&#8221;Delete&#8221; /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;/s:form&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">However this configuration can be very exhaustive and repetitive for a real application.</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">You can use what&#8217;s called the Dynamic Method Invocation</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;!DOCTYPE struts PUBLIC</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#8220;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#8221;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#8220;http://struts.apache.org/dtds/struts-2.0.dtd&#8221;&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>&#60;struts&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> &#60;package name=&#8221;default&#8221; extends=&#8221;struts-default&#8221;&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>&#60;action name=&#8221;*User&#8221; method=&#8221;{1}&#8221;&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>&#60;result name=&#8221;success&#8221;&#62;/success.jsp&#60;/result&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>&#60;/action&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span> &#60;/package&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>&#60;/struts&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">We replaced all action names with an &#8216;*&#8217;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">The word that matches for the first asterisk will be substituted for the method attribute. So when the request URL is &#8220;addUser&#8221; the add() method in the</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">UserAction class will be invoked.</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Domain Object as JavaBeans Property</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">======================================</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">In Struts2, the params interceptor is in charge of transferring the data gathered by a form in the  UI to the domain object.</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">All you need to do is to create a domain object as a javabeans with the correspongding setters and getters.The framework will automatically initializes the</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">domain object and transfers the form data. The UserAction class contains the following code.</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Your controller:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">public class UserAction extends ActionSupport</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">has a property called User which is your javabean with getters and setters</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">The form view should be something like this:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;s:form action=&#8221;UserAction&#8221; &#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>&#60;s:textfield name=&#8221;user.name&#8221; label=&#8221;User Name&#8221; /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>&#60;s:submit /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;/s:form&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">The result should be : User Name :&#60;s:property value=&#8221;user.name&#8221; /&#62;&#60;br&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">ModelDriven interface</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">==============================</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Basically, we want to achieve the same as above meaning, we want to transfer the form data to a java object without setting the object&#8217;s properties.</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">To create a ModelDriven Action our Action class should:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">- implement the ModelDriven interface. Ex: public class UserAction extends ActionSupport implements ModelDriven {}</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">- implement the getModel() method in such a way that it returns the application domain object</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">- initialize the model object ourselves. Ex: private User user = new User();</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">The form will look like:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;s:form action=&#8221;UserAction&#8221; &#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;"><span style="white-space:pre;"> </span>&#60;s:textfield name=&#8221;name&#8221; label=&#8221;User Name&#8221; /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">&#60;/s:form&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Displaying the object property will look like:</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">User Name :&#60;s:property value=&#8221;name&#8221; /&#62;</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">Hibernate integration</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">=========================================</div>
<div id="_mcePaste" style="position:absolute;left:-10000px;top:0;width:1px;height:1px;">In a DAO folder: we have an interface UserDAO and the concreate class that implements it: UserDAOImpl</div>
<p>=======================================================================</p>
<p>Goals:</p>
<p><span style="white-space:pre;"> </span>- Create an application to manage users and their cars</p>
<p><span style="white-space:pre;"> </span>- Create a search features for users</p>
<p><span style="white-space:pre;"> </span>- Use tiles</p>
<p><span style="white-space:pre;"> </span>- use Hibernate</p>
<p><span style="white-space:pre;"> </span>- use Json</p>
<p><span style="white-space:pre;"> </span>- use jQuery</p>
<p><span style="white-space:pre;"> </span>- use REST</p>
<p><span style="white-space:pre;"> </span>- use internationalization</p>
<p>Part 1: plain app: CRUD and search</p>
<p>Part 2: using REST</p>
<p>part 3: using AJAX</p>
<p>part 4: using the internationalization</p>
<p>=======================================================================</p>
<p>web.xml:Used to configure the struts2 dispatcher</p>
<p>struts.xml: used to map action to classes and specify result pages for success or errors+</p>
<p>Note: the class Controller class is not extending any particular class</p>
<p>We don&#8217;t have to use the struts.xml config file if we use the convention plugin.</p>
<p>We can use annotations instead</p>
<p>First way:</p>
<p>===========</p>
<p>If we use the convention plugin:</p>
<p>- the controller class must extend com.opensymphony.xwork2.ActionSupport</p>
<p>- The Convention plug-in uses the action class name to map the action URL. Example: the action name coulld be welcome-user and the class name will be</p>
<p>WelcomeUser. The plug-in converts the camel case class name to dashes to get the request URL.</p>
<p>- the Convention plug-in will look for result pages or templates in the WEB-INF/content directory. By convention, if the action returns success, the plugin</p>
<p>will look for a file named: welcome-user-success.jsp or welcome-user.jsp. If the result type is input, then: welcome-user-input.jsp or welcome-user-input.vm</p>
<p>or welcome-user-input.ftl</p>
<p>Second way:</p>
<p>=============</p>
<p>The controller shall import:</p>
<p>import org.apache.struts2.convention.annotation.Action;</p>
<p>import org.apache.struts2.convention.annotation.Result;</p>
<p>The Controller name shall end with Action. Example: WelcomeUserAction</p>
<p>The url mapping to this Controller is welcome-user by convention</p>
<p>By using the following:</p>
<p>@Action(value=&#8221;/welcome&#8221;,results={@Result(name=&#8221;success&#8221;,location=&#8221;/results/successPage.jsp&#8221;)}):</p>
<p>- we will call the WelcomeUserAction by calling the url /welcome and look for a success result view in the results folder and use the successpage.jsp file as</p>
<p>the result page.</p>
<p>TAGS</p>
<p>=====</p>
<p>UI tags</p>
<p>In the result, you display the property of the Action by using:</p>
<p>&#60;s:property value=&#8221;gender&#8221; /&#62;</p>
<p>OR</p>
<p>&#60;s:set name=&#8221;artistName&#8221; value=&#8221;artist.name&#8221; /&#62;</p>
<p>&#60;b&#62;Artist Name :&#60;/b&#62; &#60;s:property value=&#8221;#artistName&#8221; /&#62; &#60;br /&#62;</p>
<p>OR</p>
<p>&#60;s:set name=&#8221;artistName&#8221; value=&#8221;artist.name&#8221; scope=&#8221;session&#8221; /&#62;</p>
<p>&#60;b&#62;Artist Name :&#60;/b&#62; &#60;s:property value=&#8221;#session['artistName']&#8221; /&#62; &#60;br /&#62;</p>
<p>DispatchAction functionality in Struts 2</p>
<p>==========================================</p>
<p>You can have several actions in an Action class besides the execute()</p>
<p>You then need to configure the strus.xml file to specify which method in the action class will be called. A separate action mapping needs to be created for</p>
<p>each method in the action class.</p>
<p>Example:</p>
<p>import com.opensymphony.xwork2.ActionSupport;</p>
<p>public class UserAction extends ActionSupport{</p>
<p><span style="white-space:pre;"> </span>private String message;</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>public String execute()</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>message = &#8220;Inside execute method&#8221;;</p>
<p><span style="white-space:pre;"> </span>return SUCCESS;<span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>public String add()</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>message = &#8220;Inside add method&#8221;;</p>
<p><span style="white-space:pre;"> </span>return SUCCESS;<span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>public String update()</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>message = &#8220;Inside update method&#8221;;</p>
<p><span style="white-space:pre;"> </span>return SUCCESS;<span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>}</p>
<p><span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>public String delete()</p>
<p><span style="white-space:pre;"> </span>{</p>
<p><span style="white-space:pre;"> </span>message = &#8220;Inside delete method&#8221;;</p>
<p><span style="white-space:pre;"> </span>return SUCCESS;<span style="white-space:pre;"> </span></p>
<p><span style="white-space:pre;"> </span>}</p>
<p>}</p>
<p>&#60;!DOCTYPE struts PUBLIC</p>
<p>&#8220;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#8221;</p>
<p>&#8220;http://struts.apache.org/dtds/struts-2.0.dtd&#8221;&#62;</p>
<p>&#60;struts&#62;</p>
<p>&#60;package name=&#8221;default&#8221; extends=&#8221;struts-default&#8221;&#62;</p>
<p>&#60;action name=&#8221;User&#8221; class=&#8221;vaannila.UserAction&#8221;&#62;</p>
<p>&#60;result name=&#8221;success&#8221;&#62;/success.jsp&#60;/result&#62;</p>
<p>&#60;/action&#62;</p>
<p>&#60;action name=&#8221;addUser&#8221; method=&#8221;add&#8221; class=&#8221;vaannila.UserAction&#8221;&#62;</p>
<p>&#60;result name=&#8221;success&#8221;&#62;/success.jsp&#60;/result&#62;</p>
<p>&#60;/action&#62;</p>
<p>&#60;action name=&#8221;updateUser&#8221; method=&#8221;update&#8221; class=&#8221;vaannila.UserAction&#8221;&#62;</p>
<p>&#60;result name=&#8221;success&#8221;&#62;/success.jsp&#60;/result&#62;</p>
<p>&#60;/action&#62;</p>
<p>&#60;action name=&#8221;deleteUser&#8221; method=&#8221;delete&#8221; class=&#8221;vaannila.UserAction&#8221;&#62;</p>
<p>&#60;result name=&#8221;success&#8221;&#62;/success.jsp&#60;/result&#62;</p>
<p>&#60;/action&#62;</p>
<p>&#60;/package&#62;</p>
<p>&#60;/struts&#62;</p>
<p>Here each action is mapped to a method of the action class</p>
<p>And here is how those methods are called:</p>
<p>&#60;s:form action=&#8221;User&#8221; &#62;</p>
<p>&#60;s:submit /&#62;</p>
<p>&#60;s:submit action=&#8221;addUser&#8221; value=&#8221;Add&#8221; /&#62;</p>
<p>&#60;s:submit action=&#8221;updateUser&#8221; value=&#8221;Update&#8221; /&#62;</p>
<p>&#60;s:submit action=&#8221;deleteUser&#8221; value=&#8221;Delete&#8221; /&#62;</p>
<p>&#60;/s:form&#62;</p>
<p>However this configuration can be very exhaustive and repetitive for a real application.</p>
<p>You can use what&#8217;s called the Dynamic Method Invocation</p>
<p>&#60;!DOCTYPE struts PUBLIC</p>
<p>&#8220;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#8221;</p>
<p>&#8220;http://struts.apache.org/dtds/struts-2.0.dtd&#8221;&#62;</p>
<p><span style="white-space:pre;"> </span>&#60;struts&#62;</p>
<p><span style="white-space:pre;"> </span> &#60;package name=&#8221;default&#8221; extends=&#8221;struts-default&#8221;&#62;</p>
<p><span style="white-space:pre;"> </span>&#60;action name=&#8221;*User&#8221; method=&#8221;{1}&#8221; class=&#8221;vaannila.UserAction&#8221;&#62;</p>
<p><span style="white-space:pre;"> </span>&#60;result name=&#8221;success&#8221;&#62;/success.jsp&#60;/result&#62;</p>
<p><span style="white-space:pre;"> </span>&#60;/action&#62;</p>
<p><span style="white-space:pre;"> </span> &#60;/package&#62;</p>
<p><span style="white-space:pre;"> </span>&#60;/struts&#62;</p>
<p>We replaced all action names with an &#8216;*&#8217;</p>
<p>The word that matches for the first asterisk will be substituted for the method attribute. So when the request URL is &#8220;addUser&#8221; the add() method in the</p>
<p>UserAction class will be invoked.</p>
<p>Domain Object as JavaBeans Property</p>
<p>======================================</p>
<p>In Struts2, the params interceptor is in charge of transferring the data gathered by a form in the  UI to the domain object.</p>
<p>All you need to do is to create a domain object as a javabeans with the correspongding setters and getters.The framework will automatically initializes the</p>
<p>domain object and transfers the form data. The UserAction class contains the following code.</p>
<p>Your controller:</p>
<p>public class UserAction extends ActionSupport</p>
<p>has a property called User which is your javabean with getters and setters</p>
<p>The form view should be something like this:</p>
<p>&#60;s:form action=&#8221;UserAction&#8221; &#62;</p>
<p><span style="white-space:pre;"> </span>&#60;s:textfield name=&#8221;user.name&#8221; label=&#8221;User Name&#8221; /&#62;</p>
<p><span style="white-space:pre;"> </span>&#60;s:submit /&#62;</p>
<p>&#60;/s:form&#62;</p>
<p>The result should be : User Name :&#60;s:property value=&#8221;user.name&#8221; /&#62;&#60;br&#62;</p>
<p>ModelDriven interface</p>
<p>==============================</p>
<p>Basically, we want to achieve the same as above meaning, we want to transfer the form data to a java object without setting the object&#8217;s properties.</p>
<p>To create a ModelDriven Action our Action class should:</p>
<p>- implement the ModelDriven interface. Ex: public class UserAction extends ActionSupport implements ModelDriven {}</p>
<p>- implement the getModel() method in such a way that it returns the application domain object</p>
<p>- initialize the model object ourselves. Ex: private User user = new User();</p>
<p>The form will look like:</p>
<p>&#60;s:form action=&#8221;UserAction&#8221; &#62;</p>
<p><span style="white-space:pre;"> </span>&#60;s:textfield name=&#8221;name&#8221; label=&#8221;User Name&#8221; /&#62;</p>
<p>&#60;/s:form&#62;</p>
<p>Displaying the object property will look like:</p>
<p>User Name :&#60;s:property value=&#8221;name&#8221; /&#62;</p>
<p>Hibernate integration</p>
<p>=========================================</p>
<p>In a DAO folder: we have an interface UserDAO and the concreate class that implements it: UserDAOImpl</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[File Upload on Google App Engine using struts2]]></title>
<link>http://whyjava.wordpress.com/2009/10/04/file-upload-on-google-app-engine-using-struts2/</link>
<pubDate>Sun, 04 Oct 2009 13:14:02 +0000</pubDate>
<dc:creator>whyjava</dc:creator>
<guid>http://whyjava.wordpress.com/2009/10/04/file-upload-on-google-app-engine-using-struts2/</guid>
<description><![CDATA[Intent of my Blog Few months back, i wrote a blog on Creating Struts2 application on Google App Engi]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Intent of my Blog</strong></p>
<p>Few months back, i wrote a blog on <a href="http://whyjava.wordpress.com/2009/08/30/creating-struts2-application-on-google-app-engine-gae/">Creating Struts2 application on Google App Engine </a> and some developers asked me how to upload a file using struts2 on google app engine. At that point of time, i was playing with google app engine and was not very clear about the limitation google app engine imposes. Google App Engine does not allow your application to write a file to their application server. This was a very big limitation as most of the application require some sort of file upload. So, i decided to find some way by which i can achieve the upload functionality and i found <a href="http://code.google.com/appengine/kb/java.html#fileforms">this link</a>. But, i didn&#8217;t wanted to use servelt in my code because i was trying to build a application using struts 2.I wanted to work with actions and use <a href="http://struts.apache.org/2.0.14/struts2-core/apidocs/org/apache/struts2/interceptor/FileUploadInterceptor.html">FileUploadInterceptor</a>. With the current implementation of struts 2 FileUploadInterceptor, i can&#8217;t do fileupload because it writes file to server.So, after spending some time with struts2 code, i wrote my own extension for <a href="http://code.google.com/p/struts2-gae/">Struts 2</a>.This post will discuss how you can use small struts2 wrapper framework, i created for google app engine in your application to do fileupload and more.</p>
<p><strong>Prerequisites for starting Struts2 Application on Google App Engine</strong></p>
<p>Before you start building your sample application on google app engine using struts 2 you will need the following:-</p>
<ol>
<li>Google App Engine runs on java 5 and above so if necessary, <a href="http://java.sun.com/javase/downloads/index.jsp">download and install the Java SE Development Kit (JDK) for your platform</a> and <a href="http://developer.apple.com/java/">for mac users</a> download and install the latest version.</li>
<li>In this example we will be using Eclipse as our ide. So if necessary, <a href="http://www.eclipse.org/">download eclipse </a> and <a href="http://code.google.com/appengine/docs/java/tools/eclipse.html">google app engine plugin for eclipse</a>.You will also need to download the <a href="http://code.google.com/appengine/downloads.html">google  java app engine SDK</a>. For more information you can refer to <a href="http://code.google.com/appengine/docs/java/gettingstarted/installing.html">installing the java SDK for google app engine</a>.</li>
<li>Download the latest release of <a href="http://struts.apache.org/download.cgi">Struts2 framework</a>.If you want to learn struts 2 a very good reference is struts 2 in action book.Please buy <a href="http://www.amazon.com/gp/product/193398807X?ie=UTF8&#38;tag=javblo07-20&#38;linkCode=as2&#38;camp=1789&#38;creative=9325&#38;creativeASIN=193398807X">Struts 2 in Action</a><img style="border:medium none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=javblo07-20&#38;l=as2&#38;o=1&#38;a=193398807X" border="0" alt="" width="1" height="1" />.</li>
<li>Download the latest release of <a href="http://code.google.com/p/struts2-gae/">struts2-gae framework</a>.It is an wrapper around struts 2 for google app engine.</li>
</ol>
<p><strong>Step by Step procedure to create Struts2 File Upload application on Google App Engine.</strong></p>
<p><strong>Step 1</strong>: Create a new project by clicking the New Web Application Project button in the toolbar<img title="new_app_button" src="http://whyjava.files.wordpress.com/2009/08/new_app_button1.png?w=20&#038;h=20#38;h=20" alt="new_app_button" width="20" height="20" />.</p>
<p><img class="aligncenter size-large wp-image-17" title="1" src="http://whyjava.wordpress.com/files/2009/08/11.jpg?w=1024" alt="1" width="1024" height="624" /></p>
<p><strong>Step 2</strong> : Give the project name say struts2-fileupload  as we are going to create a simple file upload application. Enter package name as com.login and uncheck “Use Google Web Toolkit,” and ensure “Use Google App Engine” is checked and click the finish button.</p>
<p><img class="aligncenter size-large wp-image-108" title="s1" src="http://whyjava.wordpress.com/files/2009/10/s1.jpg?w=1024" alt="s1" width="1024" height="640" /></p>
<p><strong>Step3</strong> : When you click the finish button you will get a sample HelloWorld application, which you can run going in the Run menu, select Run As &#62; Web Application.By default application will run at port 8080, you can view the sample application at <a href="http://localhost:8080/">http://locahost:8080</a>. For more information on the sample google web application created by the plugin you can refer to <a href="http://code.google.com/appengine/docs/java/gettingstarted/creating.html">Google java app engine documentation</a> .Please keep in mind that intent of this document is not to provide developers the <a href="http://code.google.com/appengine/docs/java/overview.html">overview of Google App engine for Java</a>.</p>
<p><strong>Step4</strong> : By now you are ready with the google app engine infrastructure and we can move to the next step of creating a file upload application in Struts 2.</p>
<ul>
<li>for creating a struts 2 application you will need to first add the required dependencies to the struts2-fileupload project. The required struts 2 jars are below mentioned and you can find these jars in struts2 package you downloaded inside the lib folder :-
<ul>
<li>commons-fileupload-1.2.1.jar</li>
<li>commons-io-1.3.2.jar</li>
<li>commons-logging-1.1.jar</li>
<li>freemarker-2.3.13.jar</li>
<li>ognl-2.6.11.jar</li>
<li>struts2-core-2.1.6.jar</li>
<li>struts2-gae-0.1.jar</li>
<li>xwork-2.1.2.jar</li>
</ul>
</li>
<li>Add these dependencies in your eclipse java build path.</li>
</ul>
<p><img title="s2" src="http://whyjava.wordpress.com/files/2009/10/s2.jpg?w=1024" alt="s2" width="1024" height="518" /></p>
<ul>
<li>Add these dependencies in the war/WEB-INF/lib folder so that these jars gets deployed along with your application.</li>
<li>First step in creating a struts 2 application is configuring the web.xml (deployment descriptor) which is located in WEB-INF folder.You can remove the servlet declaration from web.xml as we will not be needing this.In the <a href="http://whyjava.wordpress.com/2009/08/30/creating-struts2-application-on-google-app-engine-gae/">last post</a>,we configured FilterDispatcher(this is theFilterDispatcher which comes with struts2) but in this application we need to add the GaeFilterDispatcher(this is provided by struts 2 extension framework for GAE). We will declare GaeFilterDispatcher in web.xml, because in struts2 every request goes  pass through a FilterDispatcher, which will invoke the appropriate action corresponding to the URL mapping.So our web.xml will look like :-</li>
</ul>
<pre class="brush: xml;">
&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62;
&#60;web-app xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34;
xmlns=&#34;http://java.sun.com/xml/ns/javaee&#34;
xmlns:web=&#34;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#34;
xsi:schemaLocation=&#34;http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#34; version=&#34;2.5&#34;&#62;
 &#60;filter&#62;
 &#60;filter-name&#62;struts2-gae&#60;/filter-name&#62;
 &#60;filter-class&#62;com.struts2.gae.dispatcher.GaeFilterDispatcher&#60;/filter-class&#62;
 &#60;/filter&#62;
 &#60;filter-mapping&#62;
 &#60;filter-name&#62;struts2-gae&#60;/filter-name&#62;
 &#60;url-pattern&#62;/*&#60;/url-pattern&#62;
 &#60;/filter-mapping&#62;
 &#60;welcome-file-list&#62;
 &#60;welcome-file&#62;index.html&#60;/welcome-file&#62;
 &#60;/welcome-file-list&#62;
&#60;/web-app&#62;
</pre>
<ul>
<li>To start we will be creating a jsp fileupload page using struts 2 tag library and we will call file upload page from index.html.To call the fileupload page there are two ways first, we can directly call the upload.jsp page from link second, we can calling it through struts. We will be taking the second step as this will show you how to configure actions when you dont need to invoke any action.Lets first see how our login page and index.html will look like :-</li>
</ul>
<p><strong>index.html</strong></p>
<pre class="brush: xml;">
&#60;!DOCTYPE HTML PUBLIC &#34;-//W3C//DTD HTML 4.01 Transitional//EN&#34;&#62;
&#60;html&#62;
&#60;head&#62;
&#60;meta http-equiv=&#34;content-type&#34; content=&#34;text/html; charset=UTF-8&#34;&#62;
&#60;title&#62;Struts2 File upload on Google App Engine&#60;/title&#62;
&#60;/head&#62;

&#60;body&#62;
&#60;h1&#62;Struts2 File upload on Google App Engine!&#60;/h1&#62;
&#60;table&#62;
&#60;tr&#62;
&#60;td colspan=&#34;2&#34; style=&#34;font-weight: bold;&#34;&#62;Available Application:&#60;/td&#62;
&#60;/tr&#62;
&#60;tr&#62;
&#60;td&#62;&#60;a href=&#34;/add&#34; /&#62;Upload my Photo&#60;/td&#62;
&#60;/tr&#62;
&#60;/table&#62;
&#60;/body&#62;
&#60;/html&#62;
</pre>
<p><strong>upload.jsp</strong></p>
<pre class="brush: xml;">
&#60;%@ page language=&#34;java&#34; contentType=&#34;text/html; charset=ISO-8859-1&#34;&#60;/pre&#62;
 pageEncoding=&#34;ISO-8859-1&#34;%&#62;
&#60;%@ taglib prefix=&#34;s&#34; uri=&#34;/struts-tags&#34;%&#62;
&#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD HTML 4.01 Transitional//EN&#34; &#34;http://www.w3.org/TR/html4/loose.dtd&#34;&#62;
&#60;html&#62;
&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=ISO-8859-1&#34;&#62;
&#60;title&#62;Upload my Photo&#60;/title&#62;
&#60;/head&#62;
&#60;body&#62;
 &#60;s:form action=&#34;upload&#34; method=&#34;post&#34; enctype=&#34;multipart/form-data&#34;&#62;
 &#60;s:file name=&#34;photo&#34; label=&#34;Upload new Photo&#34;&#62;&#60;/s:file&#62;
 &#60;s:submit value=&#34;Upload&#34;&#62;&#60;/s:submit&#62;
 &#60;/s:form&#62;

&#60;/body&#62;
&#60;/html&#62;
</pre>
<p>After creating the upload.jsp we need to configure this as action in the struts.xml file which you be should put inside source folder parallel to log4j.properties file.We can configure action as mentioned below:-</p>
<pre class="brush: xml;">
&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34; ?&#62;
&#60;!DOCTYPE struts PUBLIC
&#34;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#34;
&#34;http://struts.apache.org/dtds/struts-2.0.dtd&#34;&#62;
&#60;struts&#62;
	&#60;include file=&#34;struts-default.xml&#34;&#62;&#60;/include&#62;
&#60;package name=&#34;&#34; namespace=&#34;/&#34; extends=&#34;struts-default&#34;&#62;
		&#60;action name=&#34;add&#34;&#62;
			&#60;result&#62;/upload.jsp&#60;/result&#62;
		&#60;/action&#62;
	&#60;/package&#62;
&#60;/struts&#62;
</pre>
<ul>
<li>Now try running this application by right click on project run as &#62; web application and click <a href="http://localhost:8080">http://localhost:8080</a>. You will see index.html and when you click on upload my photo you will get this exception :-</li>
</ul>
<p><span style="color:#993300;">SEVERE: Unable to set parameter [location] in result of type    [org.apache.struts2.dispatcher.ServletDispatcherResult]</span></p>
<p><span style="color:#993300;">Caught OgnlException while setting property &#8216;location&#8217; on type &#8216;org.apache.struts2.dispatcher.ServletDispatcherResult&#8217;. &#8211; Class: ognl.OgnlRuntime</span></p>
<p><span style="color:#993300;">File: OgnlRuntime.java</span></p>
<p><span style="color:#993300;">Method: invokeMethod</span></p>
<p><span style="color:#993300;">Line: 508 &#8211; ognl/OgnlRuntime.java:508:-1</span></p>
<p><span style="color:#993300;"> at com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:392)</span></p>
<p><span style="color:#993300;">Caused by: java.lang.IllegalAccessException: Method [public void org.apache.struts2.dispatcher.StrutsResultSupport.setLocation(java.lang.String)] cannot be accessed.</span></p>
<p><span style="color:#993300;"> at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:508)</span></p>
<p><span style="color:#993300;"> at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:812)</span></p>
<p><span style="color:#993300;"> at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:964)</span></p>
<p><span style="color:#993300;"> at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:75)</span></p>
<p><span style="color:#993300;"> at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:131)</span></p>
<p><span style="color:#993300;"> at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:28)</span></p>
<p><span style="color:#993300;"> at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1656)</span></p>
<p><span style="color:#993300;"> at ognl.ASTProperty.setValueBody(ASTProperty.java:101)</span></p>
<p><span style="color:#993300;"> at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)</span></p>
<p><span style="color:#993300;"> at ognl.SimpleNode.setValue(SimpleNode.java:246)</span></p>
<p><span style="color:#993300;"> at ognl.Ognl.setValue(Ognl.java:476)</span></p>
<p><span style="color:#993300;"> at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:192)</span></p>
<p><span style="color:#993300;"> at com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:385)</span></p>
<p><span style="color:#993300;"> &#8230; 73 more</span></p>
<ul>
<li>In order to resolve this problem we  need to make entry in web.xml file also for OgnlListener.This OgnlListener is also provided by struts2-gae framework.(A struts2 extension framework for GAE).</li>
</ul>
<pre class="brush: xml;">[/sourcecode]

&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62;
&#60;web-app xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34;
xmlns=&#34;http://java.sun.com/xml/ns/javaee&#34;
xmlns:web=&#34;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#34;
xsi:schemaLocation=&#34;http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#34; version=&#34;2.5&#34;&#62;
&#60;filter&#62;
&#60;filter-name&#62;struts2-gae&#60;/filter-name&#62;
&#60;filter-class&#62;com.struts2.gae.dispatcher.GaeFilterDispatcher&#60;/filter-class&#62;
&#60;/filter&#62;
&#60;filter-mapping&#62;
&#60;filter-name&#62;struts2-gae&#60;/filter-name&#62;
&#60;url-pattern&#62;/*&#60;/url-pattern&#62;
&#60;/filter-mapping&#62;
&#60;listener&#62;
&#60;listener-class&#62;com.struts2.gae.listener.OgnlListener&#60;/listener-class&#62;
&#60;/listener&#62;
&#60;welcome-file-list&#62;
&#60;welcome-file&#62;index.html&#60;/welcome-file&#62;
&#60;/welcome-file-list&#62;
&#60;/web-app&#62;

[sourcecode]</pre>
<ul>
<li>You need to add this step if you are using Google App Engine 1.2.6 because when you run struts2 application on google app engine 1.2.6 you will get the following error:-</li>
</ul>
<p><span style="color:#800000;">javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax.swing.tree.TreeNode is a restricted class. Please see the Google App Engine developer’s guide for more details.<br />
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)<br />
at org.apache.jasper.runtime.PageContextImpl.access$1100(PageContextImpl.java:64)<br />
at org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:745)<br />
at java.security.AccessController.doPrivileged(Native Method)<br />
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:743)<br />
at org.apache.jsp.login_jsp._jspService(login_jsp.java:86)<br />
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)<br />
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)<br />
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)<br />
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)<br />
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)<br />
at com.google.appengine.tools.development.PrivilegedJspServlet.access$101(PrivilegedJspServlet.java:23)<br />
at com.google.appengine.tools.development.PrivilegedJspServlet$2.run(PrivilegedJspServlet.java:59)<br />
at java.security.AccessController.doPrivileged(Native Method)<br />
at com.google.appengine.tools.development.PrivilegedJspServlet.service(PrivilegedJspServlet.java)</span></p>
<p><span style="color:#800000;"><span style="color:#000000;">To avoid this error you need to create a new package </span></span>&#8220;freemarker.core&#8221;<span style="color:#800000;"><span style="color:#000000;"> in your source folder and add the following class </span></span></p>
<p><span style="color:#800000;"><span style="color:#000000;">
<pre class="brush: java;">&#60;/span&#62;&#60;/span&#62;

/*
 * Copyright (c) 2003 The Visigoth Software Society. All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above
copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowledgement:
 *       &#34;This product includes software developed by the
 *        Visigoth Software Society (http://www.visigoths.org/).&#34;
 *    Alternately, this acknowledgement may appear in the software
itself,
 *    if and wherever such third-party acknowledgements normally
appear.
 *
 * 4. Neither the name &#34;FreeMarker&#34;, &#34;Visigoth&#34;, nor any of the names
of the
 *    project contributors may be used to endorse or promote products
derived
 *    from this software without prior written permission. For written
 *    permission, please contact visigo...@visigoths.org.
 *
 * 5. Products derived from this software may not be called
&#34;FreeMarker&#34; or &#34;Visigoth&#34;
 *    nor may &#34;FreeMarker&#34; or &#34;Visigoth&#34; appear in their names
 *    without prior written permission of the Visigoth Software
Society.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE VISIGOTH SOFTWARE SOCIETY OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Visigoth Software Society. For more
 * information on the Visigoth Software Society, please see
 * http://www.visigoths.org/
 */

package freemarker.core;

import java.io.IOException;

/**
 * A TemplateElement representing a block of plain text.
 *
 * @version $Id: TextBlock.java,v 1.17 2004/01/06 17:06:42 szegedia Exp $
 */
public final class TextBlock extends TemplateElement {
 private static final char[] EMPTY_CHAR_ARRAY = new char[0];
 static final TextBlock EMPTY_BLOCK = new TextBlock(EMPTY_CHAR_ARRAY, false);
 // We're using char[] instead of String for storing the text block because
 // Writer.write(String) involves copying the String contents to a char[]
 // using String.getChars(), and then calling Writer.write(char[]).By
 // using Writer.write(char[]) directly, we avoid array copying on each
 // write.
 private char[] text;
 private final boolean unparsed;

 public TextBlock(String text) {
 this(text, false);
 }

 public TextBlock(String text, boolean unparsed) {
 this(text.toCharArray(), unparsed);
 }

 private TextBlock(char[] text, boolean unparsed) {
 this.text = text;
 this.unparsed = unparsed;
 }

 /**
 * Simply outputs the text.
 */
 public void accept(Environment env) throws IOException {
 env.getOut().write(text);
 }

 public String getCanonicalForm() {
 String text = new String(this.text);
 if (unparsed) {
 return &#34;&#60;#noparse&#62;&#34; + text + &#34;&#60;/#noparse&#62;&#34;;
 }
 return text;
 }

 public String getDescription() {
 String s = new String(text).trim();
 if (s.length() == 0) {
 return &#34;whitespace&#34;;
 }
 if (s.length() &#62; 20) {
 s = s.substring(0, 20) + &#34;...&#34;;
 s = s.replace('\n', ' ');
 s = s.replace('\r', ' ');
 }
 return &#34;text block (&#34; + s + &#34;)&#34;;
 }

 TemplateElement postParseCleanup(boolean stripWhitespace) {
 if (text.length == 0)
 return this;
 int openingCharsToStrip = 0, trailingCharsToStrip = 0;
 boolean deliberateLeftTrim = deliberateLeftTrim();
 boolean deliberateRightTrim = deliberateRightTrim();
 if (!stripWhitespace &#124;&#124; text.length == 0) {
 return this;
 }
 if (parent.parent == null &#38;&#38; previousSibling() == null)
 return this;
 if (!deliberateLeftTrim) {
 trailingCharsToStrip = trailingCharsToStrip();
 }
 if (!deliberateRightTrim) {
 openingCharsToStrip = openingCharsToStrip();
 }
 if (openingCharsToStrip == 0 &#38;&#38; trailingCharsToStrip == 0) {
 return this;
 }
 this.text = substring(text, openingCharsToStrip, text.length
 - trailingCharsToStrip);
 if (openingCharsToStrip &#62; 0) {
 this.beginLine++;
 this.beginColumn = 1;
 }
 if (trailingCharsToStrip &#62; 0) {
 this.endColumn = 0;
 }
 return this;
 }

 /**
 * Scans forward the nodes on the same line to see whether there is a
 * deliberate left trim in effect. Returns true if the left trim was
 * present.
 */
 private boolean deliberateLeftTrim() {
 boolean result = false;
 for (TemplateElement elem = this.nextTerminalNode(); elem != null
 &#38;&#38; elem.beginLine == this.endLine; elem = elem
 .nextTerminalNode()) {
 if (elem instanceof TrimInstruction) {
 TrimInstruction ti = (TrimInstruction) elem;
 if (!ti.left &#38;&#38; !ti.right) {
 result = true;
 }
 if (ti.left) {
 result = true;
 int lastNewLineIndex = lastNewLineIndex();
 if (lastNewLineIndex &#62;= 0 &#124;&#124; beginColumn == 1) {
 char[] firstPart = substring(text, 0,
 lastNewLineIndex + 1);
 char[] lastLine = substring(text, 1 + lastNewLineIndex);
 if (trim(lastLine).length == 0) {
 this.text = firstPart;
 this.endColumn = 0;
 } else {
 int i = 0;
 while (Character.isWhitespace(lastLine[i])) {
 i++;
 }
 char[] printablePart = substring(lastLine, i);
 this.text = concat(firstPart, printablePart);
 }
 }
 }
 }
 }
 if (result) {
 }
 return result;
 }

 /**
 * Checks for the presence of a t or rt directive on the same line. Returns
 * true if the right trim directive was present.
 */
 private boolean deliberateRightTrim() {
 boolean result = false;
 for (TemplateElement elem = this.prevTerminalNode(); elem != null
 &#38;&#38; elem.endLine == this.beginLine; elem = elem
 .prevTerminalNode()) {
 if (elem instanceof TrimInstruction) {
 TrimInstruction ti = (TrimInstruction) elem;
 if (!ti.left &#38;&#38; !ti.right) {
 result = true;
 }
 if (ti.right) {
 result = true;
 int firstLineIndex = firstNewLineIndex() + 1;
 if (firstLineIndex == 0) {
 return false;
 }
 if (text.length &#62; firstLineIndex
 &#38;&#38; text[firstLineIndex - 1] == '\r'
 &#38;&#38; text[firstLineIndex] == '\n') {
 firstLineIndex++;
 }
 char[] trailingPart = substring(text, firstLineIndex);
 char[] openingPart = substring(text, 0, firstLineIndex);
 if (trim(openingPart).length == 0) {
 this.text = trailingPart;
 this.beginLine++;
 this.beginColumn = 1;
 } else {
 int lastNonWS = openingPart.length - 1;
 while (Character.isWhitespace(text[lastNonWS])) {
 lastNonWS--;
 }
 char[] printablePart = substring(text, 0, lastNonWS + 1);
 if (trim(trailingPart).length == 0) {
 // THIS BLOCK IS HEINOUS! THERE MUST BE A BETTER
 // WAY! REVISIT (JR)
 boolean trimTrailingPart = true;
 for (TemplateElement te = this.nextTerminalNode(); te != null
 &#38;&#38; te.beginLine == this.endLine; te = te
 .nextTerminalNode()) {
 if (te.heedsOpeningWhitespace()) {
 trimTrailingPart = false;
 }
 if (te instanceof TrimInstruction
 &#38;&#38; ((TrimInstruction) te).left) {
 trimTrailingPart = true;
 break;
 }
 }
 if (trimTrailingPart)
 trailingPart = EMPTY_CHAR_ARRAY;
 }
 this.text = concat(printablePart, trailingPart);
 }
 }
 }
 }
 return result;
 }

 /*
 * private String leftTrim(String s) { int i =0; while (i&#60;s.length()) { if
 * (!Character.isWhitespace(s.charAt(i))) break; ++i; } return
 * s.substring(i); }
 */
 private int firstNewLineIndex() {
 String content = new String(text);
 int newlineIndex1 = content.indexOf('\n');
 int newlineIndex2 = content.indexOf('\r');
 int result = newlineIndex1 &#62;= 0 ? newlineIndex1 : newlineIndex2;
 if (newlineIndex1 &#62;= 0 &#38;&#38; newlineIndex2 &#62;= 0) {
 result = Math.min(newlineIndex1, newlineIndex2);
 }
 return result;
 }

 private int lastNewLineIndex() {
 String content = new String(text);
 return Math.max(content.lastIndexOf('\r'), content.lastIndexOf('\n'));
 }

 /**
 * figures out how many opening whitespace characters to strip in the
 * post-parse cleanup phase.
 */
 private int openingCharsToStrip() {
 int newlineIndex = firstNewLineIndex();
 if (newlineIndex == -1 &#38;&#38; beginColumn != 1) {
 return 0;
 }
 ++newlineIndex;
 if (text.length &#62; newlineIndex) {
 if (newlineIndex &#62; 0 &#38;&#38; text[newlineIndex - 1] == '\r'
 &#38;&#38; text[newlineIndex] == '\n') {
 ++newlineIndex;
 }
 }
 if (new String(text).substring(0, newlineIndex).trim().length() &#62; 0) {
 return 0;
 }
 // We look at the preceding elements on the line to see if we should
 // strip the opening newline and any whitespace preceding it.
 for (TemplateElement elem = this.prevTerminalNode(); elem != null
 &#38;&#38; elem.endLine == this.beginLine; elem = elem
 .prevTerminalNode()) {
 if (elem.heedsOpeningWhitespace()) {
 return 0;
 }
 }
 return newlineIndex;
 }

 /**
 * figures out how many trailing whitespace characters to strip in the
 * post-parse cleanup phase.
 */
 private int trailingCharsToStrip() {
 String content = new String(text);
 int lastNewlineIndex = lastNewLineIndex();
 if (lastNewlineIndex == -1 &#38;&#38; beginColumn != 1) {
 return 0;
 }
 String substring = content.substring(lastNewlineIndex + 1);
 if (substring.trim().length() &#62; 0) {
 return 0;
 }
 // We look at the elements afterward on the same line to see if we
 // should strip any whitespace after the last newline
 for (TemplateElement elem = this.nextTerminalNode(); elem != null
 &#38;&#38; elem.beginLine == this.endLine; elem = elem
 .nextTerminalNode()) {
 if (elem.heedsTrailingWhitespace()) {
 return 0;
 }
 }
 return substring.length();
 }

 boolean heedsTrailingWhitespace() {
 if (isIgnorable()) {
 return false;
 }
 for (int i = 0; i &#60; text.length; i++) {
 char c = text[i];
 if (c == '\n' &#124;&#124; c == '\r') {
 return false;
 }
 if (!Character.isWhitespace(c)) {
 return true;
 }
 }
 return true;
 }

 boolean heedsOpeningWhitespace() {
 if (isIgnorable()) {
 return false;
 }
 for (int i = text.length - 1; i &#62;= 0; i--) {
 char c = text[i];
 if (c == '\n' &#124;&#124; c == '\r') {
 return false;
 }
 if (!Character.isWhitespace(c)) {
 return true;
 }
 }
 return true;
 }

 boolean isIgnorable() {
 if (text == null &#124;&#124; text.length == 0) {
 return true;
 }
 if (!isWhitespace()) {
 return false;
 }
 // trick here
 boolean atTopLevel = true;
 TemplateElement prevSibling = previousSibling();
 TemplateElement nextSibling = nextSibling();
 return ((prevSibling == null &#38;&#38; atTopLevel) &#124;&#124; nonOutputtingType(prevSibling))
 &#38;&#38; ((nextSibling == null &#38;&#38; atTopLevel) &#124;&#124; nonOutputtingType(nextSibling));
 }

 private boolean nonOutputtingType(TemplateElement element) {
 return (element instanceof Macro &#124;&#124; element instanceof Assignment
 &#124;&#124; element instanceof AssignmentInstruction
 &#124;&#124; element instanceof PropertySetting
 &#124;&#124; element instanceof LibraryLoad &#124;&#124; element instanceof Comment);
 }

 private static char[] substring(char[] c, int from, int to) {
 char[] c2 = new char[to - from];
 System.arraycopy(c, from, c2, 0, c2.length);
 return c2;
 }

 private static char[] substring(char[] c, int from) {
 return substring(c, from, c.length);
 }

 private static char[] trim(char[] c) {
 if (c.length == 0) {
 return c;
 }
 return new String(c).trim().toCharArray();
 }

 private static char[] concat(char[] c1, char[] c2) {
 char[] c = new char[c1.length + c2.length];
 System.arraycopy(c1, 0, c, 0, c1.length);
 System.arraycopy(c2, 0, c, c1.length, c2.length);
 return c;
 }

 boolean isWhitespace() {
 return text == null &#124;&#124; trim(text).length == 0;
 }

}
</pre>
<p></span></span></p>
<ul>
<li>Now if you run the web application you will see the upload page.</li>
<li>Next step is to configure the GaeFileUploadInterceptor in struts.xml file.In struts 2, file upload is done by FileUploadInterceptor which intercept all the MultiPartRequest and provides the File object to the action. Then action does what ever it wants to do with the File object.But, on google app engine you can&#8217;t get the File object because file writes and many other file related operations are not allowed on GAE.So, we will use GaeFileUploadInterceptor which provides a String object which contains all the file content.You can save this string as a blob into the datastore or convert this string object into InputStream and return to the user.You need to add an entry in struts.xml for GaeFileUploadInterceptor.</li>
</ul>
<pre class="brush: xml;">&#60;/pre&#62;
&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34; ?&#62;
&#60;!DOCTYPE struts PUBLIC
&#34;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#34;
&#34;http://struts.apache.org/dtds/struts-2.0.dtd&#34;&#62;
&#60;struts&#62;
&#60;include file=&#34;struts-default.xml&#34;&#62;&#60;/include&#62;
&#60;package name=&#34;&#34; namespace=&#34;/&#34; extends=&#34;struts-default&#34;&#62;
&#60;interceptors&#62;
&#60;interceptor name=&#34;gaeFileUploadInterceptor&#34;
class=&#34;com.struts2.gae.interceptor.GaeFileUploadInterceptor&#34; /&#62;
&#60;interceptor-stack name=&#34;fileUploadStack&#34;&#62;
&#60;interceptor-ref name=&#34;gaeFileUploadInterceptor&#34;&#62;&#60;/interceptor-ref&#62;
&#60;interceptor-ref name=&#34;basicStack&#34;&#62;&#60;/interceptor-ref&#62;
&#60;/interceptor-stack&#62;
&#60;/interceptors&#62;

&#60;default-interceptor-ref name=&#34;fileUploadStack&#34; /&#62;
&#60;action name=&#34;add&#34;&#62;
&#60;result&#62;/upload.jsp&#60;/result&#62;
&#60;/action&#62;
&#60;/package&#62;

&#60;/struts&#62;
&#60;pre&#62;</pre>
<ul>
<li>Next step is to create the UploadAction which will handle the upload request.</li>
</ul>
<pre class="brush: java;">

package com.fileupload;

import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.opensymphony.xwork2.ActionSupport;

public class UploadAction extends ActionSupport {

 private static final long serialVersionUID = -300329750248730163L;
 private String photo;
 private String photoContentType;
 private String photoFileName;
 private InputStream photoStream;

 public String upload() throws  Exception {
 photoStream = IOUtils.toInputStream(photo,&#34;ISO-8859-1&#34;);
 return &#34;success&#34;;
 }

 public String getPhoto() {
 return photo;
 }

 public void setPhoto(String photo) {
 this.photo = photo;
 }

 public String getPhotoContentType() {
 return photoContentType;
 }

 public void setPhotoContentType(String photoContentType) {
 this.photoContentType = photoContentType;
 }

 public String getPhotoFileName() {
 return photoFileName;
 }

 public void setPhotoFileName(String photoFileName) {
 this.photoFileName = photoFileName;
 }

 public InputStream getPhotoStream() {
 return photoStream;
 }

 public void setPhotoStream(InputStream photoStream) {
 this.photoStream = photoStream;
 }
}
</pre>
<p>If you notice there are three properties in the action photo,photoContentType,photoFileName.These properties get their values from the GaeFileUploadInterceptor. These properties have to start with name you gave the file in the upload.jsp <strong>&#60;s:file name=&#8221;photo&#8221; label=&#8221;Upload new Photo&#8221;&#62;&#60;/s:file&#62;</strong>. In this, name is &#8220;photo&#8221; so you will get your file content in a property called photo and the two other properties will start with photo.</p>
<p>The second thing to notice is that result of action is &#8220;success&#8221; which is not SUCCESS you normally use. In this we are using a different result type called org.apache.struts2.dispatcher.StreamResult. Stream result is a custom Result type for sending raw data (via an InputStream) directly to the HttpServletResponse.</p>
<ul>
<li>Now we will configure UploadAction in struts.xml</li>
</ul>
<pre class="brush: xml;">

&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34; ?&#62;
&#60;!DOCTYPE struts PUBLIC
&#34;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#34;
&#34;http://struts.apache.org/dtds/struts-2.0.dtd&#34;&#62;
&#60;struts&#62;
 &#60;include file=&#34;struts-default.xml&#34;&#62;&#60;/include&#62;
 &#60;package name=&#34;&#34; namespace=&#34;/&#34; extends=&#34;struts-default&#34;&#62;
 &#60;interceptors&#62;
 &#60;interceptor name=&#34;gaeFileUploadInterceptor&#34;
 class=&#34;com.struts2.gae.interceptor.GaeFileUploadInterceptor&#34; /&#62;
 &#60;interceptor-stack name=&#34;fileUploadStack&#34;&#62;
 &#60;interceptor-ref name=&#34;gaeFileUploadInterceptor&#34;&#62;&#60;/interceptor-ref&#62;
 &#60;interceptor-ref name=&#34;basicStack&#34;&#62;&#60;/interceptor-ref&#62;
 &#60;/interceptor-stack&#62;
 &#60;/interceptors&#62;

 &#60;default-interceptor-ref name=&#34;fileUploadStack&#34; /&#62;
 &#60;action name=&#34;add&#34;&#62;
 &#60;result&#62;/upload.jsp&#60;/result&#62;
 &#60;/action&#62;
 &#60;action name=&#34;upload&#34; method=&#34;upload&#34;&#62;
 &#60;result name=&#34;success&#34; type = &#34;stream&#34;&#62;
 &#60;param name=&#34;contentType&#34;&#62;image/jpeg&#60;/param&#62;
 &#60;param name=&#34;inputName&#34;&#62;photoStream&#60;/param&#62;
 &#60;param name=&#34;contentDisposition&#34;&#62;filename=&#34;photo.jpg&#34;&#60;/param&#62;
 &#60;param name=&#34;bufferSize&#34;&#62;1024&#60;/param&#62;
 &#60;/result&#62;
 &#60;/action&#62;
 &#60;/package&#62;

&#60;/struts&#62;
</pre>
<ul>
<li>Finally, Run this application you will be able to upload the photo and then view it in your browser.</li>
</ul>
<p>In this blog, i have tried to explain you how you can do file upload using struts 2 on google app engine.Please make sure you download the <a href="http://code.google.com/p/struts2-gae/">struts2-gae jar</a>.Hope this helps you all.</p>
<p>You can dowload the sample project from <a href="http://code.google.com/p/struts2-gae/downloads/list">here</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Getting Started With Struts2 - Part 1]]></title>
<link>http://ruemarin.wordpress.com/2009/09/28/getting-started-with-struts2/</link>
<pubDate>Mon, 28 Sep 2009 23:49:39 +0000</pubDate>
<dc:creator>ruemarin</dc:creator>
<guid>http://ruemarin.wordpress.com/2009/09/28/getting-started-with-struts2/</guid>
<description><![CDATA[My first Struts2 steps &#8230; At first, I got very confused with Struts2 on how and where to get st]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><h1>My first Struts2 steps &#8230;</h1>
<p>At first, I got very confused with Struts2 on how and where to get started.</p>
<ul>
<li>What do I need to know? Learn? Shall I first learn about Servlet and JSP? How much shall I know?</li>
<li>How about Enterprise Java Beans? JavaBeans? What do I need to know?</li>
</ul>
<p>I started with many resources without finding anything for a beginner that was easy to follow and understand and really thought struts2 and the Java world are very difficult to penetrate.  These are some of the resources I first used but did not like:</p>
<ul>
<li><a href="http://www.packtpub.com/apache-struts-2-web-application-development-beginners-guide/book">http://www.packtpub.com/apache-struts-2-web-application-development-beginners-guide/book</a>. I thought it wasn&#8217;t easy to access is as a beginner &#8230;</li>
<li>APress book on Struts2 which preview is available online at h<a href="http://www.apress.com/book/preview/9781590599037">ttp://www.apress.com/book/preview/9781590599037</a> which also was not the simple and easy introduction that I was looking for.</li>
</ul>
<p>After many hours of looking for the right resources, I finally found 1 site that had what fitted me &#8230; the <strong>struts2 </strong>website itself!!</p>
<ol>
<li>You should start with the <a href="http://struts.apache.org/2.x/docs/bootstrap.html">bootstrap</a> series are easy enough and will help you to make your first baby steps.</li>
<li>Then <a href="http://www.vaannila.com">vaannila.com</a> has also series of tutorials pretty easy to follow. Plus it has also simple tutorials on Hibernate and Spring.</li>
<li><a href="http://struts.apache.org/2.x/docs/home.html">http://struts.apache.org/2.x/docs/home.html</a> has a link to a <a href="http://www.infoq.com/minibooks/starting-struts2">free PDF</a> to start with Struts2.</li>
</ol>
<p>Besides the first 2 tutorials, all the resources I found were starting with a brief description of the framework and then configuration .. struts2 is a lot of configuration so don&#8217;t be discouraged and just go over it until it&#8217;s more fun.</p>
<p>I think if you have Web Development background but new to the Java world, those are the steps that will get you familiar with the Struts2 framework.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Struts2 - Chapter 4: OGNL - Object Graph Notation Language]]></title>
<link>http://struts2tutorial.wordpress.com/2009/09/25/8/</link>
<pubDate>Fri, 25 Sep 2009 19:25:40 +0000</pubDate>
<dc:creator>sanjeevdebnath</dc:creator>
<guid>http://struts2tutorial.wordpress.com/2009/09/25/8/</guid>
<description><![CDATA[]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img style="visibility:hidden;width:0;height:0;" src="http://counters.gigya.com/wildfire/IMP/CXNID=2000002.0NXC/bHQ9MTI1MzkwNjcwNzk1NSZwdD*xMjUzOTA2NzI1NDk2JnA9MTAxOTEmZD1zc19lbWJlZCZuPXdvcmRwcmVzcyZnPTImbz*5MzgyOTdhMWU1ZGY*OGYxOGQxZTY*YjlmM2VkYmRmNSZvZj*w.gif" border="0" alt="" width="0" height="0" /></p>
<div id="__ss_2066165" style="width:425px;text-align:left;"><iframe frameborder="0" width="433" height="363" src="http://wpcomwidgets.com/?width=425&amp;height=355&amp;src=http%3A%2F%2Fstatic.slidesharecdn.com%2Fswf%2Fssplayer2.swf%3Fdoc%3Dstruts2-course-04-090925102232-phpapp01%26stripped_title%3Dstruts2-course-04&amp;quality=high&amp;wmode=tranparent&amp;_tag=gigya&amp;_hash=207fddd44258f0d99138c20f14bdff41" id="207fddd44258f0d99138c20f14bdff41"></iframe></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Struts2 - Chapter 3: Actions &amp; Results]]></title>
<link>http://struts2tutorial.wordpress.com/2009/09/25/7/</link>
<pubDate>Fri, 25 Sep 2009 19:24:51 +0000</pubDate>
<dc:creator>sanjeevdebnath</dc:creator>
<guid>http://struts2tutorial.wordpress.com/2009/09/25/7/</guid>
<description><![CDATA[]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img style="visibility:hidden;width:0;height:0;" src="http://counters.gigya.com/wildfire/IMP/CXNID=2000002.0NXC/bHQ9MTI1MzkwNjYwMjU*MCZwdD*xMjUzOTA2NjgxNjU1JnA9MTAxOTEmZD1zc19lbWJlZCZuPXdvcmRwcmVzcyZnPTImbz*5MzgyOTdhMWU1ZGY*OGYxOGQxZTY*YjlmM2VkYmRmNSZvZj*w.gif" border="0" alt="" width="0" height="0" /></p>
<div id="__ss_2045536" style="width:425px;text-align:left;"><iframe frameborder="0" width="433" height="363" src="http://wpcomwidgets.com/?width=425&amp;height=355&amp;src=http%3A%2F%2Fstatic.slidesharecdn.com%2Fswf%2Fssplayer2.swf%3Fdoc%3Dstruts2-course-03-090922181358-phpapp01%26stripped_title%3Dstruts2-course-03&amp;quality=high&amp;wmode=tranparent&amp;_tag=gigya&amp;_hash=75850316a24ed454f7cd0cd819046e5a" id="75850316a24ed454f7cd0cd819046e5a"></iframe></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Struts2 - Chapter 2: Installation &amp; Configuration]]></title>
<link>http://struts2tutorial.wordpress.com/2009/09/25/6/</link>
<pubDate>Fri, 25 Sep 2009 19:21:30 +0000</pubDate>
<dc:creator>sanjeevdebnath</dc:creator>
<guid>http://struts2tutorial.wordpress.com/2009/09/25/6/</guid>
<description><![CDATA[]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img style="visibility:hidden;width:0;height:0;" src="http://counters.gigya.com/wildfire/IMP/CXNID=2000002.0NXC/bHQ9MTI1MzkwNjQyNzM2NyZwdD*xMjUzOTA2NDc5NDg3JnA9MTAxOTEmZD1zc19lbWJlZCZuPXdvcmRwcmVzcyZnPTImbz*5MzgyOTdhMWU1ZGY*OGYxOGQxZTY*YjlmM2VkYmRmNSZvZj*w.gif" border="0" alt="" width="0" height="0" /></p>
<div id="__ss_2045535" style="width:425px;text-align:left;"><iframe frameborder="0" width="433" height="363" src="http://wpcomwidgets.com/?width=425&amp;height=355&amp;src=http%3A%2F%2Fstatic.slidesharecdn.com%2Fswf%2Fssplayer2.swf%3Fdoc%3Dstruts2-course-02-090922181353-phpapp01%26stripped_title%3Dstruts2-course-02&amp;quality=high&amp;wmode=tranparent&amp;_tag=gigya&amp;_hash=48c613b49ac6caea6744d9fddf771c07" id="48c613b49ac6caea6744d9fddf771c07"></iframe></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Struts2 - Chapter 1: Evolution of web applications]]></title>
<link>http://struts2tutorial.wordpress.com/2009/09/25/5/</link>
<pubDate>Fri, 25 Sep 2009 19:18:13 +0000</pubDate>
<dc:creator>sanjeevdebnath</dc:creator>
<guid>http://struts2tutorial.wordpress.com/2009/09/25/5/</guid>
<description><![CDATA[]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img style="visibility:hidden;width:0;height:0;" src="http://counters.gigya.com/wildfire/IMP/CXNID=2000002.0NXC/bHQ9MTI1MzkwMjY*MTE5OCZwdD*xMjUzOTA2Mjc5NjIzJnA9MTAxOTEmZD1zc19lbWJlZCZuPXdvcmRwcmVzcyZnPTImbz*5MzgyOTdhMWU1ZGY*OGYxOGQxZTY*YjlmM2VkYmRmNSZvZj*w.gif" border="0" alt="" width="0" height="0" /></p>
<div id="__ss_2035734" style="width:425px;text-align:left;"><iframe frameborder="0" width="433" height="363" src="http://wpcomwidgets.com/?width=425&amp;height=355&amp;src=http%3A%2F%2Fstatic.slidesharecdn.com%2Fswf%2Fssplayer2.swf%3Fdoc%3Dstruts2-course-01-090921190048-phpapp01%26stripped_title%3Dstruts2-course-chapter-01&amp;quality=high&amp;wmode=tranparent&amp;_tag=gigya&amp;_hash=7176c5a724e97eabdb90ef3fd490a94c" id="7176c5a724e97eabdb90ef3fd490a94c"></iframe></p>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Web development in Java: Installing the tools]]></title>
<link>http://ruemarin.wordpress.com/2009/09/19/back-to-java-development/</link>
<pubDate>Sat, 19 Sep 2009 21:46:55 +0000</pubDate>
<dc:creator>ruemarin</dc:creator>
<guid>http://ruemarin.wordpress.com/2009/09/19/back-to-java-development/</guid>
<description><![CDATA[I will soon start a new job as a Web Developer where using J2EE. I do not have experience in Java We]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I will soon start a new job as a Web Developer where using J2EE.</p>
<p>I do not have experience in Java Web Development but I do in ASP.NET and C#, PHP and Ruby on Rails.</p>
<p>So I will add new posts on my learning experience on Java Web Development and blog about Struts2 framework, Maven, Eclipse &#8230;</p>
<p>FYI, I use a Mac with Leopard OS on it. You should also know that I am a newbie to web development in Java, so you are warned! This is more like a blog from beginner to beginner.</p>
<p>In today&#8217;s post, I&#8217;ll talk about some installation issues of Tomcat, Eclipse and Struts2.</p>
<p>Starting point:</p>
<h2>Installing Java</h2>
<p>This is only for Windows users. You need to download and save the Java SDK. I installed mine under C:\Sun\</p>
<h2>Installing Tomcat</h2>
<p>Link to download Tomcat: <a href="http://tomcat.apache.org/download-60.cgi">http://tomcat.apache.org/download-60.cgi</a></p>
<p>Here is link to install Tomcat on MacOSX: <a title="Installing Tomcat on Mac OS X" href="http://www.malisphoto.com/tips/tomcatonosx.html" target="_blank">http://www.malisphoto.com/tips/tomcatonosx.html</a></p>
<h2>Installing Eclipse</h2>
<p><a href="http://www.eclipse.org/downloads/">http://www.eclipse.org/downloads/</a></p>
<p>Download this version: <a style="outline-width:0;outline-style:initial;outline-color:initial;font-size:14px;text-align:left;color:#7036be;font-weight:bold;text-decoration:none;line-height:14px;border:0 initial initial;margin:0;padding:3px 0;" href="http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR1/eclipse-jee-galileo-SR1-win32.zip">Eclipse IDE for Java EE Developers </a></p>
<p>You can install Eclipse in your application folder on Mac or in the Program Files on Windows.</p>
<ol>
<li>Eclipse uses a special folder called workspace where all the projects created via Eclipse will be located. On Mac, I created this folder under /Documents/Projects and on Windows, I created it under C:/</li>
<li>On <strong>Windows</strong> only: make also sure that the init file (C:\Program Files\eclipse\eclipse.init) is pointing to the Java runtime file in the JDK&#8217;s bin folder. I have mine under C:\Sun\SDK\jdk\bin. The reason I  mention this is that I had some issues to run Tomcat because Eclipse was looking for the javaw.exe file under my JRE folder (C:\Program Files\Java\jre1.6.0_02) &#8230; which didn&#8217;t have it. The difference between the JRE and the JDK is that the JDK allows you to develop and run Java applications while the JRE only allows you to run Java applications. So if you need to update the .init file, replace the line under -vm with the path to your jdk&#8217;s bin folder (ex: mine is C:/Sun/SDK/jdk/bin/javaw.exe.). Mac users will not have this issue because Mac comes with Java installed in a well defined folder .. so all JAVA apps running under Mac know where to look for the Java runtime. On Windows, the user does the installation and make the choice on where to save all the Java files.</li>
<li>On Mac, I put my eclipse folder in the Application folder so the location is different for all Windows users.</li>
</ol>
<h2>Installing Struts2</h2>
<p><a href="http://struts.apache.org/2.x/index.html">http://struts.apache.org/2.x/index.html</a></p>
<p>There is nothing to do besides downloading the package.</p>
<p>Struts2 is basically a library you will reference for your projects from Eclipse. So download it, unzip it and put the unzipped folder to a meaningful location like My Documents/Library/Java/Struts2/version on Windows on under HD/Library/Java/Struts2/ on Mac.</p>
<p>Now, explore the folder. You will see 4 main directories:</p>
<ol>
<li>apps: Contains templates of struts app and especially the blank app. These sample apps are packaged under the WAR format. To uncrompress them, change their extension to .zip instead of .war and then uncompress. Navigate to the uncompressed blank app&#8217;s folder to see the required jar files needed for basic struts2 web apps and aslo to get a basic struts.xml file.</li>
<li>docs: contains documentation</li>
<li>lib: contains the jar files</li>
<li>src: contains the source code of the framework</li>
</ol>
<p>When you will create a Struts2 projects from scratch by hand (without Maven), you will copy and paste the needed jar file to the lib folder of your application.</p>
<p>And that&#8217;s pretty much it for the installation part. We will install other components later but let&#8217;s keep it simple and to the point for now.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Struts 2 : the modern web application framework]]></title>
<link>http://erdosam.wordpress.com/2009/09/04/struts-2-the-modern-web-application-framework/</link>
<pubDate>Fri, 04 Sep 2009 23:02:54 +0000</pubDate>
<dc:creator>syamtastic</dc:creator>
<guid>http://erdosam.wordpress.com/2009/09/04/struts-2-the-modern-web-application-framework/</guid>
<description><![CDATA[Modern web applications are situated in a complex technological context. Some books that you read mi]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Modern web applications are situated in a complex technological context. Some books that you read might be about a single subject, such as the Java language, or a specific API or library. This book is about Struts 2, a full-featured web application framework for the Java EE platform. As such, this book must take into account the vast array of technologies that converge in the space of the Java EE.</p>
<p>In response to this complexity, we’ll start by outlining some of the most impor- tant technologies that Struts 2 depends on. Struts 2 provides some powerful boosts to production through convention over configuration, and automates many tasks that were previously accomplished only by the sweat of the developer. But we think true efficiency comes through understanding the underlying technological context, particularly as these technologies become more and more obscured by the opacity of scaffolding and the like. That said, the first half of this chapter provides a primer on the Struts 2 environment. If you’re comfortable with this stuff, feel free to skim or skip these sections entirely.</p>
<p>After sketching the important figures of the landscape, we’ll move into a high-level overview of Struts 2 itself. We’ll introduce how the Model-View-Controller (MVC) fits into the Struts 2 architecture. After that, we’ll go through a more detailed account of what happens when the framework processes a request. When we finish up, you’ll be fully ready for chapter 2’s HelloWorld application.</p>
<p>Let’s get going!</p>
<h3>1.1 Web applications: a quick study</h3>
<p>This section provides a rough primer on the technological context of a web application. We’ll cover the technology stack upon which web applications sit, and take a quick survey of common tasks that all web applications must routinely accomplish as they service their requests. If you’re quite familiar with this information, you could skip ahead to the Struts 2 architectural overview in section 1.3, but a quick study of the following sections would still provide an orientation on how we, the authors, view the web application domain.</p>
<h4>1.1.1 Using the Web to build applications</h4>
<p>While many Java developers today may have worked on web applications for most of their careers, it’s always beneficial to revisit the foundations of the domain in which one is working. A solid understanding of the context in which a framework such as Struts 2 is situated provides an intuitive understanding of the architectural decisions made by the framework. Also, establishing a common vocabulary for our discussions will make everything easier throughout the book.</p>
<p>A web application is simply, or not so simply, an application that runs over the Web. With rapid improvements in Internet speed, connectivity, and client/server technologies, the Web has become an increasingly powerful platform for building all classes of applications, from standard business-oriented enterprise solutions to personal software. The latest iterations of web applications must be as full featured and easy to use as traditional desktop applications. Yet, in spite of the increasing variety in applications built on the web platform, the core workflow of these applications remains markedly consistent, a perfect opportunity for reuse. Frameworks such as Struts 2 strive to release the developer from the mundane concerns of the domain by providing a reusable architectural solution to the core web application workflows.</p>
<h4>1.1.2 Examining the technology stack</h4>
<p>We’ll now take a quick look at two of the main components in the technology stack upon which a web application is built. In one sense, the Web is a simple affair: as with all good solutions, if it weren’t simple, it probably wouldn’t be successful. Figure 1.1 provides a simple depiction of the context in which Struts 2 is used.</p>
<p>As depicted in figure 1.1, Struts 2 sits on top of two important technologies. At the heart of all Struts 2 applications lie the client/server exchanges of the<br />
HTTP protocol. The Java Servlet API exposes these low level HTTP communications to the Java language. Although it’s possible to write web applications by directly coding against the Servlet API, this is generally not considered a good practice. Basically, Struts 2 uses the Servlet API so that you don’t have to. But while it’s a good idea to keep the Servlet API out of your Struts 2 code, it seems cavalier to enter into Struts 2 development without some idea of the underlying technologies. The next two sections provide concise descriptions of the more relevant aspects of HTTP and Java Servlets.</p>
<h5>HYPERTEXT TRANSFER PROTOCOL (HTTP)</h5>
<p>Most web applications run on top of HTTP. This protocol is a stateless series of client/server message exchanges. Normally, the client is a web browser and the server is a web or application server. The client initiates communication by sending a request for a specific resource. The resource can be a static HTML document that exists on the server’s local file system, or it can be a dynamically generated document with untold complexity behind its creation.</p>
<p>Much could be said about the HTTP protocol and the variety of ways of doing things in this domain. We’ll limit ourselves to the most important implications as seen from the perspective of a web application. We can start by noting that HTTP was not originally designed to serve in the capacity that web application developers demand of it. It was meant for requesting and serving static HTML documents. All web applications built on HTTP must address this discrepancy.</p>
<p>For web applications, HTTP has two hurdles to get over. It’s stateless, and it’s text based. Stateless protocols don’t keep track of the relationships among the various requests they receive. Each request is handled as if it were the only request the server had ever received. The HTTP server keeps no records that would allow it to track and logically connect multiple requests from a given client. The server has the client’s address, but it will only be used to return the currently requested document. If the client turns around and requests another document, the server will be unaware of this<br />
client’s repeated visits.</p>
<p>But if we are trying to build more complex web applications with more complicated use cases, this won’t work. Take the simplest, most common case of the secure web application. A secure application needs to authenticate its users. To do this, the request in which the client sends the user name and password must somehow be associated with all other requests coming from that client during that user session. Without the ability to keep track of relationships among various requests, even this introductory use case of modern web applications is impossible. This problem must be addressed by every modern web application.</p>
<p>Equally as troublesome, HTTP also is text based. Mating a text-based technology to a strongly typed technology such as Java creates a significant amount of data-binding work. While in the form of an HTTP request, all data must be represented as text. Somewhere along the way, this encoding of data must be mapped onto Java data types. Furthermore, this process must occur at both ends of the request-handling process. Incoming request parameters must be migrated into the Java environment, and outgoing responses must pull data from Java back into the text-based HTTP response. While this is not rocket science, it can create mounds of drudge work for a web application. These tasks are both error-prone and time-consuming.</p>
<h5>JAVA SERVLET API</h5>
<p>The Java Servlet API helps alleviate some of the pain. This important technology exposes HTTP to the Java platform. This means that Java developers can write HTTP server code against an intuitive object-oriented abstraction of the HTTP client/server communications. <span style="color:#0000ff;">The central figures in the Servlet API are the servlet, request, and response objects</span>. A <span style="color:#ff0000;">servlet</span> is a singleton Java object whose whole purpose is to receive requests and return responses after some arbitrary back-end processing. The <span style="color:#ff0000;">request<br />
</span> object encapsulates the various details of the request, including the all-important request parameters as submitted via form fields and querystring parameters. The <span style="color:#ff0000;">response</span> object includes such key items as the response headers and the output stream that will generate the text of the response. In short, a <span style="color:#0000ff;">servlet receives a request object, examines its data, does the appropriate back-end magic, and then writes and returns the response</span> to the client.</p>
<h5>ESSENTIAL KNOWLEDGE</h5>
<p style="padding-left:30px;">You should know Sun and the Servlet Specification. If you’re unfamiliar with Sun’s way of doing things, here’s a short course. Sun provides a specification of a technology, such as the Servlet API. The specifications are  generated through a community process that includes a variety of interested parties, not the least of which is Sun itself. The specification details the obligations and contracts that the API must honor; actual implementations are provided by various third-party vendors. In the case of the Servlet Specification, the implementations are servlet containers. These containers can be standalone implementations such as the popular Apache Tomcat, or they can be containers embedded in some larger application server. They also run the gamut from open source to fully proprietary. If you’re unfamiliar with the Servlet Specification, we recommend reading it. It’s short, to the point, and well written.</p>
<p>Next</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Creating Struts2 application on Google App Engine (GAE)]]></title>
<link>http://whyjava.wordpress.com/2009/08/30/creating-struts2-application-on-google-app-engine-gae/</link>
<pubDate>Sun, 30 Aug 2009 21:37:49 +0000</pubDate>
<dc:creator>whyjava</dc:creator>
<guid>http://whyjava.wordpress.com/2009/08/30/creating-struts2-application-on-google-app-engine-gae/</guid>
<description><![CDATA[Why i am writing this blog? I faced lot of problems while creating my first application using Struts]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Why i am writing this blog?<br />
</strong></p>
<p>I faced lot of problems while creating my first application using Struts 2 on Google App Engine . So i decided to write a blog detailing how developers can create their application on Struts2 by avoiding the problems that i faced while developing my application.</p>
<p><strong>Note</strong></p>
<p>If you want to do <strong>FileUpload using struts 2  on google app engine </strong>please refer to this <a href="http://whyjava.wordpress.com/2009/10/04/file-upload-on-google-app-engine-using-struts2/">post</a>.</p>
<p><strong>Prerequisites for starting Struts2 Application on Google App Engine</strong></p>
<p>Before you start building your sample application on google app engine using struts 2 you will need the following:-</p>
<ol>
<li>Google App Engine runs on java 5 and above so if necessary, <a href="http://java.sun.com/javase/downloads/index.jsp">download and install the Java SE Development Kit (JDK) for your platform</a> and <a href="http://developer.apple.com/java/">for mac users</a> download and install the latest version.</li>
<li>In this example we will be using Eclipse as our ide. So if necessary, <a href="http://www.eclipse.org/">download eclipse </a> and <a href="http://code.google.com/appengine/docs/java/tools/eclipse.html">google app engine plugin for eclipse</a>.You will also need to download the <a href="http://code.google.com/appengine/downloads.html">google  java app engine SDK</a>. For more information you can refer to <a href="http://code.google.com/appengine/docs/java/gettingstarted/installing.html">installing the java SDK for google app engine</a>.</li>
<li>Download the latest release of <a href="http://struts.apache.org/download.cgi">Struts2 framework</a>.If you want to learn struts 2 a very good reference is struts 2 in action book.Please buy <a href="http://www.amazon.com/gp/product/193398807X?ie=UTF8&#38;tag=javblo07-20&#38;linkCode=as2&#38;camp=1789&#38;creative=9325&#38;creativeASIN=193398807X">Struts 2 in Action</a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=javblo07-20&#38;l=as2&#38;o=1&#38;a=193398807X" border="0" alt="" width="1" height="1" />.</li>
</ol>
<p><strong>Step by Step procedure to create Struts2 application on Google App Engine.</strong></p>
<p>Step 1: Create a new project by clicking the New Web Application Project button in the toolbar<img class="alignnone size-full wp-image-14" title="new_app_button" src="http://whyjava.wordpress.com/files/2009/08/new_app_button1.png" alt="new_app_button" width="20" height="20" />.</p>
<p><img class="aligncenter size-large wp-image-17" title="1" src="http://whyjava.wordpress.com/files/2009/08/11.jpg?w=1024" alt="1" width="1024" height="624" /></p>
<p>Step 2 : Give the project name say login  as we are going to create a simple login application. Enter package name as com.login and uncheck &#8220;Use Google Web Toolkit,&#8221; and ensure &#8220;Use Google App Engine&#8221; is checked and click the finish button.</p>
<p><img class="aligncenter size-large wp-image-19" title="2" src="http://whyjava.wordpress.com/files/2009/08/2.jpg?w=1024" alt="2" width="1024" height="605" /></p>
<p>Step3 : When you click the finish button you will get a sample HelloWorld application, which you can run going in the Run menu, select Run As &#62; Web Application.By default application will run at port 8080, you can view the sample application at <a href="http://localhost:8080">http://locahost:8080</a>. For more information on the sample google web application created by the plugin you can refer to <a href="http://code.google.com/appengine/docs/java/gettingstarted/creating.html">Google java app engine documentation</a> .Please keep in mind that intent of this document is not to provide developers the <a href="http://code.google.com/appengine/docs/java/overview.html">overview of Google App engine for Java</a>.</p>
<p>Step4 : By now you are ready with the google app engine infrastructure and we can move to the next step of creating a login application in Struts 2.</p>
<ul>
<li>for creating a struts 2 application you will need to first add the required dependencies to the login project. The required struts 2 jars are below mentioned and you can find these jars in struts2 package you downloaded inside the lib folder :-
<ul>
<li>commons-fileupload-1.2.1.jar</li>
<li>commons-io-1.3.2.jar</li>
<li>commons-logging-1.1.jar</li>
<li>freemarker-2.3.13.jar</li>
<li>ognl-2.6.11.jar</li>
<li>struts2-core-2.1.6.jar</li>
<li>xwork-2.1.2.jar</li>
</ul>
</li>
<li>Add these dependencies in your eclipse java build path.</li>
</ul>
<p><img class="aligncenter size-large wp-image-22" title="3" src="http://whyjava.wordpress.com/files/2009/08/3.jpg?w=1024" alt="3" width="1024" height="501" /></p>
<ul>
<li>Add these dependencies in the war/WEB-INF/lib folder so that these jars gets deployed along with your application.</li>
</ul>
<p><img class="aligncenter size-large wp-image-23" title="4" src="http://whyjava.wordpress.com/files/2009/08/4.jpg?w=1024" alt="4" width="1024" height="615" /></p>
<ul>
<li>As you can see in the above image there are some warnings in the problems view like  &#8220;commons-fileupload-1.2.1.jar&#8217; will not be available on the server&#8217;s classpath&#8221; .To remove these warnings you need to right click on the project and select properties and then go to Google &#62; web application and click the add button and add all the jars and then press ok.</li>
</ul>
<p><img class="aligncenter size-large wp-image-24" title="5" src="http://whyjava.wordpress.com/files/2009/08/5.jpg?w=1024" alt="5" width="1024" height="584" /></p>
<ul>
<li>First step in creating a struts 2 application is configuring the web.xml (deployment descriptor) which is located in WEB-INF folder.You can remove the servlet declaration from web.xml as we will not be needing this.We need to add the FilterDispatcher declaration in web.xml because in struts2 every request goes  pass through FilterDispatcher which will invoke the appropriate action corresponding to the URL mapping.So our web.xml will look like :-</li>
</ul>
<pre class="brush: xml;">
&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62;
&#60;web-app xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34;
	xmlns=&#34;http://java.sun.com/xml/ns/javaee&#34; xmlns:web=&#34;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#34;
	xsi:schemaLocation=&#34;http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#34;

	version=&#34;2.5&#34;&#62;
	&#60;filter&#62;
		&#60;filter-name&#62;struts2&#60;/filter-name&#62;
		&#60;filter-class&#62;org.apache.struts2.dispatcher.FilterDispatcher&#60;/filter-class&#62;
	&#60;/filter&#62;
	&#60;filter-mapping&#62;
		&#60;filter-name&#62;struts2&#60;/filter-name&#62;
		&#60;url-pattern&#62;/*&#60;/url-pattern&#62;
	&#60;/filter-mapping&#62;
	&#60;welcome-file-list&#62;
		&#60;welcome-file&#62;index.html&#60;/welcome-file&#62;
	&#60;/welcome-file-list&#62;
&#60;/web-app&#62;
</pre>
<ul>
<li>To start we will be creating a jsp login page using struts 2 tag library and we will call login page from index.html.To call the login page there are two ways first, we can directly call the login.jsp page from link second, we can calling it through struts. We will be taking the second step as this will show you how to configure actions when you dont need to invoke any action.Lets first see how our login page and index.html will look like :-</li>
</ul>
<p><strong>index.html</strong></p>
<pre class="brush: xml;">
&#60;!DOCTYPE HTML PUBLIC &#34;-//W3C//DTD HTML 4.01 Transitional//EN&#34;&#62;
&#60;html&#62;
&#60;head&#62;
&#60;meta http-equiv=&#34;content-type&#34; content=&#34;text/html; charset=UTF-8&#34;&#62;
&#60;title&#62;Struts2 on Google App Engine&#60;/title&#62;
&#60;/head&#62;

&#60;body&#62;
&#60;h1&#62;Struts2 on Google App Engine!&#60;/h1&#62;
&#60;table&#62;
&#60;tr&#62;
&#60;td colspan=&#34;2&#34; style=&#34;font-weight: bold;&#34;&#62;Available Application:&#60;/td&#62;
&#60;/tr&#62;
&#60;tr&#62;
&#60;td&#62;&#60;a href=&#34;/member/login&#34; /&#62;Login&#60;/td&#62;
&#60;/tr&#62;
&#60;/table&#62;
&#60;/body&#62;
&#60;/html&#62;
</pre>
<p><strong>login.jsp</strong></p>
<pre class="brush: xml;">
&#60;%@ page language=&#34;java&#34; contentType=&#34;text/html; charset=ISO-8859-1&#34;
 pageEncoding=&#34;ISO-8859-1&#34;%&#62;
&#60;%@ taglib prefix=&#34;s&#34; uri=&#34;/struts-tags&#34; %&#62;
&#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD HTML 4.01 Transitional//EN&#34; &#34;http://www.w3.org/TR/html4/loose.dtd&#34;&#62;
&#60;html&#62;
&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=ISO-8859-1&#34;&#62;
&#60;title&#62;Please login&#60;/title&#62;
&#60;/head&#62;
&#60;body&#62;
 &#60;s:actionerror/&#62;
 &#60;s:form action=&#34;home&#34; method=&#34;post&#34;&#62;
 &#60;s:textfield name=&#34;username&#34; label=&#34;UserName&#34;&#62;&#60;/s:textfield&#62;
 &#60;s:textfield name=&#34;password&#34; label=&#34;Password&#34;&#62;&#60;/s:textfield&#62;
 &#60;s:submit name=&#34;login&#34; value=&#34;login&#34;&#62;&#60;/s:submit&#62;
 &#60;/s:form&#62;
&#60;/body&#62;
&#60;/html&#62;
</pre>
<ul>
<li>After creating the login.jsp we need to configure this as action in the struts.xml file which you be should put inside source folder parallel to log4j.properties file.We can configure action as mentioned below:-</li>
</ul>
<pre class="brush: xml;">
&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34; ?&#62;
&#60;!DOCTYPE struts PUBLIC
&#34;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#34;
&#34;http://struts.apache.org/dtds/struts-2.0.dtd&#34;&#62;
&#60;struts&#62;
	&#60;include file=&#34;struts-default.xml&#34;&#62;&#60;/include&#62;
&#60;package name=&#34;member&#34; namespace=&#34;/member&#34; extends=&#34;struts-default&#34;&#62;
		&#60;action name=&#34;login&#34;&#62;
			&#60;result&#62;/login.jsp&#60;/result&#62;
		&#60;/action&#62;
	&#60;/package&#62;
&#60;/struts&#62;
</pre>
<ul>
<li>Now try running this application by right click on project run as &#62; web application and click <a href="http://localhost:8080">http://localhost:8080</a>. You will see index.html and when you click on login you will get this exception :-</li>
</ul>
<p><span style="color:#993300;">SEVERE: Unable to set parameter [location] in result of type    [org.apache.struts2.dispatcher.ServletDispatcherResult]</span></p>
<p><span style="color:#993300;">Caught OgnlException while setting property &#8216;location&#8217; on type &#8216;org.apache.struts2.dispatcher.ServletDispatcherResult&#8217;. &#8211; Class: ognl.OgnlRuntime</span></p>
<p><span style="color:#993300;">File: OgnlRuntime.java</span></p>
<p><span style="color:#993300;">Method: invokeMethod</span></p>
<p><span style="color:#993300;">Line: 508 &#8211; ognl/OgnlRuntime.java:508:-1</span></p>
<p><span style="color:#993300;"> at com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:392)</span></p>
<p><span style="color:#993300;">Caused by: java.lang.IllegalAccessException: Method [public void org.apache.struts2.dispatcher.StrutsResultSupport.setLocation(java.lang.String)] cannot be accessed.</span></p>
<p><span style="color:#993300;"> at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:508)</span></p>
<p><span style="color:#993300;"> at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:812)</span></p>
<p><span style="color:#993300;"> at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:964)</span></p>
<p><span style="color:#993300;"> at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:75)</span></p>
<p><span style="color:#993300;"> at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:131)</span></p>
<p><span style="color:#993300;"> at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:28)</span></p>
<p><span style="color:#993300;"> at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1656)</span></p>
<p><span style="color:#993300;"> at ognl.ASTProperty.setValueBody(ASTProperty.java:101)</span></p>
<p><span style="color:#993300;"> at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)</span></p>
<p><span style="color:#993300;"> at ognl.SimpleNode.setValue(SimpleNode.java:246)</span></p>
<p><span style="color:#993300;"> at ognl.Ognl.setValue(Ognl.java:476)</span></p>
<p><span style="color:#993300;"> at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:192)</span></p>
<p><span style="color:#993300;"> at com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:385)</span></p>
<p><span style="color:#993300;"> &#8230; 73 more</span></p>
<ul>
<li>In order to resolve this problem we  need to create an <a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContextListener.html">ServletContextListner</a> which will set OGNL security manager to null when the context is initialized.</li>
</ul>
<pre class="brush: java;">
package com.login;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import ognl.OgnlRuntime;

public class OgnlListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		OgnlRuntime.setSecurityManager(null);
	}

}
</pre>
<ul>
<li>Also we will need to make entry in web.xml file also for OgnlListener</li>
</ul>
<pre class="brush: xml;">
	&#60;listener&#62;
	&#60;listener-class&#62;com.login.OgnlListener&#60;/listener-class&#62;
&#60;/listener&#62;
</pre>
<ul>
<li>Now if you run the web application you will see the login page.</li>
<li>You need to add this step if you are using Google App Engine 1.2.6 because when you run struts2 application on google app engine 1.2.6 you will get the following error:-</li>
</ul>
<p><span style="color:#800000;">javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax.swing.tree.TreeNode is a restricted class. Please see the Google App Engine developer’s guide for more details.<br />
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)<br />
at org.apache.jasper.runtime.PageContextImpl.access$1100(PageContextImpl.java:64)<br />
at org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:745)<br />
at java.security.AccessController.doPrivileged(Native Method)<br />
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:743)<br />
at org.apache.jsp.login_jsp._jspService(login_jsp.java:86)<br />
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)<br />
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)<br />
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)<br />
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)<br />
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)<br />
at com.google.appengine.tools.development.PrivilegedJspServlet.access$101(PrivilegedJspServlet.java:23)<br />
at com.google.appengine.tools.development.PrivilegedJspServlet$2.run(PrivilegedJspServlet.java:59)<br />
at java.security.AccessController.doPrivileged(Native Method)<br />
at com.google.appengine.tools.development.PrivilegedJspServlet.service(PrivilegedJspServlet.java)</span></p>
<p><span style="color:#800000;"><span style="color:#000000;">To avoid this error you need to create a new package </span></span>&#8220;freemarker.core&#8221;<span style="color:#800000;"><span style="color:#000000;"> in your source folder and add the following class </span></span></p>
<p><span style="color:#800000;"><span style="color:#000000;">
<pre class="brush: java;">&#60;/span&#62;&#60;/span&#62;

/*
 * Copyright (c) 2003 The Visigoth Software Society. All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above
copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowledgement:
 *       &#34;This product includes software developed by the
 *        Visigoth Software Society (http://www.visigoths.org/).&#34;
 *    Alternately, this acknowledgement may appear in the software
itself,
 *    if and wherever such third-party acknowledgements normally
appear.
 *
 * 4. Neither the name &#34;FreeMarker&#34;, &#34;Visigoth&#34;, nor any of the names
of the
 *    project contributors may be used to endorse or promote products
derived
 *    from this software without prior written permission. For written
 *    permission, please contact visigo...@visigoths.org.
 *
 * 5. Products derived from this software may not be called
&#34;FreeMarker&#34; or &#34;Visigoth&#34;
 *    nor may &#34;FreeMarker&#34; or &#34;Visigoth&#34; appear in their names
 *    without prior written permission of the Visigoth Software
Society.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE VISIGOTH SOFTWARE SOCIETY OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Visigoth Software Society. For more
 * information on the Visigoth Software Society, please see
 * http://www.visigoths.org/
 */

package freemarker.core;

import java.io.IOException;

/**
 * A TemplateElement representing a block of plain text.
 *
 * @version $Id: TextBlock.java,v 1.17 2004/01/06 17:06:42 szegedia Exp $
 */
public final class TextBlock extends TemplateElement {
 private static final char[] EMPTY_CHAR_ARRAY = new char[0];
 static final TextBlock EMPTY_BLOCK = new TextBlock(EMPTY_CHAR_ARRAY, false);
 // We're using char[] instead of String for storing the text block because
 // Writer.write(String) involves copying the String contents to a char[]
 // using String.getChars(), and then calling Writer.write(char[]).By
 // using Writer.write(char[]) directly, we avoid array copying on each
 // write.
 private char[] text;
 private final boolean unparsed;

 public TextBlock(String text) {
 this(text, false);
 }

 public TextBlock(String text, boolean unparsed) {
 this(text.toCharArray(), unparsed);
 }

 private TextBlock(char[] text, boolean unparsed) {
 this.text = text;
 this.unparsed = unparsed;
 }

 /**
 * Simply outputs the text.
 */
 public void accept(Environment env) throws IOException {
 env.getOut().write(text);
 }

 public String getCanonicalForm() {
 String text = new String(this.text);
 if (unparsed) {
 return &#34;&#60;#noparse&#62;&#34; + text + &#34;&#60;/#noparse&#62;&#34;;
 }
 return text;
 }

 public String getDescription() {
 String s = new String(text).trim();
 if (s.length() == 0) {
 return &#34;whitespace&#34;;
 }
 if (s.length() &#62; 20) {
 s = s.substring(0, 20) + &#34;...&#34;;
 s = s.replace('\n', ' ');
 s = s.replace('\r', ' ');
 }
 return &#34;text block (&#34; + s + &#34;)&#34;;
 }

 TemplateElement postParseCleanup(boolean stripWhitespace) {
 if (text.length == 0)
 return this;
 int openingCharsToStrip = 0, trailingCharsToStrip = 0;
 boolean deliberateLeftTrim = deliberateLeftTrim();
 boolean deliberateRightTrim = deliberateRightTrim();
 if (!stripWhitespace &#124;&#124; text.length == 0) {
 return this;
 }
 if (parent.parent == null &#38;&#38; previousSibling() == null)
 return this;
 if (!deliberateLeftTrim) {
 trailingCharsToStrip = trailingCharsToStrip();
 }
 if (!deliberateRightTrim) {
 openingCharsToStrip = openingCharsToStrip();
 }
 if (openingCharsToStrip == 0 &#38;&#38; trailingCharsToStrip == 0) {
 return this;
 }
 this.text = substring(text, openingCharsToStrip, text.length
 - trailingCharsToStrip);
 if (openingCharsToStrip &#62; 0) {
 this.beginLine++;
 this.beginColumn = 1;
 }
 if (trailingCharsToStrip &#62; 0) {
 this.endColumn = 0;
 }
 return this;
 }

 /**
 * Scans forward the nodes on the same line to see whether there is a
 * deliberate left trim in effect. Returns true if the left trim was
 * present.
 */
 private boolean deliberateLeftTrim() {
 boolean result = false;
 for (TemplateElement elem = this.nextTerminalNode(); elem != null
 &#38;&#38; elem.beginLine == this.endLine; elem = elem
 .nextTerminalNode()) {
 if (elem instanceof TrimInstruction) {
 TrimInstruction ti = (TrimInstruction) elem;
 if (!ti.left &#38;&#38; !ti.right) {
 result = true;
 }
 if (ti.left) {
 result = true;
 int lastNewLineIndex = lastNewLineIndex();
 if (lastNewLineIndex &#62;= 0 &#124;&#124; beginColumn == 1) {
 char[] firstPart = substring(text, 0,
 lastNewLineIndex + 1);
 char[] lastLine = substring(text, 1 + lastNewLineIndex);
 if (trim(lastLine).length == 0) {
 this.text = firstPart;
 this.endColumn = 0;
 } else {
 int i = 0;
 while (Character.isWhitespace(lastLine[i])) {
 i++;
 }
 char[] printablePart = substring(lastLine, i);
 this.text = concat(firstPart, printablePart);
 }
 }
 }
 }
 }
 if (result) {
 }
 return result;
 }

 /**
 * Checks for the presence of a t or rt directive on the same line. Returns
 * true if the right trim directive was present.
 */
 private boolean deliberateRightTrim() {
 boolean result = false;
 for (TemplateElement elem = this.prevTerminalNode(); elem != null
 &#38;&#38; elem.endLine == this.beginLine; elem = elem
 .prevTerminalNode()) {
 if (elem instanceof TrimInstruction) {
 TrimInstruction ti = (TrimInstruction) elem;
 if (!ti.left &#38;&#38; !ti.right) {
 result = true;
 }
 if (ti.right) {
 result = true;
 int firstLineIndex = firstNewLineIndex() + 1;
 if (firstLineIndex == 0) {
 return false;
 }
 if (text.length &#62; firstLineIndex
 &#38;&#38; text[firstLineIndex - 1] == '\r'
 &#38;&#38; text[firstLineIndex] == '\n') {
 firstLineIndex++;
 }
 char[] trailingPart = substring(text, firstLineIndex);
 char[] openingPart = substring(text, 0, firstLineIndex);
 if (trim(openingPart).length == 0) {
 this.text = trailingPart;
 this.beginLine++;
 this.beginColumn = 1;
 } else {
 int lastNonWS = openingPart.length - 1;
 while (Character.isWhitespace(text[lastNonWS])) {
 lastNonWS--;
 }
 char[] printablePart = substring(text, 0, lastNonWS + 1);
 if (trim(trailingPart).length == 0) {
 // THIS BLOCK IS HEINOUS! THERE MUST BE A BETTER
 // WAY! REVISIT (JR)
 boolean trimTrailingPart = true;
 for (TemplateElement te = this.nextTerminalNode(); te != null
 &#38;&#38; te.beginLine == this.endLine; te = te
 .nextTerminalNode()) {
 if (te.heedsOpeningWhitespace()) {
 trimTrailingPart = false;
 }
 if (te instanceof TrimInstruction
 &#38;&#38; ((TrimInstruction) te).left) {
 trimTrailingPart = true;
 break;
 }
 }
 if (trimTrailingPart)
 trailingPart = EMPTY_CHAR_ARRAY;
 }
 this.text = concat(printablePart, trailingPart);
 }
 }
 }
 }
 return result;
 }

 /*
 * private String leftTrim(String s) { int i =0; while (i&#60;s.length()) { if
 * (!Character.isWhitespace(s.charAt(i))) break; ++i; } return
 * s.substring(i); }
 */
 private int firstNewLineIndex() {
 String content = new String(text);
 int newlineIndex1 = content.indexOf('\n');
 int newlineIndex2 = content.indexOf('\r');
 int result = newlineIndex1 &#62;= 0 ? newlineIndex1 : newlineIndex2;
 if (newlineIndex1 &#62;= 0 &#38;&#38; newlineIndex2 &#62;= 0) {
 result = Math.min(newlineIndex1, newlineIndex2);
 }
 return result;
 }

 private int lastNewLineIndex() {
 String content = new String(text);
 return Math.max(content.lastIndexOf('\r'), content.lastIndexOf('\n'));
 }

 /**
 * figures out how many opening whitespace characters to strip in the
 * post-parse cleanup phase.
 */
 private int openingCharsToStrip() {
 int newlineIndex = firstNewLineIndex();
 if (newlineIndex == -1 &#38;&#38; beginColumn != 1) {
 return 0;
 }
 ++newlineIndex;
 if (text.length &#62; newlineIndex) {
 if (newlineIndex &#62; 0 &#38;&#38; text[newlineIndex - 1] == '\r'
 &#38;&#38; text[newlineIndex] == '\n') {
 ++newlineIndex;
 }
 }
 if (new String(text).substring(0, newlineIndex).trim().length() &#62; 0) {
 return 0;
 }
 // We look at the preceding elements on the line to see if we should
 // strip the opening newline and any whitespace preceding it.
 for (TemplateElement elem = this.prevTerminalNode(); elem != null
 &#38;&#38; elem.endLine == this.beginLine; elem = elem
 .prevTerminalNode()) {
 if (elem.heedsOpeningWhitespace()) {
 return 0;
 }
 }
 return newlineIndex;
 }

 /**
 * figures out how many trailing whitespace characters to strip in the
 * post-parse cleanup phase.
 */
 private int trailingCharsToStrip() {
 String content = new String(text);
 int lastNewlineIndex = lastNewLineIndex();
 if (lastNewlineIndex == -1 &#38;&#38; beginColumn != 1) {
 return 0;
 }
 String substring = content.substring(lastNewlineIndex + 1);
 if (substring.trim().length() &#62; 0) {
 return 0;
 }
 // We look at the elements afterward on the same line to see if we
 // should strip any whitespace after the last newline
 for (TemplateElement elem = this.nextTerminalNode(); elem != null
 &#38;&#38; elem.beginLine == this.endLine; elem = elem
 .nextTerminalNode()) {
 if (elem.heedsTrailingWhitespace()) {
 return 0;
 }
 }
 return substring.length();
 }

 boolean heedsTrailingWhitespace() {
 if (isIgnorable()) {
 return false;
 }
 for (int i = 0; i &#60; text.length; i++) {
 char c = text[i];
 if (c == '\n' &#124;&#124; c == '\r') {
 return false;
 }
 if (!Character.isWhitespace(c)) {
 return true;
 }
 }
 return true;
 }

 boolean heedsOpeningWhitespace() {
 if (isIgnorable()) {
 return false;
 }
 for (int i = text.length - 1; i &#62;= 0; i--) {
 char c = text[i];
 if (c == '\n' &#124;&#124; c == '\r') {
 return false;
 }
 if (!Character.isWhitespace(c)) {
 return true;
 }
 }
 return true;
 }

 boolean isIgnorable() {
 if (text == null &#124;&#124; text.length == 0) {
 return true;
 }
 if (!isWhitespace()) {
 return false;
 }
 // trick here
 boolean atTopLevel = true;
 TemplateElement prevSibling = previousSibling();
 TemplateElement nextSibling = nextSibling();
 return ((prevSibling == null &#38;&#38; atTopLevel) &#124;&#124; nonOutputtingType(prevSibling))
 &#38;&#38; ((nextSibling == null &#38;&#38; atTopLevel) &#124;&#124; nonOutputtingType(nextSibling));
 }

 private boolean nonOutputtingType(TemplateElement element) {
 return (element instanceof Macro &#124;&#124; element instanceof Assignment
 &#124;&#124; element instanceof AssignmentInstruction
 &#124;&#124; element instanceof PropertySetting
 &#124;&#124; element instanceof LibraryLoad &#124;&#124; element instanceof Comment);
 }

 private static char[] substring(char[] c, int from, int to) {
 char[] c2 = new char[to - from];
 System.arraycopy(c, from, c2, 0, c2.length);
 return c2;
 }

 private static char[] substring(char[] c, int from) {
 return substring(c, from, c.length);
 }

 private static char[] trim(char[] c) {
 if (c.length == 0) {
 return c;
 }
 return new String(c).trim().toCharArray();
 }

 private static char[] concat(char[] c1, char[] c2) {
 char[] c = new char[c1.length + c2.length];
 System.arraycopy(c1, 0, c, 0, c1.length);
 System.arraycopy(c2, 0, c, c1.length, c2.length);
 return c;
 }

 boolean isWhitespace() {
 return text == null &#124;&#124; trim(text).length == 0;
 }

}
</pre>
<p></span></span></p>
<ul>
<li>Next step is to create the LoginAction which will be do the business processing of whether usename and password are correct .</li>
</ul>
<pre class="brush: java;">
package com.login;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String username;
	private String password;

	public String login(){
		if(username.equals(&#34;whyjava&#34;) &#38;&#38; password.equals(&#34;password&#34;)){
			addActionMessage(&#34;You are successfully logged in.&#34;);
			return SUCCESS;
		}
		addActionError(&#34;Username and Password Combination doesnot match.&#34;);
		return INPUT;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
</pre>
<ul>
<li>Next we need to modify struts.xml so that we LoginAction is configured.</li>
</ul>
<pre class="brush: xml;">
&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34; ?&#62;
&#60;!DOCTYPE struts PUBLIC
&#34;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#34;
&#34;http://struts.apache.org/dtds/struts-2.0.dtd&#34;&#62;
&#60;struts&#62;
	&#60;include file=&#34;struts-default.xml&#34;&#62;&#60;/include&#62;
&#60;package name=&#34;member&#34; namespace=&#34;/member&#34; extends=&#34;struts-default&#34;&#62;
		&#60;action name=&#34;login&#34;&#62;
			&#60;result&#62;/login.jsp&#60;/result&#62;
		&#60;/action&#62;
		&#60;action name=&#34;home&#34; method=&#34;login&#34; class=&#34;com.login.LoginAction&#34;&#62;
			&#60;result&#62;/home.jsp&#60;/result&#62;
			&#60;result name=&#34;input&#34;&#62;/login.jsp&#60;/result&#62;
		&#60;/action&#62;
	&#60;/package&#62;
&#60;/struts&#62;
</pre>
<ul>
<li>finally we need to add one more jsp which is home.jsp which will be called when user is able to successfully login.</li>
</ul>
<pre class="brush: xml;">
&#60;%@ page language=&#34;java&#34; contentType=&#34;text/html; charset=ISO-8859-1&#34;
	pageEncoding=&#34;ISO-8859-1&#34;%&#62;
&#60;%@ taglib prefix=&#34;s&#34; uri=&#34;/struts-tags&#34;%&#62;
&#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD HTML 4.01 Transitional//EN&#34; &#34;http://www.w3.org/TR/html4/loose.dtd&#34;&#62;
&#60;html&#62;
&#60;head&#62;
&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=ISO-8859-1&#34;&#62;
&#60;title&#62;Home Page&#60;/title&#62;
&#60;/head&#62;
&#60;body&#62;
&#60;s:actionmessage /&#62;

&#60;/body&#62;
&#60;/html&#62;
</pre>
<ul>
<li>Now try running this application by right click on project run as &#62; web application and click <a href="http://localhost:8080/">http://localhost:8080</a>.</li>
</ul>
<p><img class="aligncenter size-large wp-image-48" title="index" src="http://whyjava.wordpress.com/files/2009/08/index1.jpg?w=1024" alt="index" width="1024" height="516" /></p>
<ul>
<li>Now click on the login link you will be taken to the login page</li>
</ul>
<p><img class="aligncenter size-large wp-image-49" title="login" src="http://whyjava.wordpress.com/files/2009/08/login.jpg?w=1024" alt="login" width="1024" height="506" /></p>
<ul>
<li>Now enter username as whyjava and password as password you will be an struts 2 action will fire and you will be taken to the home page.</li>
</ul>
<p><img class="aligncenter size-large wp-image-50" title="home" src="http://whyjava.wordpress.com/files/2009/08/home.jpg?w=1024" alt="home" width="1024" height="505" /></p>
<p>I have tried to cover all the steps you will need to start of your first struts 2 project. Hope you all find this post useful.</p>
<p>If you need to start learning struts2 you can read <a href="http://www.amazon.com/gp/product/193398807X?ie=UTF8&#38;tag=javblo07-20&#38;linkCode=as2&#38;camp=1789&#38;creative=9325&#38;creativeASIN=193398807X">Struts 2 in Action</a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=javblo07-20&#38;l=as2&#38;o=1&#38;a=193398807X" border="0" alt="" width="1" height="1" />. It is a very good book to get a very good understanding of all the struts 2 concepts.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[EJB 3.0 and Struts2]]></title>
<link>http://hlinski.wordpress.com/2009/08/24/ejb3-0struts2/</link>
<pubDate>Mon, 24 Aug 2009 16:06:00 +0000</pubDate>
<dc:creator>hlinski</dc:creator>
<guid>http://hlinski.wordpress.com/2009/08/24/ejb3-0struts2/</guid>
<description><![CDATA[Задался вопросом, каким образом EJB 3.0 уживаются с таким фрэймворком как Struts2. Насколько мне изв]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img class="aligncenter size-full wp-image-42" title="struts" src="http://hlinski.wordpress.com/files/2009/08/struts.jpg" alt="struts" width="302" height="161" />Задался вопросом, каким образом EJB 3.0 уживаются с таким фрэймворком как Struts2. Насколько мне известно, анатация @EJB работает только в объектах управляемых контейнером. Как же получить что-то подобное в struts action? Google Guice -один из ответов.  Это IoC легковесный контейнер от Google.  Вот не плохая  <a href="http://samolisov.blogspot.com/2008/04/guice-ioc-google.html" target="_blank">статья</a>.  Для примера использую Eclipse Galileo for J2EE и Geronimo 2.1.4 on Jetty. Для начала нужно установить плагин для Geronimo.</p>
<p style="text-align:center;"><img class="aligncenter size-medium wp-image-27" title="download GEP" src="http://hlinski.wordpress.com/files/2009/08/31.jpg?w=270" alt="download GEP" width="270" height="299" /></p>
<p style="text-align:center;">Нужны  следующие jar:</p>
<ul>
<li>commons-fileupload-1.2.1.jar</li>
<li>commons-logging-1.0.4.jar</li>
<li>freemarker-2.3.13.jar</li>
<li>ognl-2.6.11.jar</li>
<li>struts2-core-2.1.6.jar</li>
<li>xwork-2.1.2.jar</li>
<li>guice-struts2-plugin-1.0.1.jar</li>
<li>guice-1.0.jar</li>
<li>guice-servlet-1.0.jar</li>
</ul>
<p>Создаём EAR приложение, EJB проект и WEB проект:</p>
<p><img title="4" src="http://hlinski.wordpress.com/files/2009/08/41.jpg" alt="4" width="345" height="628" /></p>
<p>Создаём Stateless Session Bean и бизнесс интерфейсы, можно только Local</p>
<p><span style="text-decoration:underline;"><span style="font-size:x-small;"><img class="aligncenter size-full wp-image-41" title="Stateless Session Bean" src="http://hlinski.wordpress.com/files/2009/08/stateless-session-bean.jpg" alt="Stateless Session Bean" width="302" height="180" /></span></span></p>
<p><span style="font-size:x-small;">Создаём struts.xml</span></p>
<p>&#60;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243; ?&#62;<br />
&#60;!DOCTYPE struts PUBLIC<br />
&#8220;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&#8221;<br />
&#8220;http://struts.apache.org/dtds/struts-2.0.dtd&#8221;&#62;<br />
&#60;struts&#62;<br />
&#60;constant name=&#8221;struts.enable.DynamicMethodInvocation&#8221; value=&#8221;false&#8221; /&#62;<br />
&#60;constant name=&#8221;struts.devMode&#8221; value=&#8221;false&#8221; /&#62;</p>
<p>&#60;!&#8211; Use Guice as the ObjectFactory for this application &#8211;&#62;<br />
&#60;constant name=&#8221;struts.objectFactory&#8221; value=&#8221;guice&#8221; /&#62;<br />
&#60;!&#8211; When wiring actions use Guice bindings defined in the below module &#8211;&#62;<br />
&#60;constant name=&#8221;guice.module&#8221; value=&#8221;com.store.module.EJBModule&#8221;/&#62;</p>
<p>&#60;package name=&#8221;store&#8221; extends=&#8221;struts-default&#8221;&#62;<br />
&#60;action name=&#8221;saveItem&#8221;&#62;<br />
&#60;result&#62;/result.html&#60;/result&#62;<br />
&#60;/action&#62;<br />
&#60;!&#8211; Add more actions here &#8211;&#62;<br />
&#60;/package&#62;<br />
&#60;/struts&#62;</p>
<p><span style="font-size:x-small;"> </span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Solving the UI Framework Puzzle]]></title>
<link>http://winstond.wordpress.com/2009/08/19/solving-the-ui-framework-puzzle/</link>
<pubDate>Wed, 19 Aug 2009 14:02:49 +0000</pubDate>
<dc:creator>winstond</dc:creator>
<guid>http://winstond.wordpress.com/2009/08/19/solving-the-ui-framework-puzzle/</guid>
<description><![CDATA[I was recently tasked to recommend and specify components of a thin client architecture for a large ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="text-align:left;">I was recently tasked to recommend and specify components of a thin client architecture for a large web-based application (1000+ views!). It had to be Java-based, so the first obvious questions that sprung-up were -</p>
<p>  &#8211; What is best way to build such a large web aplication in Java ?&#8230;.which in turn can be  broken down into -  <br />
          - What are the best frameworks available in the world today that facilitate web-app development?&#8230;which in turn can be broken down into -<br />
                 &#8211; Which framework is most suitable in terms of technical, functional &#38; commercial criteria? &#8212; clearly each of these 3 criteria classes can further be exploded into detailed independant heirarchies.<br />
                 &#8211; Which framework will result in code/artifacts that are well-factored &#38; maintenable.<br />
                 &#8211; Which framework will support well-known <a href="http://designinginterfaces.com/About_Patterns">Usability patterns</a>.<br />
             <br />
       &#8211; What development methodology will be most suitable?&#8230;.which can further be broken down into -<br />
               - Which framework will guarantee high levels of productivity&#8230;which can further be broken down into -    <br />
                    - Which framework/tool(set) supports a clean separation of and smooth hand-offs of UI design &#38; coding concerns?&#8230;.which can further be broken down into -     <br />
                            &#8211; Which framework will allow parallelism of work-streams?     <br />
   <br />
So, simply put, one just needs to pick out the best &#8220;techno-functional-commercial&#8221; framework out there that also ensures that the application is delivered at an acceptable cost !</p>
<p>Sounds simple?&#8230;hmmm maybe yes, if one had to choose only from say 2 or 3 UI frameworks and, if it were year 2001 !<br />
Today if one scans the Internet for UI frameworks, the information found can be overwhelming and quite difficult to effectively navigate through. The UI framework puzzle as it were, also is a rather pertinent question, as seen from the number of google searches people have made on key words such as<br />
  - &#8220;ui frameworks comparison&#8221; &#8211; 5.19 million.<br />
  - &#8220;ui frameworks&#8221; &#8211; 5.8 million.<br />
  - &#8220;ui framework java&#8221; &#8211; 1.76 million.</p>
<p>So here&#8217;s a first hand account of an approach that can help one solve the UI framework puzzle. Mind you, there is no one single &#8220;best&#8221; solution; there&#8217;s only what is most suitable &#38; acceptable for a given need, with the (relative <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ) peace of mind that you have (wisely) considered and understood the rationale for all the choices you have made &#38; not made!</p>
<p>I use an age old principle of dealing with complexity/information overload &#8211; &#8220;Abstraction&#8221;.</p>
<p>To quote Wikipedia &#8211; &#8220;Abstraction is the process or result of generalization by reducing the information content of a concept or an observable phenomenon, typically to retain only information which is relevant for a particular purpose&#8221;.<br />
    <br />
Following this principle one can easily derive a few &#8220;UI Framework Abstractions&#8221; and start placing/sorting available frameworks/toolkits/technologies into these &#8220;Abstraction buckets&#8221;. So here goes..</p>
<p><strong>1. Web 1.0 Technologies (JavaScript, DOM, HTML &#38; CSS)</strong> <br />
These address client-side need only. This is essentially the pre-2004 way of building Web applications, featured by -<br />
 - Open standards<br />
 - No asynchronous calls and as a result &#8211; complete page refresh.<br />
  - No rich widget library.<br />
 - Requires a good server-side MVC framework as described in point 5 below.<br />
<strong>2. Lightweight Ajax Toolkits</strong><br />
Again, these address client-side need only. Ajax is not a technology in itself, rather a group of technologies such as HTML, CSS, Javascript, DOM, XML, JSON and a method for exchanging data asynchronously between browser and server, thereby avoiding complete page reloads. Key features of this framework type are:<br />
 <br />
 - Ajax applied correctly, increases Responsiveness of the application by avoiding complete page refreshes.<br />
 - It is based on open standards mentioned above.  <br />
 - It usually provides a rich widget library, and if not, may combine with other widget libraries.<br />
 - Screen developers code in HTML &#38; JavaScript with API support for widgets and data exchange via asynchronous server calls.<br />
 - Requires a good server-side MVC framework as described in point 5 below.</p>
<p>The popular ones are:<br />
 - Dojo<br />
 - Yahoo UI<br />
 - Ext-JS<br />
 - jQuery<br />
 - MooTools<br />
 - Prototype + Scriptaculous</p>
<p>  <br />
<strong>3. Java Component-based Ajax Toolkits</strong><br />
These address both Client &#38; Server side needs. These frameworks have essentially adapted the Java Swing or Eclipse SWT programming model to the Web. They differ from Lightweight Ajax Toolkit in that -</p>
<p> - The development language is Java. Developers need to code HTML, Javascript only in exceptional cases. <br />
 - The framework compiles screen layout &#38; behaviour code written in Java, to Javascript rendered by the browser.  <br />
 - Server-side application development is also framework driven. No need for a separate server-side MVC framework.<br />
 - It usually provides a rich widget library, and if not, may combine with other widget libraries.</p>
<p>The popular ones are:<br />
 - GWT (Ext)<br />
 - Ext-GWT<br />
 - Echo3<br />
 - Apache Wicket<br />
  <br />
 <br />
<strong>4. RIA Toolkits<br />
</strong>These address both Client &#38; Server side needs. These are complete Web application toolkits promoted by companies such as Adobe, Microsoft &#38; Sun. Their USP is rich internet applications using rapid development tools. Other key features are:<br />
 - It requires a runtime interpreter to be installed as a plug-in within each browser.<br />
 - It is usually based on custom scripting and layout languages and data exchange formats.<br />
 - Framework drives development of both client &#38; server-side application components. No need for separate MVC server-side framework.</p>
<p>The popular ones are:<br />
 - Flex (Cairngorm + BlazeDS)<br />
 - JavaFx<br />
 - Silverlight</p>
<p><strong>5. Server-side-only UI Frameworks</strong><br />
These address server-side need only. This is a basket of frameworks that not only aid the development of application components that accept and process a web request, but also aggregate and render page views back to the browser. They are meant to be used in conjunction with Lightweight Ajax Toolkits OR Web 1.0 Technologies.  The popular ones are:<br />
 - Struts2<br />
 - Spring MVC &#38; Webflow<br />
 - JSF<br />
 - Seam Framework<br />
 - Tapestry<br />
 - Stripes<br />
 <br />
 Some of the popular Scripting language based frameworks -<br />
 - Ruby On Rails<br />
 - Grails<br />
 </p>
<p><strong>5A. View Technology</strong><br />
Though this is essentially a Server-side framework/component and represents the &#8216;V&#8217; part of a MVC framework, it deserves a separate section of its own on account of the varied choices available in this area too. The key responsibility of View technology is to manage dynamic web content. This could involve say completely dynamic HTML generation or merge dynamic content with static HTML+Javascript.   </p>
<p>The popular View Technologies are:<br />
 - JSP (Java Server Pages) + JSTL  (JSP Standard Tag Library)<br />
 - Velocity &#38; Freemarker (Templating Engine)<br />
 - XSLT (Xml &#8211;&#62; Html)<br />
  <br />
<strong>5Aa.View Aggregation Technology</strong><br />
This is essentially a web-page layout and decoration framework that provides a consistent look and feel, navigation and layout scheme. It works on top of any of the View technologies mentioned in 5A.<br />
 - Site Mesh<br />
 - Tiles<br />
 <br />
This throws up a number of interesting combinations or styles from an architecture perspective. Some of the valid ones are:</p>
<p><strong>A. Traditional &#38; Conservative</strong> &#8211; (1) Web 1.0 tech +  (5) Server-side-only UI Frameworks      </p>
<p><strong>B. Modern yet Conservative</strong> &#8211; (2) Lightweight Ajax Toolkits + (5) Server-side-only UI Frameworks</p>
<p><strong>C. Modern &#38; Not-so-conservative</strong> &#8211; (3) Java Component-based Ajax Toolkits</p>
<p><strong>D. Modern &#38; Cutting-edge</strong> &#8211; (4) RIA Toolkits</p>
<p>So which one combination/style do I choose? Or can I make 2 choices? What are the trade-offs I need to be aware of when I make a choice? Will a particular style help acheive my GOAL (heirarchy)? Soul-searching questions, right? <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The level of abstraction that we are dealing in, can only help so far as to eliminate or put aside &#8220;Styles&#8221;, one is not &#8220;comfortable&#8221; with. For example:</p>
<p> - Style A is probably totally superceded by other styles and one really should look at modernizing with changing times.   </p>
<p> - Some of us may &#8220;feel&#8221;, Style C is actually a Leap-of-Faith &#8211; As a general practice, how can you expect me NOT to touch Javascript &#38; HTML, basically I don&#8217;t trust the Java-to-Javascript compiler well enough to handle all things that I have done all these years with DHTML. This may gravitate one to the slightly conservative Style B, though one would lose out on Style C&#8217;s BIG benefit of fine-grained componentization of UI element layout &#38; behaviour, coded in Java language itself. Debugging, re-factoring &#38; code maintenance is so much better with a strongly typed language like Java than Javascript and mind you, as a rough estimate, in a large enterprise business application, atleast 35% effort goes into UI layer development, and within that atleast 70% goes into screen layout and behaviour development.      <br />
 <br />
 - Some of us may not want to surrender to proprietory (licensed) IDE driven approach of Style D, since one would really need to use the IDE to reap the productivity benefits espoused by it. However, the richness in UI features offered by RIA Toolkits is much greater than that offered by any of the other Styles and that alone may favour Style D, especially if your competitor&#8217;s product already offers it.                   </p>
<p> - Style B is kind-of-a small evolutionary step forward, which I think most Enterprises would prefer for their back-office applications. It has many more moving parts than any of the other Styles and there are a number of sub-combinations possible within Style B itself. Still, it is the most robust on account of reliance on time-tested design patterns. A BIG issue that creeps up gradually especially in case of large applications is the &#8220;Javascript Mayhem&#8221;. Simply too much gets written and quickly becomes unweildy and unmanageble, duplication across number of screens and difficult to change, test &#38; refactor. All is not lost on this front though. Upfront thought and effort can be put to struture Javascript usage in a Object oriented fashion. Here are some links:<br />
            <a href="http://www.amazon.com/Object-Oriented-JavaScript-high-quality-applications-libraries/dp/1847194141">http://www.amazon.com/Object-Oriented-JavaScript-high-quality-applications-libraries/dp/1847194141</a><br />
            <a href="http://my.safaribooksonline.com/9781590599082">http://my.safaribooksonline.com/9781590599082</a><br />
            <a href="http://www.webreference.com/programming/javascript/ncz/column5/">http://www.webreference.com/programming/javascript/ncz/column5/</a><br />
            <a href="http://www.jsunit.net/">http://www.jsunit.net/</a><br />
                            <br />
So there we have it, a few architectural styles to choose from. There may be more, please do share your thoughts &#38; comments. Once you&#8217;ve chosen a style, the next step is the evaluation of frameworks within a Style say between Dojo &#38; YUI or Struts 2 &#38; Spring MVC or GWT &#38; Wicket. The internet is abound with such comparisons and one should back it up with PoCs of her own. Here are some links:</p>
<p><a href="http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks">http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks</a><br />
<a href="http://www.oreillynet.com/onjava/blog/2008/03/spring_mvc_javafx_google_web_t.html">http://www.oreillynet.com/onjava/blog/2008/03/spring_mvc_javafx_google_web_t.html</a></p>
<p style="text-align:center;">          xxx</p>
<p style="text-align:left;"><strong> </strong></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Framework MCV Para Java -Struts2]]></title>
<link>http://maikguerra.wordpress.com/2009/06/28/framework-mcv-para-java-struts2/</link>
<pubDate>Sun, 28 Jun 2009 19:55:38 +0000</pubDate>
<dc:creator>Maik Guerra</dc:creator>
<guid>http://maikguerra.wordpress.com/2009/06/28/framework-mcv-para-java-struts2/</guid>
<description><![CDATA[Struts 2 Los frameworks pueden ser vistos como implementaciones de patrones de diseño que facilitan ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><h1>Struts 2</h1>
<p>Los frameworks pueden ser vistos como implementaciones de patrones de diseño que facilitan la reutilización de diseño y código.</p>
<p>Apache Struts es una de estas frameworks</p>
<p>Creada por Craig McClanahan y donada a la Apache Software Foundation en el 2000 .</p>
<p>Provee librería de clases y TAG-LIBS que conforman el Controlador, la integración con el Modelo (o lógica de negocio) y facilitan la construcción de vistas.</p>
<p>Struts ofrece su propio componente controlador y proporciona integración con otras tecnologías para implementar el modelo, mediante tecnologías de acceso a datos como JDBC, y la vista, mediante JSP o XSLT. Además ofrece un sistema de tuberías que permite la comunicación entre el modelo que contiene los datos y las vistas que ofrecen estos datos a los usuarios y reciben sus órdenes.</p>
<p>Struts 2 está basado en el patrón MVC (Modelo-Vista-Controlador), una arquitectura que busca reducir el acoplamiento dividiendo las responsabilidades en 3 capas:</p>
<ul>
<li>El modelo, que hace referencia a los datos que maneja la aplicación y las reglas de negocio que operan sobre ellos. Se traducen en las Acciones.</li>
</ul>
<ul>
<li>La vista, encargada de generar la interfaz con la que la aplicación interacciona con el usuario. Equivale a los Resultados.</li>
</ul>
<ul>
<li>El controlador, que comunica la vista y el modelo respondiendo a eventos generados por el usuario en la vista, invocando cambios en el modelo, y devolviendo a la vista la información del modelo necesaria para que pueda generar la respuesta adecuada para el usuario. Se implementa mediante el filtro FilterDispatcher.</li>
</ul>
<p>Como Actúa el Framework Struts en una aplicacion Web</p>
<p><a href="http://asaes.files.wordpress.com/2009/06/imagen1.png"><img title="Imagen1" src="http://asaes.files.wordpress.com/2009/06/imagen1.png?w=360&#038;h=142#38;h=244" alt="Imagen1" width="360" height="142" /></a></p>
<p>En relacion con el Framework Sprin MVC, los dos tienden a tener las mismas formas de programarlo en la forma como lo veo.</p>
<p>Solo lo que cambian serian los metodos o sentencias de una a la otra.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Flex with Struts 2 with Source]]></title>
<link>http://niamathbasha.wordpress.com/2009/06/26/flex-with-struts-2-with-source/</link>
<pubDate>Fri, 26 Jun 2009 04:53:19 +0000</pubDate>
<dc:creator>niamathbasha</dc:creator>
<guid>http://niamathbasha.wordpress.com/2009/06/26/flex-with-struts-2-with-source/</guid>
<description><![CDATA[In my previous post (http://niamathbasha.wordpress.com/2008/09/01/configuring-struts-2-with-flex/) I]]></description>
<content:encoded><![CDATA[In my previous post (http://niamathbasha.wordpress.com/2008/09/01/configuring-struts-2-with-flex/) I]]></content:encoded>
</item>
<item>
<title><![CDATA[Struts2 File Upload]]></title>
<link>http://truongngh.wordpress.com/2009/06/25/struts2-file-upload/</link>
<pubDate>Thu, 25 Jun 2009 11:26:10 +0000</pubDate>
<dc:creator>truongngh</dc:creator>
<guid>http://truongngh.wordpress.com/2009/06/25/struts2-file-upload/</guid>
<description><![CDATA[The Struts 2 framework provides built-in support for processing file uploads that conform to RFC 186]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div>
<div>
<p>The Struts 2 framework provides built-in support for processing file uploads that conform to <span><a title="Visit page outside Confluence" rel="nofollow" href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867<sup><img src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" border="0" alt="" width="7" height="7" align="absmiddle" /></sup></a></span>, &#8220;Form-based File Upload in HTML&#8221;. When correctly configured the framework will pass uploaded file(s) into your Action class. Support for individual and multiple file uploads are provided. When a file is uploaded it will typically be stored in a temporary directory. Uploaded files should be processed or moved by your Action class to ensure the data is not lost. Be aware that servers may have a security policy in place that prohibits you from writing to directories other than the temporary directory and the directories that belong to your web application.</p>
<div>
<ul>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-Dependencies">Dependencies</a></li>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-BasicUsage">Basic Usage</a></li>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-UploadingMultipleFiles">Uploading Multiple Files</a>
<ul>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-UploadingMultipleFilesusingArrays">Uploading Multiple Files using Arrays</a></li>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-UploadingMultipleFilesusingLists">Uploading Multiple Files using Lists</a></li>
</ul>
</li>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-AdvancedConfiguration">Advanced Configuration</a>
<ul>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-FileSizeLimits">File Size Limits</a></li>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-FileTypes">File Types</a></li>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-ErrorMessages">Error Messages</a></li>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-TemporaryDirectories">Temporary Directories</a></li>
<li><a href="http://struts.apache.org/2.0.14/docs/file-upload.html#FileUpload-AlternateLibraries">Alternate Libraries</a></li>
</ul>
</li>
</ul>
</div>
<h2><a name="FileUpload-Dependencies"></a>Dependencies</h2>
<p>The Struts 2 framework leverages add-on libraries to handle the parsing of uploaded files. These libraries are not included in the Struts distribution, you must add them into your project. The libraries needed are:</p>
<table border="0">
<tbody>
<tr>
<th> Library</th>
<th> URL</th>
<th> Struts 2.0.x</th>
<th> Struts 2.1.x</th>
</tr>
<tr>
<td>Commons-FileUpload</td>
<td><span><a title="Visit page outside Confluence" rel="nofollow" href="http://commons.apache.org/fileupload/">http://commons.apache.org/fileupload/<sup><img src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" border="0" alt="" width="7" height="7" align="absmiddle" /></sup></a></span></td>
<td>1.1.1</td>
<td>1.2.1</td>
</tr>
<tr>
<td>Commons-IO</td>
<td><span><a title="Visit page outside Confluence" rel="nofollow" href="http://commons.apache.org/io/">http://commons.apache.org/io/<sup><img src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" border="0" alt="" width="7" height="7" align="absmiddle" /></sup></a></span></td>
<td>1.0</td>
<td>1.3.2</td>
</tr>
</tbody>
</table>
<p>If you are using Maven then you can add these libraries as dependencies in your project&#8217;s pom.xml.</p>
<div>
<div><strong>Struts 2.0.x File Upload Dependencies</strong></div>
<div>
<pre style="padding-left:30px;"><span>&#60;dependency&#62;</span><span>
    &#60;groupId&#62;</span>commons-fileupload<span>&#60;/groupId&#62;
</span><span>    &#60;artifactId&#62;</span>commons-fileupload<span>&#60;/artifactId&#62;
</span><span>    &#60;version&#62;</span>1.1.1<span>&#60;/version&#62;</span><span>
&#60;/dependency&#62;</span><span>
&#60;dependency&#62;
</span><span>    &#60;groupId&#62;</span>commons-io<span>&#60;/groupId&#62;</span>
<span>    &#60;artifactId&#62;</span>commons-io<span>&#60;/artifactId&#62;
</span><span>    &#60;version&#62;</span>1.0<span>&#60;/version&#62;
</span><span>&#60;/dependency&#62;</span></pre>
</div>
</div>
<div>
<div><strong>Struts 2.1.x File Upload Dependencies</strong></div>
<div>
<pre style="padding-left:30px;"><span>&#60;dependency&#62;</span><span>
    &#60;groupId&#62;</span>commons-fileupload<span>&#60;/groupId&#62;
    </span><span>&#60;artifactId&#62;</span>commons-fileupload<span>&#60;/artifactId&#62;
    </span><span>&#60;version&#62;</span>1.2.1<span>&#60;/version&#62;
</span><span>&#60;/dependency&#62;</span><span>
&#60;dependency&#62;</span>
    <span>&#60;groupId&#62;</span>commons-io<span>&#60;/groupId&#62;
    </span><span>&#60;artifactId&#62;</span>commons-io<span>&#60;/artifactId&#62;</span>
    <span>&#60;version&#62;</span>1.3.2<span>&#60;/version&#62;
</span><span>&#60;/dependency&#62;</span></pre>
</div>
</div>
<h2><a name="FileUpload-BasicUsage"></a>Basic Usage</h2>
<p>The <tt>org.apache.struts2.interceptor.FileUploadInterceptor</tt> class is included as part of the <tt>defaultStack</tt>. As long as the required libraries are added to your project you will be able to take advantage of of the Struts 2 fileUpload capability. Configure an Action mapping for your Action class as you typically would.</p>
<p><strong>Example action mapping:</strong></p>
<div>
<div>
<pre style="padding-left:30px;"><span>&#60;action name=<span>"doUpload"</span> class=<span>"com.example.UploadAction"</span>&#62;</span>
<span>    &#60;result name=<span>"success"</span>&#62;</span>good_result.jsp<span>&#60;/result&#62;</span><span>
&#60;/action&#62;</span></pre>
</div>
</div>
<p>A form must be create with a form field of type file, <tt>&#60;INPUT type="file" name="upload"&#62;</tt>. The form used to upload the file must have its encoding type set to multipart/form-data, <tt>&#60;FORM action="doUpload" enctype="multipart/form-data" method="post"&#62;</tt>. The standard procedure for adding these elements is by using the Struts 2 tag libraries as shown in the following example:</p>
<p><strong>Example JSP form tags:</strong></p>
<div>
<div>
<pre style="padding-left:30px;"><span>&#60;s:form action=<span>"doUpload"</span> method=<span>"post"</span> enctype=<span>"multipart/form-data"</span>&#62;</span>
<span>    &#60;s:file name=<span>"upload"</span> label=<span>"File"</span>/&#62;</span>
<span>&#60;s:submit/&#62;</span><span>&#60;/s:form&#62;</span></pre>
</div>
</div>
<p>The fileUpload interceptor will use setter injection to insert the uploaded file and related data into your Action class. For a form field named <strong>upload</strong> you would provide the three setter methods shown in the following example:</p>
<p><strong>Example Action class:</strong></p>
<div>
<div>
<pre style="padding-left:30px;"><span>package</span> com.example;
<span>import</span> java.io.File;   <span>import</span> com.opensymphony.xwork2.ActionSupport;

<span>public</span> UploadAction <span>extends</span> ActionSupport {
<span>    private</span> File file;
<span>    private</span> <span>String</span> contentType;
<span>    private</span> <span>String</span> filename;

      <span>public</span> void setUpload(File file) {         <span>this</span>.file = file;      }

      <span>public</span> void setUploadContentType(<span>String</span> contentType) {         <span>this</span>.contentType = contentType;      }

      <span>public</span> void setUploadFileName(<span>String</span> filename) {         <span>this</span>.filename = filename;      }

      <span>public</span> <span>String</span> execute() {         <span>//...</span>         <span>return</span> SUCCESS;      }
}</pre>
</div>
</div>
<p>The purpose of each one of these methods is described in the table below. Notice that if you have multiple file form elements with different names you would be required to have another corresponding set of these methods for each file uploaded.</p>
<table border="0">
<tbody>
<tr>
<th> Method Signature</th>
<th> Description</th>
</tr>
<tr>
<td>setX(File file)</td>
<td>The file that contains the content of the uploaded file. This is a temporary file and <tt>file.getName()</tt> will not return the original name of the file</td>
</tr>
<tr>
<td>setXContentType(String contentType)</td>
<td>The mime type of the uploaded file</td>
</tr>
<tr>
<td>setXFileName(String fileName)</td>
<td>The actual file name of the uploaded file (not the HTML name)</td>
</tr>
</tbody>
</table>
<h2><a name="FileUpload-UploadingMultipleFiles"></a>Uploading Multiple Files</h2>
<p>As mentioned in the previous section one technique for uploading multiple files would be to simply have multiple form input elements of type file all with different names. This would require a number of setter methods that was equal to 3 times the number of files being uploaded. Another option is to use Arrays or java.util.Lists. The following examples are taken from the Showcase example application that is part sample applications you can download at <span><a title="Visit page outside Confluence" rel="nofollow" href="http://struts.apache.org/download.cgi">http://struts.apache.org/download.cgi<sup><img src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" border="0" alt="" width="7" height="7" align="absmiddle" /></sup></a></span>. For the Action mapping details see <tt>struts-fileupload.xml</tt> in the sample application download.</p>
<h3><a name="FileUpload-UploadingMultipleFilesusingArrays"></a>Uploading Multiple Files using Arrays</h3>
<p><strong>multipleUploadUsingArray.jsp</strong> Notice all file input types have the same name.</p>
<div>
<div>
<pre style="padding-left:30px;">&#60;%@ page	language=<span>"java"</span>	contentType=<span>"text/html; charset=UTF-8"</span>    pageEncoding=<span>"UTF-8"</span>%&#62;<span>
&#60;%@ taglib prefix=<span>"s"</span> uri=<span>"/struts-tags"</span> %&#62;</span><span>
&#60;html&#62;</span><span>
&#60;head&#62;</span><span>
&#60;title&#62;</span>Showcase - fileupload - multiple fileupload using List<span>&#60;/title&#62;</span><span>
&#60;/head&#62;
</span><span>&#60;body&#62;</span>

<span>&#60;s:form action=<span>"doMultipleUploadUsingArray"</span> method=<span>"POST"</span> enctype=<span>"multipart/form-data"</span>&#62;</span>
<span>    &#60;s:file label=<span>"File (1)"</span> name=<span>"upload"</span> /&#62;</span>
<span>    &#60;s:file label=<span>"File (2)"</span> name=<span>"upload"</span> /&#62;</span>
<span>    &#60;s:file label=<span>"FIle (3)"</span> name=<span>"upload"</span> /&#62;</span>
<span>    &#60;s:submit /&#62;</span><span>
&#60;/s:form&#62;</span>

<span>&#60;/body&#62;</span><span>
&#60;/html&#62;</span></pre>
</div>
</div>
<p><strong>MultipleFileUploadUsingArrayAction.java</strong></p>
<div>
<div>
<pre style="padding-left:30px;"><span>package</span> org.apache.struts2.showcase.fileupload;

<span>import</span> java.io.File;

<span>import</span> com.opensymphony.xwork2.ActionSupport;

/** * Showcase action - mutiple file upload using array. * * @version $Date$ $Id$ */<span>public</span> class MultipleFileUploadUsingArrayAction <span>extends</span> ActionSupport {

    <span>private</span> File[] uploads;    <span>private</span> <span>String</span>[] uploadFileNames;    <span>private</span> <span>String</span>[] uploadContentTypes;

    <span>public</span> File[] getUpload() { <span>return</span> <span>this</span>.uploads; }    <span>public</span> void setUpload(File[] upload) { <span>this</span>.uploads = upload; }

    <span>public</span> <span>String</span>[] getUploadFileName() { <span>return</span> <span>this</span>.uploadFileNames; }
    <span>public</span> void setUploadFileName(<span>String</span>[] uploadFileName) { <span>this</span>.uploadFileNames = uploadFileName; }

    <span>public</span> <span>String</span>[] getUploadContentType() { <span>return</span> <span>this</span>.uploadContentTypes; }
    <span>public</span> void setUploadContentType(<span>String</span>[] uploadContentType) { <span>this</span>.uploadContentTypes = uploadContentType; }

    <span>public</span> <span>String</span> upload() <span>throws</span> Exception {
        <span>System</span>.out.println(<span>"\n\n upload2"</span>);
        <span>System</span>.out.println(<span>"files:"</span>);
 <span>       for</span> (File u: uploads) {<span>    System</span>.out.println(<span>"*** "</span>+u+<span>"\t"</span>+u.length());        }
        <span>System</span>.out.println(<span>"filenames:"</span>);
        <span>for</span> (<span>String</span> n: uploadFileNames) {    <span>System</span>.out.println(<span>"*** "</span>+n);        }
        <span>System</span>.out.println(<span>"content types:"</span>);
 <span>       for</span> (<span>String</span> c: uploadContentTypes) {    <span>System</span>.out.println(<span>"*** "</span>+c);        }
        <span>System</span>.out.println(<span>"\n\n"</span>);
        <span>return</span> SUCCESS;
    }
}</pre>
</div>
</div>
<h3><a name="FileUpload-UploadingMultipleFilesusingLists"></a>Uploading Multiple Files using Lists</h3>
<p><strong>multipleUploadUsingList.jsp</strong> Notice all file input types have the same name.</p>
<div>
<div>
<pre style="padding-left:30px;">&#60;%@ page	language=<span>"java"</span>	contentType=<span>"text/html; charset=UTF-8"</span>    pageEncoding=<span>"UTF-8"</span>%&#62;<span>
&#60;%@ taglib prefix=<span>"s"</span> uri=<span>"/struts-tags"</span> %&#62;</span><span>
&#60;html&#62;</span><span>
&#60;head&#62;
</span><span>&#60;title&#62;</span>Showcase - fileupload - multiple fileupload using List<span>&#60;/title&#62;
</span><span>&#60;/head&#62;</span><span>
&#60;body&#62;</span>

<span>&#60;s:form action=<span>"doMultipleUploadUsingList"</span> method=<span>"POST"</span> enctype=<span>"multipart/form-data"</span>&#62;</span>
<span>&#60;s:file label=<span>"File (1)"</span> name=<span>"upload"</span> /&#62;</span>
 <span>&#60;s:file label=<span>"File (2)"</span> name=<span>"upload"</span> /&#62;</span>
 <span>&#60;s:file label=<span>"FIle (3)"</span> name=<span>"upload"</span> /&#62;</span>
 <span>&#60;s:submit /&#62;
</span><span>&#60;/s:form&#62;</span>

<span>&#60;/body&#62;</span><span>
&#60;/html&#62;</span></pre>
</div>
</div>
<p><strong>MultipleFileUploadUsingListAction.java</strong></p>
<div>
<div>
<pre style="padding-left:30px;"><span>package</span> org.apache.struts2.showcase.fileupload;<span>import</span> java.io.File;<span>import</span> java.util.ArrayList;<span>import</span> java.util.List;

<span>import</span> com.opensymphony.xwork2.ActionSupport;

/** * Showcase action - multiple file upload using List
 * @version $Date$ $Id$
 */
<span>public</span> class MultipleFileUploadUsingListAction <span>extends</span> ActionSupport {

    <span>private</span> List&#60;File&#62; uploads = <span>new</span> ArrayList&#60;File&#62;();
    <span>private</span> List&#60;<span>String</span>&#62; uploadFileNames = <span>new</span> ArrayList&#60;<span>String</span>&#62;();
    <span>private</span> List&#60;<span>String</span>&#62; uploadContentTypes = <span>new</span> ArrayList&#60;<span>String</span>&#62;();

    <span>public</span> List&#60;File&#62; getUpload() {        <span>return</span> <span>this</span>.uploads;    }
    <span>public</span> void setUpload(List&#60;File&#62; uploads) {        <span>this</span>.uploads = uploads;    }

    <span>public</span> List&#60;<span>String</span>&#62; getUploadFileName() {        <span>return</span> <span>this</span>.uploadFileNames;    }
    <span>public</span> void setUploadFileName(List&#60;<span>String</span>&#62; uploadFileNames) {        <span>this</span>.uploadFileNames = uploadFileNames;    }

    <span>public</span> List&#60;<span>String</span>&#62; getUploadContentType() {        <span>return</span> <span>this</span>.uploadContentTypes;    }
    <span>public</span> void setUploadContentType(List&#60;<span>String</span>&#62; contentTypes) {        <span>this</span>.uploadContentTypes = contentTypes;    }

    <span>public</span> <span>String</span> upload() <span>throws</span> Exception {

        <span>System</span>.out.println(<span>"\n\n upload1"</span>);
        <span>System</span>.out.println(<span>"files:"</span>);
        <span>for</span> (File u: uploads) {            <span>System</span>.out.println(<span>"*** "</span>+u+<span>"\t"</span>+u.length());        }
        <span>System</span>.out.println(<span>"filenames:"</span>);
        <span>for</span> (<span>String</span> n: uploadFileNames) {            <span>System</span>.out.println(<span>"*** "</span>+n);        }
        <span>System</span>.out.println(<span>"content types:"</span>);
        <span>for</span> (<span>String</span> c: uploadContentTypes) {            <span>System</span>.out.println(<span>"*** "</span>+c);        }
        <span>System</span>.out.println(<span>"\n\n"</span>);        <span>return</span> SUCCESS;
    }
}</pre>
</div>
</div>
<h2><a name="FileUpload-AdvancedConfiguration"></a>Advanced Configuration</h2>
<p>The Struts 2 <tt>default.properties</tt> file defines several settings that affect the behavior of file uploading. You may find in necessary to change these values. The names and default values are:</p>
<div>
<div>
<pre style="padding-left:30px;">struts.multipart.parser=jakarta
struts.multipart.saveDir=
<strong>struts.multipart.maxSize=2097152</strong></pre>
</div>
</div>
<p>In order to change theses settings you define a constant in your applications <tt>struts.xml</tt> file like so:</p>
<div>
<div>
<pre style="padding-left:30px;"><span>&#60;?xml version=<span>"1.0"</span> encoding=<span>"UTF-8"</span>?&#62;</span>
&#60;!DOCTYPE struts PUBLIC<span> "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"</span>
                        <span>"http://struts.apache.org/dtds/struts-2.0.dtd"</span>&#62;
<span>&#60;struts&#62;</span>
 <span>    <strong>&#60;constant name=<span>"struts.multipart.maxSize"</span> value=<span>"1000000"</span> /&#62;</strong></span>
 ...
<span>&#60;/struts&#62;</span></pre>
</div>
</div>
<p>Additionally the <tt>fileUpload</tt> interceptor has settings that can be put in place for individual action mappings by customizing your interceptor stack.</p>
<div>
<div>
<pre style="padding-left:30px;"><span>&#60;action name=<span>"doUpload"</span> class=<span>"com.example.UploadAction"</span>&#62;
</span> <span>   &#60;interceptor-ref name=<span>"basicStack"</span>/&#62;
</span> <span>   <strong>&#60;interceptor-ref name=<span>"fileUpload"</span>&#62;</strong></span><strong>
        <span>&#60;param name=<span>"allowedTypes"</span>&#62;</span>text/plain<span>&#60;/param&#62;</span>
    </strong><span><strong>&#60;/interceptor-ref&#62;</strong>
</span>    <span>&#60;interceptor-ref name=<span>"validation"</span>/&#62;</span>
    <span>&#60;interceptor-ref name=<span>"workflow"</span>/&#62;</span>

    <span>&#60;result name=<span>"success"</span>&#62;</span>good_result.jsp<span>&#60;/result&#62;
</span><span>&#60;/action&#62;</span></pre>
</div>
</div>
<h3><a name="FileUpload-FileSizeLimits"></a>File Size Limits</h3>
<p>There are two separate file size limits. First is <tt>struts.multipart.maxSize</tt> which comes from the Struts 2 <tt>default.properties</tt> file. This setting exists for security reasons to prohibit a malicious user from uploading extremely large files to file up your servers disk space. This setting defaults to approximately 2 megabytes and should be adjusted to the maximum size file (2 gigs max) that your will need the framework to receive. If you are uploading more than one file on a form the <tt>struts.multipart.maxSize</tt> applies to the combined total, not the individual file sizes. The other setting, <tt>maximumSize</tt>, is an interceptor setting that is used to ensure a particular Action does not receive a file that is too large. Notice the locations of both settings in the following example:</p>
<div>
<div>
<pre style="padding-left:30px;"><span>&#60;?xml version=<span>"1.0"</span> encoding=<span>"UTF-8"</span>?&#62;
</span>&#60;!DOCTYPE struts PUBLIC	<span>"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"</span>
                        <span>"http://struts.apache.org/dtds/struts-2.0.dtd"</span>&#62;<span>
&#60;struts&#62;</span>
<span>    &#60;constant name=<span>"struts.multipart.maxSize"</span> value=<span>"1000000"</span> /&#62;</span>

<span>    &#60;action name=<span>"doUpload"</span> class=<span>"com.example.UploadAction"</span>&#62;
</span>        <span>&#60;interceptor-ref name=<span>"basicStack"</span>/&#62;</span>
 <span>       <strong>&#60;interceptor-ref name=<span>"fileUpload"</span>&#62;
</strong></span><strong>            <span>&#60;param name=<span>"maximumSize"</span>&#62;</span>500000<span>&#60;/param&#62;
</span> </strong><span><strong>       &#60;/interceptor-ref&#62;</strong>
</span>        <span>&#60;interceptor-ref name=<span>"validation"</span>/&#62;
</span> <span>       &#60;interceptor-ref name=<span>"workflow"</span>/&#62;</span>

<span>        &#60;result name=<span>"success"</span>&#62;</span>good_result.jsp<span>&#60;/result&#62;</span>
<span>    &#60;/action&#62;
</span><span>&#60;/struts&#62;</span></pre>
</div>
</div>
<h3><a name="FileUpload-FileTypes"></a>File Types</h3>
<p>There are two ways to limit the uploaded file type, declaratively and programmatically. To declaratively limit the file type a comma separated list of allowedTypes can be specified as a fileUpload interceptor param as shown in the following example:</p>
<div>
<div>
<pre style="padding-left:30px;"><span>&#60;action name=<span>"doUpload"</span> class=<span>"com.example.UploadAction"</span>&#62;</span>
    <span>&#60;interceptor-ref name=<span>"basicStack"</span>/&#62;
</span>    <strong><span>&#60;interceptor-ref name=<span>"fileUpload"</span>&#62;</span>
        <span>&#60;param name=<span>"allowedTypes"</span>&#62;</span>image/jpeg,image/gif<span>&#60;/param&#62;
</span>    </strong><span><strong>&#60;/interceptor-ref&#62;</strong>
</span>    <span>&#60;interceptor-ref name=<span>"validation"</span>/&#62;
</span> <span>   &#60;interceptor-ref name=<span>"workflow"</span>/&#62;</span>

    <span>&#60;result name=<span>"success"</span>&#62;</span>good_result.jsp<span>&#60;/result&#62;
</span><span>&#60;/action&#62;</span></pre>
</div>
</div>
<p>When the uploaded file type does not match one of the MIME types specified a field error will be created as described in the next section entitled Error Messages. Programmatically limiting the file type means using the information passed in to your Action class via the <tt>setXContentType(String contentType)</tt> method. The benefit to this type of approach would be that it&#8217;s more flexible and no interceptor configuration would be needed if file sizes are keep under 2 megs.</p>
<h3><a name="FileUpload-ErrorMessages"></a>Error Messages</h3>
<p>If an error occurs several field errors will be added assuming that the action implements <tt>com.opensymphony.xwork2.ValidationAware</tt> or extends <tt>com.opensymphony.xwork2.ActionSupport</tt>. These error messages are based on several i18n values stored in struts-messages.properties, a default i18n file processed for all i18n requests. You can override the text of these messages by providing text for the following keys:</p>
<table border="0">
<tbody>
<tr>
<th> Error Key</th>
<th> Description</th>
</tr>
<tr>
<td>struts.messages.error.uploading</td>
<td>A general error that occurs when the file could not be uploaded</td>
</tr>
<tr>
<td>struts.messages.error.file.too.large</td>
<td>Occurs when the uploaded file is too large as specified by maximumSize.</td>
</tr>
<tr>
<td>struts.messages.error.content.type.not.allowed</td>
<td>Occurs when the uploaded file does not match the expected content types specified</td>
</tr>
</tbody>
</table>
<h3><a name="FileUpload-TemporaryDirectories"></a>Temporary Directories</h3>
<p>All uploaded files are saved to a temporary directory by the framework before being passed in to an Action. Depending on the allowed file sizes it may be necessary to have the framework store these temporary files in an alternate location. To do this change <tt>struts.multipart.saveDir</tt> to the directory where the uploaded files will be placed. If this property is not set it defaults to <tt>javax.servlet.context.tempdir</tt>. Keep in mind that on some operating systems, like Solaris, <tt>/tmp</tt> is memory based and files stored in that directory would consume an amount of RAM approximately equal to the size of the uploaded file.</p>
<h3><a name="FileUpload-AlternateLibraries"></a>Alternate Libraries</h3>
<p>The <tt>struts.multipart.parser</tt> used by the fileUpload interceptor to handle HTTP POST requests, encoded using the MIME-type multipart/form-data, can be changed out. Currently there are two choices, jakarta and pell. The jakarta parser is a standard part of the Struts 2 framework needing only its required libraries added to a project. The pell parser uses Jason Pell&#8217;s multipart parser instead of the Commons-FileUpload library. The pell parser is a Struts 2 plugin, for more details see: <span><a title="Visit page outside Confluence" rel="nofollow" href="http://cwiki.apache.org/S2PLUGINS/pell-multipart-plugin.html">http://cwiki.apache.org/S2PLUGINS/pell-multipart-plugin.html<sup><img src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" border="0" alt="" width="7" height="7" align="absmiddle" /></sup></a></span>. There was a third alternative, cos, but it was removed due to licensing incompatibilities.</p>
<p>Source: <a href="http://struts.apache.org/2.0.14/docs/file-upload.html">http://struts.apache.org/2.0.14/docs/file-upload.html</a></div>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Struts 2 File Upload]]></title>
<link>http://truongngh.wordpress.com/2009/06/15/struts-2-file-upload/</link>
<pubDate>Mon, 15 Jun 2009 07:09:09 +0000</pubDate>
<dc:creator>truongngh</dc:creator>
<guid>http://truongngh.wordpress.com/2009/06/15/struts-2-file-upload/</guid>
<description><![CDATA[In this section you will learn how to write program in Struts 2 to upload the file on the server. In]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><span style="color:#000080;">In this section you will learn how to write program in Struts 2 to upload the file on the server. In this example we are also providing the code to save the uploaded file in any directory on the server machine.</span></p>
<p><span style="color:#000080;">The Struts 2 FileUpload component can be used to upload the multipart file in your Struts 2 application. In this section you will learn about the code to upload file on the server.</span></p>
<p><span style="color:#000080;"><strong>How File Upload Works in Struts 2?</strong></span></p>
<p><span style="color:#000080;">Struts 2 utilizes the service of  <strong>File Upload Interceptor</strong> to add the support for uploading files in the Struts applications. The Struts 2 File Upload Interceptor is based on MultiPartRequestWrapper, which is automatically applied to the request if it contains the file element. Then it adds the following parameters to the request (assuming the uploaded file name is MyFile). </span></p>
<ul>
<li><span style="color:#000080;">[<strong>MyFile</strong>] : File &#8211; the actual File</span></li>
<li><span style="color:#000080;">[<strong>MyFile</strong>]<strong>ContentType</strong> : String &#8211; the content type of the file</span></li>
<li><span style="color:#000080;">[<strong>File Name</strong>]<strong>FileName</strong> : String &#8211; the actual name of the file uploaded (not the HTML name)</span></li>
</ul>
<p><span style="color:#000080;">In the action class you can get the file, the uploaded file name and content type by just creating getter and setters. For example, setMyfile(File file), setMyFileContentType(String contentType), getMyFile(), etc..</span></p>
<div>//<br />
	// <ins><ins></ins></ins></div>
<p><span style="color:#000080;">The file upload interceptor also does the validation and adds errors, these error messages are stored in the struts-messsages.properties file. The values of the messages can be overridden by providing the text for the following keys:</span></p>
<ul>
<li><span style="color:#000080;"><strong>struts.messages.error.uploading</strong> &#8211; error when uploading     of file fails<br />
</span></li>
<li><span style="color:#000080;"><strong>struts.messages.error.file.too.large</strong> &#8211; error     occurs when file size is large<br />
</span></li>
<li><span style="color:#000080;"><strong>struts.messages.error.content.type.not.allowed</strong> &#8211;     when the content type is not allowed<br />
</span></li>
</ul>
<p><span style="color:#000080;"><strong>Parameters</strong></p>
<p>You can use the following parameters to control the file upload functionality.</span></p>
<ul>
<li><span style="color:#000080;"><strong>maximumSize</strong> This parameter is optional. The     default value of this is 2MB.<br />
</span></li>
<li><span style="color:#000080;"><strong>allowedTypes</strong> This parameter is also optional.     It allows you to specify the allowed content type.</span></li>
</ul>
<p><span style="color:#000080;"><strong>Writing Example code to upload file</strong></span></p>
<p><span style="color:#000080;">Now we will write the code to upload the file on server.</span></p>
<p><span style="color:#000080;"><strong>Action Class</strong></span></p>
<p><span style="color:#000080;">In the action class we will define four properties to facilitate the file upload.</span></p>
<p><span style="font-size:x-small;"> </span></p>
<p align="left"><strong><span style="color:#7f0055;font-size:x-small;">private</span></strong><span style="font-size:x-small;"> File </span><span style="color:#0000c0;font-size:x-small;">upload</span><span style="font-size:x-small;">; // The actual file</span></p>
<p align="left"><strong><span style="color:#7f0055;font-size:x-small;">private</span></strong><span style="font-size:x-small;"> String </span><span style="color:#0000c0;font-size:x-small;">uploadContentType</span><span style="font-size:x-small;">;// The content type of the file</span></p>
<p align="left"><strong><span style="color:#7f0055;font-size:x-small;">private</span></strong><span style="font-size:x-small;"> String </span><span style="color:#0000c0;font-size:x-small;">uploadFileName</span><span style="font-size:x-small;">;// The uploaded file name and path</span></p>
<p><strong><span style="color:#7f0055;font-size:x-small;">private</span></strong><span style="font-size:x-small;"> String </span><span style="color:#0000c0;font-size:x-small;">fileCaption</span><span style="font-size:x-small;">;// The caption of the file entered by user.</span></p>
<p><span style="color:#000080;">Here is the full code of action class StrutsFileUpload.java</span></p>
<div>
<table border="1" cellspacing="0" cellpadding="3" bgcolor="#ffffcc">
<tbody>
<tr><!-- start source code --></p>
<td align="left" valign="top"><code> <span style="color:#7f0055;"><strong>package </strong></span><span style="color:#000000;">net.roseindia;</span><br />
<span style="color:#7f0055;"><strong>import </strong></span><span style="color:#000000;">java.util.Date;</span><br />
<span style="color:#7f0055;"><strong>import </strong></span><span style="color:#000000;">java.io.File;</span><br />
<span style="color:#7f0055;"><strong>import </strong></span><span style="color:#000000;">com.opensymphony.xwork2.ActionSupport;</span><br />
<span style="color:#7f0055;"><strong>public class </strong></span><span style="color:#000000;">StrutsFileUpload </span><span style="color:#7f0055;"><strong>extends </strong></span><span style="color:#000000;">ActionSupport </span><span style="color:#000000;">{</span><br />
<span style="color:#ffffff;"> </span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>private </strong></span><span style="color:#000000;">File upload;</span><span style="color:#3f7f5f;">//The actual file</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>private </strong></span><span style="color:#000000;">String uploadContentType; </span><span style="color:#3f7f5f;">//The content type of the file</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>private </strong></span><span style="color:#000000;">String uploadFileName; </span><span style="color:#3f7f5f;">//The uploaded file name</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>private </strong></span><span style="color:#000000;">String fileCaption;</span><span style="color:#3f7f5f;">//The caption of the file entered by user</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>public </strong></span><span style="color:#000000;">String execute</span><span style="color:#000000;">() </span><span style="color:#7f0055;"><strong>throws </strong></span><span style="color:#000000;">Exception </span><span style="color:#000000;">{</span></p>
<p><span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>return </strong></span><span style="color:#000000;">SUCCESS;</span></p>
<p><span style="color:#ffffff;"> </span><span style="color:#000000;">}</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>public </strong></span><span style="color:#000000;">String getFileCaption</span><span style="color:#000000;">() {</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>return </strong></span><span style="color:#000000;">fileCaption;</span><br />
<span style="color:#ffffff;"> </span><span style="color:#000000;">}</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>public </strong></span><span style="color:#7f0055;"><strong>void </strong></span><span style="color:#000000;">setFileCaption</span><span style="color:#000000;">(</span><span style="color:#000000;">String fileCaption</span><span style="color:#000000;">) {</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>this</strong></span><span style="color:#000000;">.fileCaption = fileCaption;</span><br />
<span style="color:#ffffff;"> </span><span style="color:#000000;">}</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>public </strong></span><span style="color:#000000;">File getUpload</span><span style="color:#000000;">() {</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>return </strong></span><span style="color:#000000;">upload;</span><br />
<span style="color:#ffffff;"> </span><span style="color:#000000;">}</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>public </strong></span><span style="color:#7f0055;"><strong>void </strong></span><span style="color:#000000;">setUpload</span><span style="color:#000000;">(</span><span style="color:#000000;">File upload</span><span style="color:#000000;">) {</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>this</strong></span><span style="color:#000000;">.upload = upload;</span><br />
<span style="color:#ffffff;"> </span><span style="color:#000000;">}</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>public </strong></span><span style="color:#000000;">String getUploadContentType</span><span style="color:#000000;">() {</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>return </strong></span><span style="color:#000000;">uploadContentType;</span><br />
<span style="color:#ffffff;"> </span><span style="color:#000000;">}</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>public </strong></span><span style="color:#7f0055;"><strong>void </strong></span><span style="color:#000000;">setUploadContentType</span><span style="color:#000000;">(</span><span style="color:#000000;">String uploadContentType</span><span style="color:#000000;">) {</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>this</strong></span><span style="color:#000000;">.uploadContentType = uploadContentType;</span><br />
<span style="color:#ffffff;"> </span><span style="color:#000000;">}</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>public </strong></span><span style="color:#000000;">String getUploadFileName</span><span style="color:#000000;">() {</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>return </strong></span><span style="color:#000000;">uploadFileName;</span><br />
<span style="color:#ffffff;"> </span><span style="color:#000000;">}</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>public </strong></span><span style="color:#7f0055;"><strong>void </strong></span><span style="color:#000000;">setUploadFileName</span><span style="color:#000000;">(</span><span style="color:#000000;">String uploadFileName</span><span style="color:#000000;">) {</span><br />
<span style="color:#ffffff;"> </span><span style="color:#7f0055;"><strong>this</strong></span><span style="color:#000000;">.uploadFileName = uploadFileName;</span><br />
<span style="color:#ffffff;"> </span><span style="color:#000000;">}</span></p>
<p><span style="color:#ffffff;"> </span><br />
<span style="color:#000000;">}</span></code></td>
<p><!-- end source code --></tr>
</tbody>
</table>
</div>
<p><span style="color:#000080;"><br />
Here we have not shown the code to save the uploaded file. But it can be done easily using the following code in execute(..) method of action class. Here is code snippet.</span><span style="font-size:x-small;"> </span></p>
<p align="left"><span style="color:#3f7f5f;font-size:x-small;">//Following code can be used to save the uploaded file</span></p>
<p><span style="font-size:x-small;"> </span></p>
<p align="left"><strong><span style="color:#7f0055;font-size:x-small;">try</span></strong><span style="font-size:x-small;"> {</span></p>
<p align="left"><span style="font-size:x-small;">String fullFileName = </span><span style="color:#2a00ff;font-size:x-small;">&#8220;c:/upload/myfile.txt&#8221;</span><span style="font-size:x-small;">;</span></p>
<p align="left"><span style="font-size:x-small;">File theFile = </span><strong><span style="color:#7f0055;font-size:x-small;">new</span></strong><span style="font-size:x-small;"> File(fullFileName);</span></p>
<p align="left"><span style="font-size:x-small;">FileUtils.copyFile(</span><span style="color:#0000c0;font-size:x-small;">upload</span><span style="font-size:x-small;">, theFile);</span></p>
<p align="left"><span style="font-size:x-small;">} </span><strong><span style="color:#7f0055;font-size:x-small;">catch</span></strong><span style="font-size:x-small;"> (Exception e) {</span></p>
<p align="left"><span style="font-size:x-small;">addActionError(e.getMessage());</span></p>
<p align="left"><strong><span style="color:#7f0055;font-size:x-small;">return</span></strong><span style="font-size:x-small;"> </span><em><span style="color:#0000c0;font-size:x-small;">INPUT</span></em><span style="font-size:x-small;">;</span></p>
<p align="left"><span style="font-size:x-small;">}</span></p>
<p><span style="color:#000080;"><strong>Writing JSP page</strong></span></p>
<p><span style="color:#000080;">Here is the code of jsp file (<strong>upload.jsp</strong>) that displays the file upload form to the user.</span></p>
<div>
<table border="1" cellspacing="0" cellpadding="0" width="530" bgcolor="#ffffcc">
<tbody>
<tr>
<td width="528">&#60;%@ taglib prefix=&#8221;s&#8221; uri=&#8221;/struts-tags&#8221; %&#62;<br />
&#60;html&#62;<br />
&#60;head&#62;<br />
&#60;title&#62;File Upload Example&#60;/title&#62;<br />
&#60;link href=&#8221;&#60;s:url value=&#8221;/css/main.css&#8221;/&#62;&#8221; rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221;/&#62;</p>
<p>&#60;/head&#62;</p>
<p>&#60;body&#62;</p>
<p>&#60;s:actionerror /&#62;<br />
&#60;s:fielderror /&#62;<br />
&#60;s:form action=&#8221;doUpload&#8221; method=&#8221;POST&#8221; enctype=&#8221;<strong>multipart/form-data</strong>&#8220;&#62;<br />
&#60;tr&#62;<br />
&#60;td colspan=&#8221;2&#8243;&#62;&#60;h1&#62;File Upload Example&#60;/h1&#62;&#60;/td&#62;<br />
&#60;/tr&#62;</p>
<p><strong> &#60;s:file name=&#8221;upload&#8221; label=&#8221;File&#8221;/&#62;</strong><br />
&#60;s:textfield name=&#8221;caption&#8221; label=&#8221;Caption&#8221;/&#62;<br />
&#60;s:submit /&#62;<br />
&#60;/s:form&#62;<br />
&#60;/body&#62;<br />
&#60;/html&#62;</td>
</tr>
</tbody>
</table>
</div>
<p><span style="color:#000080;">In the above code the form encrypt type is &#8220;<strong>multipart/form-data</strong>&#8221; and &#60;s:file ../&#62; tag renders the html file tag.</span></p>
<p><span style="color:#000080;"><strong>File upload success page</strong></span></p>
<p><span style="color:#000080;">Here is the code of file upload(upload-success.jsp) success page.</span></p>
<div>
<table border="1" cellspacing="0" cellpadding="0" width="576" bgcolor="#ffffcc">
<tbody>
<tr>
<td width="574">&#60;%@ page<br />
language=&#8221;java&#8221;<br />
contentType=&#8221;text/html; charset=UTF-8&#8243;<br />
pageEncoding=&#8221;UTF-8&#8243;%&#62;<br />
&#60;%@ taglib prefix=&#8221;s&#8221; uri=&#8221;/struts-tags&#8221; %&#62;<br />
&#60;html&#62;<br />
&#60;head&#62;<br />
&#60;title&#62;Showcase&#60;/title&#62;<br />
&#60;link href=&#8221;&#60;s:url value=&#8221;/css/main.css&#8221;/&#62;&#8221; rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221;/&#62;<br />
&#60;/head&#62;</p>
<p>&#60;body&#62;<br />
&#60;table&#62;<br />
&#60;tr&#62;</p>
<p>&#60;td colspan=&#8221;2&#8243;&#62;&#60;h1&#62;File Upload Example&#60;/h1&#62;&#60;/td&#62;<br />
&#60;/tr&#62;</p>
<p>&#60;tr&#62;<br />
&#60;td&#62;&#60;label for=&#8221;doUpload_upload&#8221;&#62;Content Type:&#60;/label&#62;&#60;/td&#62;<br />
&#60;td&#62;<strong>&#60;s:property value=&#8221;uploadContentType&#8221; /&#62;</strong>&#60;/td&#62;<br />
&#60;/tr&#62;</p>
<p>&#60;tr&#62;<br />
&#60;td&#62;&#60;label for=&#8221;doUpload_upload&#8221;&#62;File Name:&#60;/label&#62;&#60;/td&#62;<br />
&#60;td &#62;<strong>&#60;s:property value=&#8221;uploadFileName&#8221; /&#62;</strong>&#60;/td&#62;<br />
&#60;/tr&#62;</p>
<p>&#60;tr&#62;<br />
&#60;td&#62;&#60;label for=&#8221;doUpload_upload&#8221;&#62;File:&#60;/label&#62;&#60;/td&#62;<br />
&#60;td&#62;<strong>&#60;s:property value=&#8221;upload&#8221; /&#62;</strong>&#60;/td&#62;<br />
&#60;/tr&#62;</p>
<p>&#60;tr&#62;<br />
&#60;td&#62;&#60;label for=&#8221;doUpload_upload&#8221;&#62;File Caption:&#60;/label&#62;&#60;/td&#62;<br />
&#60;td&#62;<strong>&#60;s:property value=&#8221;caption&#8221; /&#62;</strong>&#60;/td&#62;<br />
&#60;/tr&#62;</p>
<p>&#60;/table&#62;</p>
<p>&#60;/body&#62;<br />
&#60;/html&#62;</td>
</tr>
</tbody>
</table>
</div>
<p><span style="color:#000080;"><strong>Adding mapping in struts.xml file</strong></span></p>
<p><span style="color:#000080;">Add the following mapping in the struts.xml file.</span></p>
<p><span style="color:#0000ff;"> &#60;!&#8211; File Upload &#8211;&#62;</p>
<p>&#60;action name=&#8221;showUpload&#8221;&#62;<br />
&#60;result&#62;/pages/upload.jsp&#60;/result&#62;<br />
&#60;/action&#62;</p>
<p>&#60;action name=&#8221;doUpload&#8221;&#62;<br />
&#60;result name=&#8221;input&#8221;&#62;/pages/upload.jsp&#60;/result&#62;<br />
&#60;result&#62;/pages/upload-success.jsp&#60;/result&#62;<br />
&#60;/action&#62;</p>
<p>&#60;!&#8211; End File Upload &#8211;&#62;</span></p>
<p><span style="color:#000080;">The &#8220;showUpload&#8221; action displays the upload form and &#8220;doUpload&#8221; action actually uploads the file.</span></p>
<p><span style="color:#000080;"><strong>Running the example</strong></span></p>
<p><span style="color:#000080;">To test the application compile code and then run the tomcat. Type <a href="http://localhost:8080/struts2tutorial/roseindia/showUpload.action">http://localhost:8080/struts2tutorial/roseindia/showUpload.action</a> in your browser. You browser should show the following form:</span></p>
<p><img src="http://www.roseindia.net/struts/struts2/struts2fileupload.gif" alt="" /></p>
<p><span style="color:#000080;">Now browse the file, enter caption and then click on the &#8220;Submit&#8221; button. Application will upload your file and then following success screen will be displayed.</span></p>
<p><img src="http://www.roseindia.net/struts/struts2/struts2fileuploadsuccess.gif" alt="" /></p>
<p><span style="color:#000080;">There is one important point to be noted about File Upload Interceptor. The File Upload Interceptor actually deletes the the upload, once the action is executed. Here is the screen shot of tomcat that shows the file delete message:</span></p>
<p><span style="color:#0000ff;">INFO: Removing file upload C:\apache-tomcat-6.0.10Struts2\apache-tomcat-6.0.10\work\Catalina\<br />
localhost\struts2tutorial\upload__13f532f7_1132e1d4754__8000_00000000.tmp</span></p>
<p><span style="color:#000080;">In this section you learnt the concept of file upload in struts 2.</span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Java Persistence API In EJB 3 For Professionals - Covers EJB 3.1 using GlassFish v3 Prelude]]></title>
<link>http://sharanamshah.wordpress.com/2009/06/03/java-persistence-api-in-ejb-3-for-professionals-covers-ejb-3-1-using-glassfish-v3-prelude/</link>
<pubDate>Wed, 03 Jun 2009 03:14:36 +0000</pubDate>
<dc:creator>sharanamshah</dc:creator>
<guid>http://sharanamshah.wordpress.com/2009/06/03/java-persistence-api-in-ejb-3-for-professionals-covers-ejb-3-1-using-glassfish-v3-prelude/</guid>
<description><![CDATA[Java Persistence API In EJB 3 For Professionals Designed for beginners and intermediate developers, ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div class="wp-caption aligncenter" style="width: 400px"><a href="http://www.sharanamshah.com/index.php/Books-authored-by-Sharanam-Shah/Shroff-Publishers-and-Distributors-Pvt.-Ltd./Java-Persistence-API-In-EJB-3-For-Professionals-Covers-a-section-on-EJB-3.1.html"><img title="Java Persistence API In EJB 3 For Professionals" src="http://www.sharanamshah.com/images/stories/books/JPAInEJB3ForProfessionals.jpg" alt="Java Persistence API In EJB 3 For Professionals" width="390" height="500" /></a><p class="wp-caption-text">Java Persistence API In EJB 3 For Professionals</p></div>
<p style="text-align:justify;"><!--[if gte mso 9]&#62;  Normal 0   false false false        MicrosoftInternetExplorer4  &#60;![endif]--><!--[if gte mso 9]&#62;   &#60;![endif]--><!--[if !mso]&#62;-->Designed for beginners and intermediate developers, this book teaches JPA from the ground up with an aim to get the reader up to speed with JPA as quickly as possible. It delves deeply into the core of the JPA, providing a sound understanding of the components that make up the frameworkand the way they interact with each other.</p>
<p style="text-align:justify;">This book uses the learning by doing pattern with a lot of ready-to-use examples. This pattern has proven to be the best approach for learning a new technology. Most [if not all] of the concepts that you will find in this book are demonstrated using well described and easy to understand examples, yet sophisticated enough to demonstrate JPA in a real-world context.</p>
<p style="text-align:justify;">This book demonstrates a step-by-step guide to developing <strong>Web</strong> as well as <strong>Enterprise</strong> applications [using <strong>EJB 3</strong> ] which re-enforces all the learning that takes place throughout the book. It also teaches how to integrate an enterprise application with <strong>Struts2</strong>. Not only this, the book also introduces <strong>EJB 3.1 [a part of Java EE 6]</strong> and demonstrates developing a IPA based EIB 3.1 application with the help of <strong>Glassfish v3 Prelude.</strong></p>
<p><!--[if gte mso 9]&#62;  Normal 0   false false false        MicrosoftInternetExplorer4  &#60;![endif]--><!--[if gte mso 9]&#62;   &#60;![endif]--><!--[if !mso]&#62;--></p>
<p class="MsoNormal" style="text-align:justify;"><strong><span style="font-size:10pt;font-family:Verdana;color:black;">What You&#8217;ll Learn?</span></strong></p>
<p class="MsoNormal" style="text-align:justify;"><span style="font-size:10pt;font-family:Verdana;color:black;"> </span></p>
<p class="FirstBullet" style="margin-left:0;text-indent:0;">Building Web Applications</p>
<p class="FirstBullet" style="margin-left:.5in;text-indent:0;">Using JSP/Servlets, DAO, JPA using Hibernate 3, Ajax, Glassfish v2</p>
<p class="FirstBullet" style="margin-left:.5in;text-indent:0;">Using JSP, JPA using TopLink, Glassfish v2</p>
<p class="FirstBullet" style="margin-left:0;text-indent:0;">Building Enterprise Applications</p>
<p class="FirstBullet" style="margin-left:.5in;text-indent:0;">Using JSP/Servlets, EJB 3 &#8211; Session Beans, JPA using TopLink, Glassfish v2</p>
<p class="FirstBullet" style="margin-left:.5in;text-indent:0;">Integrating an enterprise application with Struts2 [An extensible framework for creating enterprise-ready Java Web applications]</p>
<p class="FirstBullet" style="margin-left:0;text-indent:0;">Building Enterprise Applications Using EJB 3.1</p>
<p class="FirstBullet" style="margin-left:.5in;text-indent:0;">Using JSP/Servlets, EJB 3.1 &#8211; Session Beans, JPA using EclipseLink, Glassfish v3 Prelude</p>
<p class="FirstBullet" style="margin-left:0;text-indent:0;">Using the NetBeans IDE to develop JPA based applications<br />
Reverse Engineering POJOs and Mapping Documents from Database tables</p>
<p class="FirstBullet" style="margin-left:0;text-indent:0;">Pagination using JPA</p>
<p class="MsoNormal" style="text-align:justify;"><span style="font-size:10pt;font-family:Verdana;color:black;"><br />
To ensure that the focus remains on understanding the technology, we have adopted the simplest and most customary domain models such as Customer, Authors, ContactDetails, Books, Subscribers and Guestbook.</span></p>
<p class="MsoNormal" style="text-align:justify;">
<p><strong>ISBN 10:</strong> 81-8404-709-7</p>
<p><strong>ISBN 13:</strong> 978-81-8404-709-7</p>
<p><strong>Edition:</strong> First</p>
<p><strong>Downloads</strong></p>
<p><a title="Java Persistence API In EJB 3 For Professionals - Covers EJB 3.1 using GlassFish v3 Prelude" href="http://www.sharanamshah.com/downloads/pdfs/JPAInEJB3_Chap03.pdf"><strong><span style="text-decoration:underline;">Sample Chapter</span></strong></a> <a title="Java Persistence API In EJB 3 For Professionals - Covers EJB 3.1 using GlassFish v3 Prelude" href="http://www.sharanamshah.com/downloads/pdfs/JPAInEJB3_TOC.pdf"><span style="text-decoration:underline;"><strong> </strong></span></a></p>
<p><a title="Java Persistence API In EJB 3 For Professionals - Covers EJB 3.1 using GlassFish v3 Prelude" href="http://www.sharanamshah.com/downloads/pdfs/JPAInEJB3_TOC.pdf"><span style="text-decoration:underline;"><strong>TOC</strong></span></a></p>
<p><strong><br />
</strong></p>
<p><strong>THE TOPICS COVERED IN THE BOOK</strong></p>
<p><strong>Introduction</strong><br />
Persistence, Object/Relational Mapping And JPA, Introduction To Java Persistence API, Writing The First Application<br />
<strong>Core Components Of JPA</strong></p>
<p>Entity, Entity Manager And Its Factory, Transactions, Persistence Unit<br />
<strong>Metadata</strong><br />
Getting Started With Metadata, Database Identity, Associations, Collections, Inheritance, Defining Metadata Using XML<br />
<strong>The JPA Query Language</strong></p>
<p>The Basics Of Java Persistence Query Language, Joins, Query Interface, Pagination, Named Queries, Native SQL Queries<br />
<strong>Web Application Development</strong></p>
<p>Customer Database Web Application, Subscriber Management Web Application</p>
<p><strong>Enterprise</strong><strong> Application Development</strong></p>
<p>Introduction To EJB 3.0, Customer Database Enterprise Application, Integrating Customer Database Enterprise Application With Struts2<br />
<strong>Enterprise</strong><strong> Application Development Using EJB 3.1</strong></p>
<p>Introduction To EJB 3.1, Customer Database Enterprise Application<br />
<strong>Appendix</strong><br />
Installing The NetBeans IDE, Customer Database Application Using Different ORMs</p>
<p><strong>CONTENTS OF THE CD-ROM</strong></p>
<p>Setup files for JDK 6</p>
<p>NetBeans IDE 6.5</p>
<p>Hibernate Core 3.x</p>
<p>Hibernate Annotations 3.x</p>
<p>Hibernate EntityManager 3.x</p>
<p>Struts 2.x</p>
<p>MySQL Community Server 6.x</p>
<p>JDBC Drivers</p>
<p>Library files for<strong>:</strong></p>
<p>Display Tags</p>
<p>EclipseLink</p>
<p>TopLink</p>
<p>OpenJPA</p>
<p>Source code for the examples covered in this book</p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:850px;width:1px;height:1px;"><!--[if gte mso 9]&#62;  Normal 0   false false false        MicrosoftInternetExplorer4  &#60;![endif]--><!--[if gte mso 9]&#62;   &#60;![endif]-->&#60;!&#8211;[if !mso]&#62;<span class="mceItemObject"></span> &#60;!  st1\:*{behavior:url(#ieooui) } &#8211;&#62; <!--[endif]--><!--  /* Font Definitions */  @font-face 	{font-family:Wingdings; 	panose-1:5 0 0 0 0 0 0 0 0 0; 	mso-font-charset:2; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face 	{font-family:Verdana; 	panose-1:2 11 6 4 3 5 4 4 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:536871559 0 0 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} p.FirstBullet, li.FirstBullet, div.FirstBullet 	{mso-style-name:FirstBullet; 	margin-top:0in; 	margin-right:0in; 	margin-bottom:0in; 	margin-left:.25in; 	margin-bottom:.0001pt; 	text-indent:-.25in; 	mso-pagination:widow-orphan; 	mso-list:l0 level1 lfo1; 	tab-stops:list .25in; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;}  /* List Definitions */  @list l0 	{mso-list-id:1755934047; 	mso-list-type:hybrid; 	mso-list-template-ids:1055432622 552664646 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l0:level1 	{mso-level-number-format:bullet; 	mso-level-style-link:FirstBullet; 	mso-level-text:; 	mso-level-tab-stop:.25in; 	mso-level-number-position:left; 	margin-left:.25in; 	text-indent:-.25in; 	mso-ansi-font-size:8.0pt; 	font-family:Wingdings;} @list l0:level2 	{mso-level-number-format:bullet; 	mso-level-text:o; 	mso-level-tab-stop:1.0in; 	mso-level-number-position:left; 	text-indent:-.25in; 	font-family:"Courier New";} ol 	{margin-bottom:0in;} ul 	{margin-bottom:0in;} --><!--[if gte mso 10]&#62; &#60;!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:&#34;Table Normal&#34;; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:&#34;&#34;; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:&#34;Times New Roman&#34;; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --> <!--[endif]--></p>
<p class="MsoNormal" style="text-align:justify;"><strong><span style="font-size:10pt;font-family:Verdana;color:black;">What You&#8217;ll Learn?</span></strong></p>
<p class="MsoNormal" style="text-align:justify;"><span style="font-size:10pt;font-family:Verdana;color:black;"> </span></p>
<p class="FirstBullet"><!--[if !supportLists]--><span style="font-size:8pt;font-family:Wingdings;"><span>ü<span style="font-family:&#34;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->Building Web Applications</p>
<p class="FirstBullet" style="margin-left:.5in;"><!--[if !supportLists]--><span style="font-size:10pt;font-family:Verdana;color:black;"><span><span style="font-family:&#34;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span style="font-size:10pt;font-family:Verdana;color:black;">Using JSP/Servlets, DAO, JPA using Hibernate 3, Ajax, Glassfish v2</span></p>
<p class="FirstBullet" style="margin-left:.5in;"><!--[if !supportLists]--><span style="font-size:10pt;font-family:Verdana;color:black;"><span><span style="font-family:&#34;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span style="font-size:10pt;font-family:Verdana;color:black;">Using JSP, JPA using TopLink, Glassfish v2</span></p>
<p class="FirstBullet"><!--[if !supportLists]--><span style="font-size:8pt;font-family:Wingdings;color:black;"><span>ü<span style="font-family:&#34;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]-->Building<span style="font-size:10pt;font-family:Verdana;color:black;"> Enterprise Applications</span></p>
<p class="FirstBullet" style="margin-left:.5in;"><!--[if !supportLists]--><span style="font-size:10pt;font-family:Verdana;color:black;"><span><span style="font-family:&#34;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span style="font-size:10pt;font-family:Verdana;color:black;">Using JSP/Servlets, EJB 3 &#8211; Session Beans, JPA using TopLink, Glassfish v2</span></p>
<p class="FirstBullet" style="margin-left:.5in;"><!--[if !supportLists]--><span style="font-size:10pt;font-family:Verdana;color:black;"><span><span style="font-family:&#34;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span style="font-size:10pt;font-family:Verdana;color:black;">Integrating an enterprise application with Struts2 [An extensible framework for creating enterprise-ready Java Web applications]</span></p>
<p class="FirstBullet"><!--[if !supportLists]--><span style="font-size:8pt;font-family:Wingdings;color:black;"><span>ü<span style="font-family:&#34;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span style="font-size:10pt;font-family:Verdana;color:black;">Building Enterprise Applications Using EJB 3.1</span></p>
<p class="FirstBullet" style="margin-left:.5in;"><!--[if !supportLists]--><span style="font-size:10pt;font-family:Verdana;color:black;"><span><span style="font-family:&#34;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span style="font-size:10pt;font-family:Verdana;color:black;">Using JSP/Servlets, EJB 3.1 &#8211; Session Beans, JPA using EclipseLink, Glassfish v3 Prelude</span></p>
<p class="FirstBullet"><!--[if !supportLists]--><span style="font-size:8pt;font-family:Wingdings;color:black;"><span>ü<span style="font-family:&#34;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span style="font-size:10pt;font-family:Verdana;color:black;">Using the NetBeans IDE to develop JPA based applications<br />
Reverse Engineering POJOs and Mapping Documents from Database tables</span></p>
<p class="FirstBullet"><!--[if !supportLists]--><span style="font-size:8pt;font-family:Wingdings;color:black;"><span>ü<span style="font-family:&#34;font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;"> </span></span></span><!--[endif]--><span style="font-size:10pt;font-family:Verdana;color:black;">Pagination using JPA</span></p>
<p class="MsoNormal" style="text-align:justify;"><span style="font-size:10pt;font-family:Verdana;color:black;"><br />
To ensure that the focus remains on understanding the technology, we have adopted the simplest and most customary domain models such as Customer, Authors, ContactDetails, Books, Subscribers and Guestbook.</span></p>
</div>
</div>]]></content:encoded>
</item>

</channel>
</rss>
