Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
Struts 2, file tag, accept attribute not working?

Struts 2, file tag, accept attribute not working?

2007-11-03       - By Martin Gainty

 Back
Reply:     1     2  

you have been provided a working solution..

If you feel the accept attribute does'nt perform the behaviour you expect
you may
1)File a JIRA saying this tag isnt accomplishing the expected behaviour
https://issues.apache.org/struts/secure/Dashboard.jspa

2)Download the Tag source and modify to your requirements
http://svn.apache.org/viewvc/struts/struts2/tags/

Good Luck/
Martin--
-- -- Original Message -- --
From: "Anton Pussep" <anton-ml@(protected)>
To: "Struts Users Mailing List" <user@(protected)>
Sent: Saturday, November 03, 2007 1:11 PM
Subject: Re: Struts 2, file tag, accept attribute not working?


> Modifying FileUploadInterceptor or settings its parameters in struts.xml
> is not a proper solution since I have two s:file fields in my form and
> both require different content types. I am not looking for a work
> around, I rather have the question:
>
> Is the accept attribute working at all and if it does, why isn't it
> working for me?
>
> Best,
> Anton
>
> Martin Gainty wrote:
> > Anton-
> >
> > I had to take a break to find some paying work which didnt happen..
> >
> > struts.xml includes your web application specific xml I call it
> > YourWebApp.xml
> > <include file="YourWebApp.xml" />
> >
> > YourWebApp.xml includes a basicStack which includes fileUpload
> > <struts>
> >  <package name="YourWebApp" extends="struts-default"
> > namespace="/YourWebApp">
> >   <interceptors>
> >             <interceptor name="fileUpload"
> > class="org.apache.struts2.interceptor.FileUploadInterceptor"/>
> >         <!-- Basic stack -->
> >             <interceptor-stack name="basicStack">
> >                 <interceptor-ref name="fileUpload"/>
> >
> > so if you modify the allowedTypes in FileUploadInterceptor.java to
include
> > ONLY the types you want
> >
> > package org.apache.struts2.interceptor;
> >
> > import java.io.File;
> > import java.util.Collection;
> > import java.util.Collections;
> > import java.util.Enumeration;
> > import java.util.HashSet;
> > import java.util.Iterator;
> > import java.util.Locale;
> > import java.util.Map;
> > import java.util.Set;
> > import java.util.StringTokenizer;
> >
> > import javax.servlet.http.HttpServletRequest;
> >
> > import org.apache.commons.logging.Log;
> > import org.apache.commons.logging.LogFactory;
> > import org.apache.struts2.ServletActionContext;
> > import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
> >
> > import com.opensymphony.xwork2.ActionContext;
> > import com.opensymphony.xwork2.ActionInvocation;
> > import com.opensymphony.xwork2.ActionProxy;
> > import com.opensymphony.xwork2.ValidationAware;
> > import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
> > import com.opensymphony.xwork2.util.LocalizedTextUtil;
> >
> > /**
> >  * <!-- START SNIPPET: description -->
> >  *
> >  * Interceptor that is based off of {@(protected) MultiPartRequestWrapper},
which
> > is automatically applied for any request that
> >  * includes a file. It adds the following parameters, where [File Name]
is
> > the name given to the file uploaded by the
> >  * HTML form:
> >  *
> >  * <ul>
> >  *
> >  * <li>[File Name] : File - the actual File</li>
> >  *
> >  * <li>[File Name]ContentType : String - the content type of the
file</li>
> >  *
> >  * <li>[File Name]FileName : String - the actual name of the file
uploaded
> > (not the HTML name)</li>
> >  *
> >  * </ul>
> >  *
> >  * <p/> You can get access to these files by merely providing setters in
> > your action that correspond to any of the three
> >  * patterns above, such as setDocument(File document),
> > setDocumentContentType(String contentType), etc.
> >  * <br/>See the example code section.
> >  *
> >  * <p/> This interceptor will add several field errors, assuming that
the
> > action implements {@(protected) ValidationAware}.
> >  * 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:
> >  *
> >  * <ul>
> >  *
> >  * <li>struts.messages.error.uploading - a general error that occurs
when
> > the file could not be uploaded</li>
> >  *
> >  * <li>struts.messages.error.file.too.large - occurs when the uploaded
file
> > is too large</li>
> >  *
> >  * <li>struts.messages.error.content.type.not.allowed - occurs when the
> > uploaded file does not match the expected
> >  * content types specified</li>
> >  *
> >  * </ul>
> >  *
> >  * <!-- END SNIPPET: description -->
> >  *
> >  * <p/> <u>Interceptor parameters:</u>
> >  *
> >  * <!-- START SNIPPET: parameters -->
> >  *
> >  * <ul>
> >  *
> >  * <li>maximumSize (optional) - the maximum size (in bytes) that the
> > interceptor will allow a file reference to be set
> >  * on the action. Note, this is <b>not</b> related to the various
properties
> > found in struts.properties.
> >  * Default to approximately 2MB.</li>
> >  *
> >  * <li>allowedTypes (optional) - a comma separated list of content types
> > (ie: text/html) that the interceptor will allow
> >  * a file reference to be set on the action. If none is specified allow
all
> > types to be uploaded.</li>
> >  *
> >  * </ul>
> >  *
> >  * <!-- END SNIPPET: parameters -->
> >  *
> >  * <p/> <u>Extending the interceptor:</u>
> >  *
> >  * <p/>
> >  *
> >  * <!-- START SNIPPET: extending -->
> >  *
> >  * You can extend this interceptor and override the {@(protected) #acceptFile}
> > method to provide more control over which files
> >  * are supported and which are not.
> >  *
> >  * <!-- END SNIPPET: extending -->
> >  *
> >  * <p/> <u>Example code:</u>
> >  *
> >  * <pre>
> >  * <!-- START SNIPPET: example -->
> >  * &lt;action name="doUpload" class="com.examples.UploadAction"&gt;
> >  *     &lt;interceptor-ref name="fileUpload"/&gt;
> >  *     &lt;interceptor-ref name="basicStack"/&gt;
> >  *     &lt;result name="success"&gt;good_result.ftl&lt;/result&gt;
> >  * &lt;/action&gt;
> >  * </pre>
> >  *
> >  * And then you need to set encoding <code>multipart/form-data</code> in
the
> > form where the user selects the file to upload.
> >  * <pre>
> >  *   &lt;a:form action="doUpload" method="post"
> > enctype="multipart/form-data"&gt;
> >  *       &lt;a:file name="upload" label="File"/&gt;
> >  *       &lt;a:submit/&gt;
> >  *   &lt;/a:form&gt;
> >  * </pre>
> >  *
> >  * And then in your action code you'll have access to the File object if
you
> > provide setters according to the
> >  * naming convention documented in the start.
> >  *
> >  * <pre>
> >  *    public com.examples.UploadAction implements Action {
> >  *       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;
> >  *       }
> >  *
> >  *       ...
> >  *  }
> >  * </pre>
> >  * <!-- END SNIPPET: example -->
> >  *
> >  */
> > public class FileUploadInterceptor extends AbstractInterceptor {
> >
> >  private static final long serialVersionUID = -4764627478894962478L;
> >
> >  protected static final Log log =
> > LogFactory.getLog(FileUploadInterceptor.class);
> >     private static final String DEFAULT_DELIMITER = ",";
> >     private static final String DEFAULT_MESSAGE = "no.message.found";
> >
> >     protected Long maximumSize;
> >     protected String allowedTypes="html,xml"; //modify this
> >
> > ...
> > } //end class
> >
> > Viel Gluck/
> > Martin
> > -- -- Original Message -- --
> > From: "Anton Pussep" <anton-ml@(protected)>
> > To: "Struts Users Mailing List" <user@(protected)>
> > Sent: Friday, November 02, 2007 12:03 PM
> > Subject: Re: Struts 2, file tag, accept attribute not working?
> >
> >
> >> There is no s:head tag, since I am not using Ajax. Thus it should be
the
> >> default xhtml.
> >>
> >> Best,
> >> Anton
> >>
> >> Martin Gainty wrote:
> >>> Hi Anton
> >>>
> >>> which theme is specified in your s:head tag?
> >>>
> >>> Martin-
> >>> -- -- Original Message -- --
> >>> From: "Anton Pussep" <anton-ml@(protected)>
> >>>
> >>> To: "Struts Users Mailing List" <user@(protected)>
> >>> Sent: Friday, November 02, 2007 6:03 AM
> >>> Subject: Struts 2, file tag, accept attribute not working?
> >>>
> >>>
> >>>> Hello,
> >>>>
> >>>> I am using the following tag for uploading text files:
> >>>>
> >>>> <s:file name="myDoc" accept="text/plain" />
> >>>>
> >>>> I expected it to recognise wrong content types, but it accepts any
> > files
> >>>> I upload. What might be the problem here?
> >>>>
> >>>> I tried this with Struts 2.0.9 and 2.0.11.
> >>>>
> >>>> Best,
> >>>> Anton
> >>>>
> >>>>
> >>>>
> >>>> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
> >>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
> >>>> For additional commands, e-mail: user-help@(protected)
> >>>>
> >>>>
> >>> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
> >>> To unsubscribe, e-mail: user-unsubscribe@(protected)
> >>> For additional commands, e-mail: user-help@(protected)
> >>>
> >>>
> >>>
> >>
> >> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
> >> To unsubscribe, e-mail: user-unsubscribe@(protected)
> >> For additional commands, e-mail: user-help@(protected)
> >>
> >>
> >
> >
> >
>
>
> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>


-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.