You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2013/07/17 11:31:13 UTC
svn commit: r869821 [14/43] - in
/websites/production/struts/content/development/2.x/docs: ./
ajax-validation.data/ big-picture.data/ chaining-interceptor.data/
colophon.data/ config-browser-plugin.data/
create-struts-2-web-application-using-maven-to-m...
Added: websites/production/struts/content/development/2.x/docs/file-upload.html
==============================================================================
--- websites/production/struts/content/development/2.x/docs/file-upload.html (added)
+++ websites/production/struts/content/development/2.x/docs/file-upload.html Wed Jul 17 09:31:08 2013
@@ -0,0 +1,586 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<html>
+<head>
+ <LINK type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
+ <style type="text/css">
+ .dp-highlighter {
+ width:95% !important;
+ }
+ </style>
+ <style type="text/css">
+ .footer {
+ background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
+ background-repeat: repeat-x;
+ background-position: left top;
+ padding-top: 4px;
+ color: #666;
+ }
+ </style>
+ <link href='http://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
+ <link href='http://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
+ <script src='http://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
+ <script src='http://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
+ <script src='http://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script>
+ <script src='http://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script>
+
+ <script type="text/javascript">
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
+ <script type="text/javascript" language="javascript">
+ var hide = null;
+ var show = null;
+ var children = null;
+
+ function init() {
+ /* Search form initialization */
+ var form = document.forms['search'];
+ if (form != null) {
+ form.elements['domains'].value = location.hostname;
+ form.elements['sitesearch'].value = location.hostname;
+ }
+
+ /* Children initialization */
+ hide = document.getElementById('hide');
+ show = document.getElementById('show');
+ children = document.all != null ?
+ document.all['children'] :
+ document.getElementById('children');
+ if (children != null) {
+ children.style.display = 'none';
+ show.style.display = 'inline';
+ hide.style.display = 'none';
+ }
+ }
+
+ function showChildren() {
+ children.style.display = 'block';
+ show.style.display = 'none';
+ hide.style.display = 'inline';
+ }
+
+ function hideChildren() {
+ children.style.display = 'none';
+ show.style.display = 'inline';
+ hide.style.display = 'none';
+ }
+ </script>
+ <title>File Upload</title>
+</head>
+<body onload="init()">
+<table border="0" cellpadding="2" cellspacing="0" width="100%">
+ <tr class="topBar">
+ <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
+ <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="core-developers-guide.html">Core Developers Guide</a> > <a href="interceptors.html">Interceptors</a> > <a href="file-upload.html">File Upload</a>
+ </td>
+ <td align="right" valign="middle" nowrap>
+ <form name="search" action="http://www.google.com/search" method="get">
+ <input type="hidden" name="ie" value="UTF-8" />
+ <input type="hidden" name="oe" value="UTF-8" />
+ <input type="hidden" name="domains" value="" />
+ <input type="hidden" name="sitesearch" value="" />
+ <input type="text" name="q" maxlength="255" value="" />
+ <input type="submit" name="btnG" value="Google Search" />
+ </form>
+ </td>
+ </tr>
+</table>
+
+<div id="PageContent">
+ <div class="pageheader" style="padding: 6px 0px 0px 0px;">
+ <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
+ <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
+ <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
+ <div style="margin: 0px 10px 8px 10px" class="pagetitle">File Upload</div>
+
+ <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
+ <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=86602">
+ <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=86602">Edit Page</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
+ <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=86602">
+ <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=86602">Add Page</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=86602">
+ <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=86602">Add News</a>
+ </div>
+ </div>
+
+ <div class="pagecontent">
+ <div class="wiki-content">
+ <div id="ConfluenceContent"><p>The Struts 2 framework provides built-in support for processing file uploads that conform to <a shape="rect" class="external-link" href="http://www.ietf.org/rfc/rfc1867.txt" rel="nofollow">RFC 1867</a>, "Form-based File Upload in HTML". 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 shape="rect" href="#FileUpload-Dependencies">Dependencies</a></li><li><a shape="rect" href="#FileUpload-BasicUsage">Basic Usage</a></li><li><a shape="rect" href="#FileUpload-UploadingMultipleFiles">Uploading Multiple Files</a></li><ul><li><a shape="rect" href="#FileUpload-UploadingMultipleFilesusingArrays">Uploading Multiple Files using Arrays</a></li><li><a shape="rect" href="#FileUpload-UploadingMultipleFilesusingLists">Uploading Multiple Files using Lists</a></li></ul><li><a shape="rect" href="#FileUpload-AdvancedConfiguration">Advanced Configuration</a></li><ul><li><a shape="rect" href="#FileUpload-FileSizeLimits">File Size Limits</a></li><li><a shape="rect" href="#FileUpload-FileTypes">File Types</a></li><li><a shape="rect" href="#FileUpload-ErrorMessages">Error Messages</a></li><li><a shape="rect" href="#FileUpload-TemporaryDirectories">Temporary Directories</a></li><li><a shape="rect" href="#FileUpload-AlternateLibraries">Alternate Libraries</a></li></ul></ul></div
>
+
+<h2><a shape="rect" 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>
+
+<div class="table-wrap">
+<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"> Library </th><th colspan="1" rowspan="1" class="confluenceTh"> URL </th><th colspan="1" rowspan="1" class="confluenceTh"> Struts 2.0.x </th><th colspan="1" rowspan="1" class="confluenceTh"> Struts 2.1.x </th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">Commons-FileUpload </td><td colspan="1" rowspan="1" class="confluenceTd"> <a shape="rect" class="external-link" href="http://commons.apache.org/fileupload/">http://commons.apache.org/fileupload/</a> </td><td colspan="1" rowspan="1" class="confluenceTd"> 1.1.1 </td><td colspan="1" rowspan="1" class="confluenceTd"> 1.2.1 </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">Commons-IO </td><td colspan="1" rowspan="1" class="confluenceTd"> <a shape="rect" class="external-link" href="http://commons.apache.org/io/">http://commons.apache.org/io/</a> </td><td colspan="1" rowspan="1" class="confluenceTd"> 1.0 </td><td colspan="1"
rowspan="1" class="confluenceTd"> 1.3.2 </td></tr></tbody></table>
+</div>
+
+
+<p>If you are using Maven then you can add these libraries as dependencies in your project's pom.xml.</p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Struts 2.0.x File Upload Dependencies</b></div><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+<dependency>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload</artifactId>
+ <version>1.1.1</version>
+</dependency>
+<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.0</version>
+</dependency>
+]]></script>
+</div></div>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Struts 2.1.x File Upload Dependencies</b></div><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+<dependency>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload</artifactId>
+ <version>1.2.1</version>
+</dependency>
+<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.3.2</version>
+</dependency>
+]]></script>
+</div></div>
+
+<h2><a shape="rect" 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><b>Example action mapping:</b></p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+<action name="doUpload" class="com.example.UploadAction">
+ <result name="success">good_result.jsp</result>
+</action>
+]]></script>
+</div></div>
+
+<p>A form must be create with a form field of type file, <tt><INPUT type="file" name="upload"></tt>. The form used to upload the file must have its encoding type set to multipart/form-data, <tt><FORM action="doUpload" enctype="multipart/form-data" method="post"></tt>. The standard procedure for adding these elements is by using the Struts 2 tag libraries as shown in the following example:</p>
+
+<p><b>Example JSP form tags:</b></p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+<s:form action="doUpload" method="post" enctype="multipart/form-data">
+ <s:file name="upload" label="File"/>
+ <s:submit/>
+</s:form>
+]]></script>
+</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 <b>upload</b> you would provide the three setter methods shown in the following example:</p>
+
+<p><b>Example Action class:</b></p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+package com.example;
+
+ import java.io.File;
+ import com.opensymphony.xwork2.ActionSupport;
+
+ public class UploadAction extends ActionSupport {
+ private File file;
+ private String contentType;
+ private String filename;
+
+ public void setUpload(File file) {
+ this.file = file;
+ }
+
+ public void setUploadContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public void setUploadFileName(String filename) {
+ this.filename = filename;
+ }
+
+ public String execute() {
+ //...
+ return SUCCESS;
+ }
+ }
+]]></script>
+</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>
+<div class="table-wrap">
+<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"> Method Signature </th><th colspan="1" rowspan="1" class="confluenceTh"> Description </th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> setX(File file) </td><td colspan="1" rowspan="1" class="confluenceTd"> 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 colspan="1" rowspan="1" class="confluenceTd"> setXContentType(String contentType) </td><td colspan="1" rowspan="1" class="confluenceTd"> The mime type of the uploaded file </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> setXFileName(String fileName) </td><td colspan="1" rowspan="1" class="confluenceTd"> The actual file name of the uploaded file (not the HTML name) </td></tr></tbody></table>
+</div>
+
+
+<h2><a shape="rect" 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 <a shape="rect" class="external-link" href="http://struts.apache.org/download.cgi">http://struts.apache.org/download.cgi</a>. For the Action mapping details see <tt>struts-fileupload.xml</tt> in the sample application download.</p>
+
+<h3><a shape="rect" name="FileUpload-UploadingMultipleFilesusingArrays"></a>Uploading Multiple Files using Arrays</h3>
+
+<p><b>multipleUploadUsingArray.jsp</b> Notice all file input types have the same name.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[
+<%@ page
+ language="java"
+ contentType="text/html; charset=UTF-8"
+ pageEncoding="UTF-8"%>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+ <title>Struts2 Showcase - Fileupload sample - Multiple fileupload using Array</title>
+</head>
+
+<body>
+<div class="page-header">
+ <h1>Fileupload sample - Multiple fileupload using Array</h1>
+</div>
+
+<div class="container-fluid">
+ <div class="row-fluid">
+ <div class="span12">
+
+ <s:form action="doMultipleUploadUsingArray" method="POST" enctype="multipart/form-data">
+ <s:file label="File (1)" name="upload" />
+ <s:file label="File (2)" name="upload" />
+ <s:file label="FIle (3)" name="upload" />
+ <s:submit cssClass="btn btn-primary"/>
+ </s:form>
+
+ </div>
+ </div>
+</div>
+
+</body>
+</html>
+]]></script>
+</div></div>
+
+<p><b>MultipleFileUploadUsingArrayAction.java</b></p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+package org.apache.struts2.showcase.fileupload;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+import java.io.File;
+
+/**
+ * Showcase action - mutiple file upload using array.
+ *
+ * @version $Date$ $Id$
+ */
+public class MultipleFileUploadUsingArrayAction extends ActionSupport {
+
+ private File[] uploads;
+ private String[] uploadFileNames;
+ private String[] uploadContentTypes;
+
+
+ public String upload() throws Exception {
+ System.out.println("\n\n upload2");
+ System.out.println("files:");
+ for (File u : uploads) {
+ System.out.println("*** " + u + "\t" + u.length());
+ }
+ System.out.println("filenames:");
+ for (String n : uploadFileNames) {
+ System.out.println("*** " + n);
+ }
+ System.out.println("content types:");
+ for (String c : uploadContentTypes) {
+ System.out.println("*** " + c);
+ }
+ System.out.println("\n\n");
+ return SUCCESS;
+ }
+
+ public File[] getUpload() {
+ return this.uploads;
+ }
+
+ public void setUpload(File[] upload) {
+ this.uploads = upload;
+ }
+
+ public String[] getUploadFileName() {
+ return this.uploadFileNames;
+ }
+
+ public void setUploadFileName(String[] uploadFileName) {
+ this.uploadFileNames = uploadFileName;
+ }
+
+ public String[] getUploadContentType() {
+ return this.uploadContentTypes;
+ }
+
+ public void setUploadContentType(String[] uploadContentType) {
+ this.uploadContentTypes = uploadContentType;
+ }
+}
+]]></script>
+</div></div>
+
+<h3><a shape="rect" name="FileUpload-UploadingMultipleFilesusingLists"></a>Uploading Multiple Files using Lists</h3>
+
+<p><b>multipleUploadUsingList.jsp</b> Notice all file input types have the same name.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[
+<%@ page
+ language="java"
+ contentType="text/html; charset=UTF-8"
+ pageEncoding="UTF-8"%>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+ <title>Struts2 Showcase - Fileupload sample - Multiple fileupload using List</title>
+</head>
+
+<body>
+<div class="page-header">
+ <h1>Fileupload sample - Multiple fileupload using List</h1>
+</div>
+
+<div class="container-fluid">
+ <div class="row-fluid">
+ <div class="span12">
+
+ <s:form action="doMultipleUploadUsingList" method="POST" enctype="multipart/form-data">
+ <s:file label="File (1)" name="upload" />
+ <s:file label="File (2)" name="upload" />
+ <s:file label="FIle (3)" name="upload" />
+ <s:submit cssClass="btn btn-primary"/>
+ </s:form>
+
+ </div>
+ </div>
+</div>
+
+</body>
+</html>
+]]></script>
+</div></div>
+
+<p><b>MultipleFileUploadUsingListAction.java</b></p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+package org.apache.struts2.showcase.fileupload;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Showcase action - multiple file upload using List
+ *
+ * @version $Date$ $Id$
+ */
+public class MultipleFileUploadUsingListAction extends ActionSupport {
+
+ private List<File> uploads = new ArrayList<File>();
+ private List<String> uploadFileNames = new ArrayList<String>();
+ private List<String> uploadContentTypes = new ArrayList<String>();
+
+
+ public List<File> getUpload() {
+ return this.uploads;
+ }
+
+ public void setUpload(List<File> uploads) {
+ this.uploads = uploads;
+ }
+
+ public List<String> getUploadFileName() {
+ return this.uploadFileNames;
+ }
+
+ public void setUploadFileName(List<String> uploadFileNames) {
+ this.uploadFileNames = uploadFileNames;
+ }
+
+ public List<String> getUploadContentType() {
+ return this.uploadContentTypes;
+ }
+
+ public void setUploadContentType(List<String> contentTypes) {
+ this.uploadContentTypes = contentTypes;
+ }
+
+ public String upload() throws Exception {
+
+ System.out.println("\n\n upload1");
+ System.out.println("files:");
+ for (File u : uploads) {
+ System.out.println("*** " + u + "\t" + u.length());
+ }
+ System.out.println("filenames:");
+ for (String n : uploadFileNames) {
+ System.out.println("*** " + n);
+ }
+ System.out.println("content types:");
+ for (String c : uploadContentTypes) {
+ System.out.println("*** " + c);
+ }
+ System.out.println("\n\n");
+ return SUCCESS;
+ }
+}
+]]></script>
+</div></div>
+
+<h2><a shape="rect" 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 class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: plain; gutter: false" type="syntaxhighlighter"><![CDATA[
+struts.multipart.parser=jakarta
+struts.multipart.saveDir=
+struts.multipart.maxSize=2097152
+]]></script>
+</div></div>
+
+<div class="panelMacro"><table class="noteMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/warning.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1">Please remember that the <b>struts.multipart.maxSize</b> is the size limit of the whole request, which means when you uploading multiple files, the sum of their size must be below the <b>struts.multipart.maxSize</b>!</td></tr></table></div>
+
+<p>In order to change theses settings you define a constant in your applications <tt>struts.xml</tt> file like so:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
+<struts>
+ <constant name="struts.multipart.maxSize" value="1000000" />
+ ...
+</struts>
+]]></script>
+</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 class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+<action name="doUpload" class="com.example.UploadAction">
+ <interceptor-ref name="basicStack"/>
+ <interceptor-ref name="fileUpload">
+ <param name="allowedTypes">text/plain</param>
+ </interceptor-ref>
+ <interceptor-ref name="validation"/>
+ <interceptor-ref name="workflow"/>
+
+ <result name="success">good_result.jsp</result>
+</action>
+]]></script>
+</div></div>
+
+<h3><a shape="rect" 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 class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
+<struts>
+ <constant name="struts.multipart.maxSize" value="1000000" />
+
+ <action name="doUpload" class="com.example.UploadAction">
+ <interceptor-ref name="basicStack"/>
+ <interceptor-ref name="fileUpload">
+ <param name="maximumSize">500000</param>
+ </interceptor-ref>
+ <interceptor-ref name="validation"/>
+ <interceptor-ref name="workflow"/>
+
+ <result name="success">good_result.jsp</result>
+ </action>
+</struts>
+]]></script>
+</div></div>
+
+<h3><a shape="rect" 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 class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+<action name="doUpload" class="com.example.UploadAction">
+ <interceptor-ref name="basicStack"/>
+ <interceptor-ref name="fileUpload">
+ <param name="allowedTypes">image/jpeg,image/gif</param>
+ </interceptor-ref>
+ <interceptor-ref name="validation"/>
+ <interceptor-ref name="workflow"/>
+
+ <result name="success">good_result.jsp</result>
+</action>
+]]></script>
+</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's more flexible and no interceptor configuration would be needed if file sizes are keep under 2 megs.</p>
+
+<h3><a shape="rect" 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>
+
+<div class="table-wrap">
+<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"> Error Key </th><th colspan="1" rowspan="1" class="confluenceTh"> Description </th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> struts.messages.error.uploading </td><td colspan="1" rowspan="1" class="confluenceTd"> A general error that occurs when the file could not be uploaded </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> struts.messages.error.file.too.large </td><td colspan="1" rowspan="1" class="confluenceTd"> Occurs when the uploaded file is too large as specified by maximumSize. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> struts.messages.error.content.type.not.allowed </td><td colspan="1" rowspan="1" class="confluenceTd"> Occurs when the uploaded file does not match the expected content types specified </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> struts.messages.error.file.extension.not.allowed </td><td colspan="1" row
span="1" class="confluenceTd"> Occurs when uploaded file has disallowed extension </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> struts.messages.upload.error.SizeLimitExceededException </td><td colspan="1" rowspan="1" class="confluenceTd"> Occurs when the upload request (as a whole) exceed configured <b>struts.multipart.maxSize</b> </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> struts.messages.upload.error.<Exception class SimpleName> </td><td colspan="1" rowspan="1" class="confluenceTd"> Occurs when any other exception took place during file upload process </td></tr></tbody></table>
+</div>
+
+
+<h3><a shape="rect" 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 shape="rect" 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's multipart parser instead of the Commons-FileUpload library. The pell parser is a Struts 2 plugin, for more details see: <a shape="rect" class="external-link" href="http://cwiki.apache.org/S2PLUGINS/pell-multipart-plugin.html">http://cwiki.apache.org/S2PLUGINS/pell-multipart-plugin.html</a>. There was a third alternative, cos, but it was removed due to licensing incompatibilities.</p></div>
+ </div>
+
+
+ </div>
+</div>
+<div class="footer">
+ Generated by CXF SiteExporter
+</div>
+</body>
+</html>
\ No newline at end of file
Added: websites/production/struts/content/development/2.x/docs/flying-solo.html
==============================================================================
--- websites/production/struts/content/development/2.x/docs/flying-solo.html (added)
+++ websites/production/struts/content/development/2.x/docs/flying-solo.html Wed Jul 17 09:31:08 2013
@@ -0,0 +1,146 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<html>
+<head>
+ <LINK type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
+ <style type="text/css">
+ .dp-highlighter {
+ width:95% !important;
+ }
+ </style>
+ <style type="text/css">
+ .footer {
+ background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
+ background-repeat: repeat-x;
+ background-position: left top;
+ padding-top: 4px;
+ color: #666;
+ }
+ </style>
+ <script type="text/javascript" language="javascript">
+ var hide = null;
+ var show = null;
+ var children = null;
+
+ function init() {
+ /* Search form initialization */
+ var form = document.forms['search'];
+ if (form != null) {
+ form.elements['domains'].value = location.hostname;
+ form.elements['sitesearch'].value = location.hostname;
+ }
+
+ /* Children initialization */
+ hide = document.getElementById('hide');
+ show = document.getElementById('show');
+ children = document.all != null ?
+ document.all['children'] :
+ document.getElementById('children');
+ if (children != null) {
+ children.style.display = 'none';
+ show.style.display = 'inline';
+ hide.style.display = 'none';
+ }
+ }
+
+ function showChildren() {
+ children.style.display = 'block';
+ show.style.display = 'none';
+ hide.style.display = 'inline';
+ }
+
+ function hideChildren() {
+ children.style.display = 'none';
+ show.style.display = 'inline';
+ hide.style.display = 'none';
+ }
+ </script>
+ <title>Flying Solo</title>
+</head>
+<body onload="init()">
+<table border="0" cellpadding="2" cellspacing="0" width="100%">
+ <tr class="topBar">
+ <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
+ <a href="home.html">Home</a> > <a href="tutorials.html">Tutorials</a> > <a href="bootstrap.html">Bootstrap</a> > <a href="flying-solo.html">Flying Solo</a>
+ </td>
+ <td align="right" valign="middle" nowrap>
+ <form name="search" action="http://www.google.com/search" method="get">
+ <input type="hidden" name="ie" value="UTF-8" />
+ <input type="hidden" name="oe" value="UTF-8" />
+ <input type="hidden" name="domains" value="" />
+ <input type="hidden" name="sitesearch" value="" />
+ <input type="text" name="q" maxlength="255" value="" />
+ <input type="submit" name="btnG" value="Google Search" />
+ </form>
+ </td>
+ </tr>
+</table>
+
+<div id="PageContent">
+ <div class="pageheader" style="padding: 6px 0px 0px 0px;">
+ <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
+ <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
+ <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
+ <div style="margin: 0px 10px 8px 10px" class="pagetitle">Flying Solo</div>
+
+ <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
+ <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=13984">
+ <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=13984">Edit Page</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
+ <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=13984">
+ <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=13984">Add Page</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=13984">
+ <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=13984">Add News</a>
+ </div>
+ </div>
+
+ <div class="pagecontent">
+ <div class="wiki-content">
+ <div id="ConfluenceContent"><p>There are several resources available to help you create your own applications, including QuickStart and the various example applications.</p>
+
+<h2><a shape="rect" name="FlyingSolo-BrowsetheResources"></a>Browse the Resources</h2>
+
+<p>There are online resources to help you along, every step of the way.</p>
+<ul><li><a shape="rect" class="external-link" href="http://struts.apache.org/downloads.html">Download the framework</a> - The full distribution includes sample applications, source code, and documentation.</li><li><a shape="rect" class="external-link" href="http://struts.apache.org/mail.html">Subscribe to Mailing List</a> and post a question, or browse Mail Archive. (You probably want to browse the archive or forum first.)</li><li><a shape="rect" class="external-link" href="http://svn.apache.org/viewvc/struts/struts2/">Subversion Repository</a> - Browse the source.</li><li><a shape="rect" class="external-link" href="http://cwiki.apache.org/confluence/display/WW/Home">Online documentation</a> - Read it here first! The project documentation is maintained using Confluence and exported to HTML on every change.</li><li><a shape="rect" class="external-link" href="http://issues.apache.org/struts/">JIRA Issue Tracker</a> - Browse or file enhancements requests and defect reports.</li></ul>
+
+
+<h2><a shape="rect" name="FlyingSolo-BacktoTutorials"></a>Back to <a shape="rect" href="tutorials.html" title="Tutorials">Tutorials</a></h2></div>
+ </div>
+
+
+ </div>
+</div>
+<div class="footer">
+ Generated by CXF SiteExporter
+</div>
+</body>
+</html>
\ No newline at end of file
Added: websites/production/struts/content/development/2.x/docs/form-validation-using-xml.data/Screen-shot-2010-05-05-at-10.05.14-AM.png
==============================================================================
Binary file - no diff available.
Propchange: websites/production/struts/content/development/2.x/docs/form-validation-using-xml.data/Screen-shot-2010-05-05-at-10.05.14-AM.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Added: websites/production/struts/content/development/2.x/docs/form-validation-using-xml.data/Screen-shot-2010-05-05-at-10.25.38-AM.png
==============================================================================
Binary file - no diff available.
Propchange: websites/production/struts/content/development/2.x/docs/form-validation-using-xml.data/Screen-shot-2010-05-05-at-10.25.38-AM.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Added: websites/production/struts/content/development/2.x/docs/form-validation-using-xml.data/Screen-shot-2010-05-05-at-10.45.18-AM.png
==============================================================================
Binary file - no diff available.
Propchange: websites/production/struts/content/development/2.x/docs/form-validation-using-xml.data/Screen-shot-2010-05-05-at-10.45.18-AM.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Added: websites/production/struts/content/development/2.x/docs/form-validation-using-xml.html
==============================================================================
--- websites/production/struts/content/development/2.x/docs/form-validation-using-xml.html (added)
+++ websites/production/struts/content/development/2.x/docs/form-validation-using-xml.html Wed Jul 17 09:31:08 2013
@@ -0,0 +1,275 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<html>
+<head>
+ <LINK type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
+ <style type="text/css">
+ .dp-highlighter {
+ width:95% !important;
+ }
+ </style>
+ <style type="text/css">
+ .footer {
+ background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
+ background-repeat: repeat-x;
+ background-position: left top;
+ padding-top: 4px;
+ color: #666;
+ }
+ </style>
+ <link href='http://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
+ <link href='http://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
+ <script src='http://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
+ <script src='http://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
+
+ <script type="text/javascript">
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
+ <script type="text/javascript" language="javascript">
+ var hide = null;
+ var show = null;
+ var children = null;
+
+ function init() {
+ /* Search form initialization */
+ var form = document.forms['search'];
+ if (form != null) {
+ form.elements['domains'].value = location.hostname;
+ form.elements['sitesearch'].value = location.hostname;
+ }
+
+ /* Children initialization */
+ hide = document.getElementById('hide');
+ show = document.getElementById('show');
+ children = document.all != null ?
+ document.all['children'] :
+ document.getElementById('children');
+ if (children != null) {
+ children.style.display = 'none';
+ show.style.display = 'inline';
+ hide.style.display = 'none';
+ }
+ }
+
+ function showChildren() {
+ children.style.display = 'block';
+ show.style.display = 'none';
+ hide.style.display = 'inline';
+ }
+
+ function hideChildren() {
+ children.style.display = 'none';
+ show.style.display = 'inline';
+ hide.style.display = 'none';
+ }
+ </script>
+ <title>Form Validation Using XML</title>
+</head>
+<body onload="init()">
+<table border="0" cellpadding="2" cellspacing="0" width="100%">
+ <tr class="topBar">
+ <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
+ <a href="home.html">Home</a> > <a href="tutorials.html">Tutorials</a> > <a href="getting-started.html">Getting Started</a> > <a href="form-validation-using-xml.html">Form Validation Using XML</a>
+ </td>
+ <td align="right" valign="middle" nowrap>
+ <form name="search" action="http://www.google.com/search" method="get">
+ <input type="hidden" name="ie" value="UTF-8" />
+ <input type="hidden" name="oe" value="UTF-8" />
+ <input type="hidden" name="domains" value="" />
+ <input type="hidden" name="sitesearch" value="" />
+ <input type="text" name="q" maxlength="255" value="" />
+ <input type="submit" name="btnG" value="Google Search" />
+ </form>
+ </td>
+ </tr>
+</table>
+
+<div id="PageContent">
+ <div class="pageheader" style="padding: 6px 0px 0px 0px;">
+ <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
+ <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
+ <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
+ <div style="margin: 0px 10px 8px 10px" class="pagetitle">Form Validation Using XML</div>
+
+ <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
+ <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=20644608">
+ <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=20644608">Edit Page</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
+ <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=20644608">
+ <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=20644608">Add Page</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=20644608">
+ <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=20644608">Add News</a>
+ </div>
+ </div>
+
+ <div class="pagecontent">
+ <div class="wiki-content">
+ <div id="ConfluenceContent"><div class="panelMacro"><table class="infoMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1">The example code for this tutorial, form_xml_validation, is available for checkout at <a shape="rect" class="external-link" href="https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/">https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/</a></td></tr></table></div>
+
+<h3><a shape="rect" name="FormValidationUsingXML-Introduction"></a>Introduction</h3>
+<p>In this tutorial we'll cover how to validate a user's input in form fields using Struts 2's XML validation methodology. In the <a shape="rect" href="form-validation.html" title="Form Validation">Form Validation</a> tutorial we discussed validating a user's input using the validate method in the Action class. Using a separate XML validation file gives you the ability to use validators built-in to the Struts 2 framework.</p>
+
+<div class="panelMacro"><table class="tipMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/check.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1">The <a shape="rect" class="external-link" href="http://struts.apache.org/mail.html">Struts 2 user mailing list</a> is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.</td></tr></table></div>
+
+<h3><a shape="rect" name="FormValidationUsingXML-ExampleApplication"></a>Example Application</h3>
+<p>The example application that supports this tutorial shows how to use Struts 2's XML validation methodology. The information that can be edited is encapsulated in an object of class Person. </p>
+
+<p>To enable the user to edit his information that is stored in the Person object, we have this form:</p>
+
+<p><span class="image-wrap" style=""><img src="form-validation-using-xml.data/Screen+shot+2010-05-05+at+10.05.14+AM.png" style="border: 1px solid black"></span></p>
+
+<p>When the user submits the form, we want to validate his entries into the form fields. </p>
+
+<h3><a shape="rect" name="FormValidationUsingXML-ValidationUsingXML"></a>Validation Using XML</h3>
+<p>To validate a user's form field entries you can use a separate XML file that contains your validation rules. The XML file that contains the validation rules must be named as ActionClassName-validation.xml. In the example application, the XML validation file is named EditAction-validation.xml (see src/main/resources/org/apache/struts/edit/action).</p>
+
+<p>Struts 2 provides several different validators that you can use in the XML validation file. See <a shape="rect" href="validation.html" title="Validation">Validation</a> for a list of validators you can employ.</p>
+
+<p>In the above form, we want to ensure the user enters a first name. To have the Struts 2 framework enforce that rule we can used the Struts 2 <a shape="rect" href="requiredstring-validator.html" title="requiredstring validator">requiredstring validator</a>. This validator checks that the user has entered a string value in the form field.</p>
+
+<h3><a shape="rect" name="FormValidationUsingXML-XMLValidatorFormat"></a>XML Validator Format</h3>
+<p>In the XML validation file (for this example that is EditAction-validation.xml), is this XML:</p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>XML Validator Required String</b></div><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+
+<!DOCTYPE validators PUBLIC
+"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+<validators>
+ <validator type="requiredstring">
+ <param name="fieldname">personBean.firstName</param>
+ <message>First name is required.</message>
+ </validator>
+</validators>
+
+]]></script>
+</div></div>
+
+<p>Within the validators node you can have 1 or more validator nodes. The type attribute specifies which validator you want the Struts 2 framework to use (see <a shape="rect" href="validation.html" title="Validation">Validation</a>). The param name="fieldname" node is used to tell the framework which form field entry to apply the rule to. See edit.jsp for the form fields and their name value (review <a shape="rect" href="struts-2-form-tags.html" title="Struts 2 Form Tags">Struts 2 Form Tags</a> if you're not familiar with how to use Struts 2 form tags). The message node is used to tell the framework what message to display if the validation fails.</p>
+
+<div class="panelMacro"><table class="tipMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/check.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1">There are alternate ways to write the XML that goes in the validation XML file. See <a shape="rect" href="validation.html" title="Validation">Validation</a> in the Struts 2 documentation for a full discussion.</td></tr></table></div>
+
+<p>For example if the user doesn't enter a value in the first name form field and clicks on the Save Changes button, he will see the following.</p>
+
+<p><span class="image-wrap" style=""><img src="form-validation-using-xml.data/Screen+shot+2010-05-05+at+10.25.38+AM.png" style="border: 1px solid black"></span></p>
+
+<h3><a shape="rect" name="FormValidationUsingXML-ValidatingAnEmailAddress"></a>Validating An Email Address</h3>
+<p>You can use the Struts 2 <a shape="rect" href="email-validator.html" title="email validator">email validator</a> to validate the user's input in the email field. Here is the validator node that is in the EditAction-validation.xml file.</p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Email Validator</b></div><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+
+ <validator type="requiredstring">
+ <param name="fieldname">personBean.email</param>
+ <message>Email address is required.</message>
+ </validator>
+ <validator type="email">
+ <param name="fieldname">personBean.email</param>
+ <message>Email address not valid.</message>
+ </validator>
+
+]]></script>
+</div></div>
+
+<p>Note that in the example, we are requiring the user to enter an email address and then validating the email address the user entered.</p>
+
+<h3><a shape="rect" name="FormValidationUsingXML-ValidatingAUser%27sInputUsingARegularExpression"></a>Validating A User's Input Using A Regular Expression</h3>
+<p>The Struts 2 framework provides a powerful way to validate a user's form field input by using the <a shape="rect" href="regex-validator.html" title="regex validator">regex validator</a>. In the example application, we want to ensure the user enters the phone number in the format 999-999-9999. We can use a regular expression and the <a shape="rect" href="regex-validator.html" title="regex validator">regex validator</a> to enforce this rule.</p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>REGEX Validator</b></div><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+
+<validator type="requiredstring">
+ <param name="fieldname">personBean.phoneNumber</param>
+ <message>Phone number is required.</message>
+ </validator>
+<validator type="regex">
+ <param name="fieldname">personBean.phoneNumber</param>
+ <param name="expression"><![CDATA[\d{3}-\d{3}-\d{4}]]></param>
+ <message>Phone number must be entered as 999-999-9999.</message>
+</validator>
+
+]]></script>
+</div></div>
+
+<p>The param name="expression" node is used to specify the regular expression that will be applied to the user's input. Note how the regular expression is contained within a CDATA section.</p>
+
+<h3><a shape="rect" name="FormValidationUsingXML-ValidatingAUser%27sInputUsingAnOGNLExpression"></a>Validating A User's Input Using An OGNL Expression</h3>
+<p>In the example application, we want to ensure the user checks at least one of the car model check boxes. To enforce this rule we can use the <a shape="rect" href="fieldexpression-validator.html" title="fieldexpression validator">fieldexpression validator</a>. Here's the XML for that validator node.</p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>FieldExpression Validator</b></div><div class="codeContent panelContent">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+
+<validator type="fieldexpression">
+ <param name="fieldname">personBean.carModels</param>
+ <param name="expression"><![CDATA[personBean.carModels.length > 0]]></param>
+ <message>You must select at least one car model.</message>
+</validator>
+
+]]></script>
+</div></div>
+
+<p>The param name="expression" node contains an OGNL expression that evaluates to true or false. We haven't previously discussed OGNL, which stands for Object-Graph Navigation Language (see <a shape="rect" class="external-link" href="http://www.opensymphony.com/ognl/" rel="nofollow">http://www.opensymphony.com/ognl/</a> and <a shape="rect" href="ognl.html" title="OGNL">OGNL</a>). OGNL expressions can be evaluated by the Struts 2 framework as Java statements. </p>
+
+<p>In the above XML the value of the param name="expression" node, personBean.carModels.length > 0, will be evaluated by the framework as a Java statement. The part personBean.carModels tells the framework to call the getCarModels method of class Person. That method returns an Array. Since class Array has a length attribute, the framework will get the value of the length attribute of the Array returned by the getCarModels method.</p>
+
+<p>If the user did not check any of the check boxes, the Array returned by the getCarModels method will have a length value of 0. Since the complete OGNL expression will only evaluate to true if the length value is greater than 0, the validation fails. The user will see this.</p>
+
+<p><span class="image-wrap" style=""><img src="form-validation-using-xml.data/Screen+shot+2010-05-05+at+10.45.18+AM.png" style="border: 1px solid black"></span></p>
+
+
+<p>The fieldexpression validator is useful when doing conditional validation of a user's input. If the OGNL expression doesn't evaluate to true then the user's input won't be allowed.</p>
+
+<h3><a shape="rect" name="FormValidationUsingXML-Summary"></a>Summary</h3>
+<p>The Struts 2 framework provides easy-to-use validation methodologies. You can add a validate method to the Action class or have a separate XML file with validation rules or you can use a combination of both methodologies.</p>
+
+<h3><a shape="rect" name="FormValidationUsingXML-UpNext"></a>Up Next</h3>
+
+<p>In our next tutorial we'll cover how to enable one action node in struts.xml to respond to several different action URLs.</p>
+
+<div class="table-wrap">
+<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"> Next </th><td colspan="1" rowspan="1" class="confluenceTd"> Onward to <a shape="rect" href="wildcard-method-selection.html" title="Wildcard Method Selection">Wildcard Method Selection</a> </td></tr></tbody></table>
+</div>
+
+</div>
+ </div>
+
+
+ </div>
+</div>
+<div class="footer">
+ Generated by CXF SiteExporter
+</div>
+</body>
+</html>
\ No newline at end of file
Added: websites/production/struts/content/development/2.x/docs/formatting-dates-and-numbers.html
==============================================================================
--- websites/production/struts/content/development/2.x/docs/formatting-dates-and-numbers.html (added)
+++ websites/production/struts/content/development/2.x/docs/formatting-dates-and-numbers.html Wed Jul 17 09:31:08 2013
@@ -0,0 +1,217 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<html>
+<head>
+ <LINK type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
+ <style type="text/css">
+ .dp-highlighter {
+ width:95% !important;
+ }
+ </style>
+ <style type="text/css">
+ .footer {
+ background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
+ background-repeat: repeat-x;
+ background-position: left top;
+ padding-top: 4px;
+ color: #666;
+ }
+ </style>
+ <link href='http://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
+ <link href='http://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
+ <script src='http://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
+ <script src='http://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
+
+ <script type="text/javascript">
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
+ <script type="text/javascript" language="javascript">
+ var hide = null;
+ var show = null;
+ var children = null;
+
+ function init() {
+ /* Search form initialization */
+ var form = document.forms['search'];
+ if (form != null) {
+ form.elements['domains'].value = location.hostname;
+ form.elements['sitesearch'].value = location.hostname;
+ }
+
+ /* Children initialization */
+ hide = document.getElementById('hide');
+ show = document.getElementById('show');
+ children = document.all != null ?
+ document.all['children'] :
+ document.getElementById('children');
+ if (children != null) {
+ children.style.display = 'none';
+ show.style.display = 'inline';
+ hide.style.display = 'none';
+ }
+ }
+
+ function showChildren() {
+ children.style.display = 'block';
+ show.style.display = 'none';
+ hide.style.display = 'inline';
+ }
+
+ function hideChildren() {
+ children.style.display = 'none';
+ show.style.display = 'inline';
+ hide.style.display = 'none';
+ }
+ </script>
+ <title>Formatting Dates and Numbers</title>
+</head>
+<body onload="init()">
+<table border="0" cellpadding="2" cellspacing="0" width="100%">
+ <tr class="topBar">
+ <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
+ <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="core-developers-guide.html">Core Developers Guide</a> > <a href="formatting-dates-and-numbers.html">Formatting Dates and Numbers</a>
+ </td>
+ <td align="right" valign="middle" nowrap>
+ <form name="search" action="http://www.google.com/search" method="get">
+ <input type="hidden" name="ie" value="UTF-8" />
+ <input type="hidden" name="oe" value="UTF-8" />
+ <input type="hidden" name="domains" value="" />
+ <input type="hidden" name="sitesearch" value="" />
+ <input type="text" name="q" maxlength="255" value="" />
+ <input type="submit" name="btnG" value="Google Search" />
+ </form>
+ </td>
+ </tr>
+</table>
+
+<div id="PageContent">
+ <div class="pageheader" style="padding: 6px 0px 0px 0px;">
+ <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
+ <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
+ <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
+ <div style="margin: 0px 10px 8px 10px" class="pagetitle">Formatting Dates and Numbers</div>
+
+ <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
+ <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=75443">
+ <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=75443">Edit Page</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
+ <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=75443">
+ <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=75443">Add Page</a>
+
+ <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=75443">
+ <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
+ height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
+ <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=75443">Add News</a>
+ </div>
+ </div>
+
+ <div class="pagecontent">
+ <div class="wiki-content">
+ <div id="ConfluenceContent"><h2><a shape="rect" name="FormattingDatesandNumbers-DefiningFormats"></a>Defining Formats</h2>
+<p>Struts2 supports localization (l10n) aware formatting of dates, times and numbers very easily, utilizing Java's built-in date formatting features.</p>
+
+<p>As seen in the <a shape="rect" href="localization.html" title="Localization">Localization</a> chapter, it is quite easy to define hierarchical resource bundles with Struts2, giving the developer the opportunity to define locale dependent message formats. This is the entry point to define the needed date, time and number formats. Your default properties could contain the following generic formats:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+format.time = {0,time}
+format.number = {0,number,#0.0##}
+format.percent = {0,number,##0.00'%'}
+format.money = {0,number,\u00A4##0.00}
+]]></script>
+</div></div>
+<p>An appropriate en_US format definition extension could look like this:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+format.date = {0,date,MM/dd/yy}
+]]></script>
+</div></div>
+<p>In parallel, you could add the following to your de_DE bundle:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+format.date = {0,date,dd.MM.yyyy}
+]]></script>
+</div></div>
+<p>Read more on how to define message formats in Sun's Java API docs for <a shape="rect" class="external-link" href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html" rel="nofollow">MessageFormat</a>.</p>
+
+<p>Now that we have our formats set up, it is quite easy to use them in our views.</p>
+
+<h2><a shape="rect" name="FormattingDatesandNumbers-Formattingoutputusingthes%3Atexttag"></a>Formatting output using the s:text tag</h2>
+
+<p>Given you had a Float value myMoneyValue, accessible through the getter getMyMoneyValue in your action, the following code would print out localized representation of the value as a currency amount, using the format.money message format defined above with a <a shape="rect" href="text.html" title="text">s:text</a> tag:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+<s:text name="format.money">
+ <s:param name="value" value="myMoneyValue"/>
+</s:text>
+]]></script>
+</div></div>
+<p>The (first) parameter defines the value which is to replace the '0' placeholder in the defined message format.<br clear="none">
+Another example, formatting a date value:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+<s:text name="format.date"><s:param value="dueDate"/></s:text>
+]]></script>
+</div></div>
+<div class="panelMacro"><table class="noteMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/warning.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1">While the s:text tag is very useful to format numbers, date formatting has become a lot easier thanks to the <a shape="rect" href="date.html" title="date">s:date</a> tag.</td></tr></table></div>
+
+<h2><a shape="rect" name="FormattingDatesandNumbers-LocalizingformdatawithgetText"></a>Localizing form data with getText</h2>
+<p>Placing a textfield in a form like this</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+<s:textfield key="orderItem.price" />
+]]></script>
+</div></div>
+<p>to input a number, one might have noticed that the number is always shown in the Java default number format. Not only that this is not "nice", if you are in a non-en locale, it will also cause trouble when submitting the form since type conversion is locale aware. The solution is to again use the message formats as defined above, by using the getText Method of ActionSupport:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+<s:textfield key="orderItem.price" value="%{getText('format.number',{orderItem.price})}" />
+]]></script>
+</div></div>
+<p>This maps to the method signature getText( String key, Object[] params ) in ActionSupport.</p>
+
+<h2><a shape="rect" name="FormattingDatesandNumbers-UsinggetFormatted%28%29withconversionsupport"></a>Using getFormatted() with conversion support</h2>
+<p>A new method getFormatted was added to ActionSupport (which can be implemented in your base action) to support formatting and conversion errors with I10N.<br clear="none">
+You can place a code like below</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+<s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />
+]]></script>
+</div></div>
+<p>to get support for I10N and also to support conversion errors.</p></div>
+ </div>
+
+
+ </div>
+</div>
+<div class="footer">
+ Generated by CXF SiteExporter
+</div>
+</body>
+</html>
\ No newline at end of file