FileDocCategorySizeDatePackage
File.javaAPI DocExample3711Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

File

public class File extends UIBean
Renders an HTML file input element.

Examples


<s:file name="anUploadFile" accept="text/*" />
<s:file name="anohterUploadFIle" accept="text/html,text/plain" />

Fields Summary
private static final Log
log
public static final String
TEMPLATE
protected String
accept
protected String
size
Constructors Summary
public File(com.opensymphony.xwork2.util.ValueStack stack, HttpServletRequest request, HttpServletResponse response)


           
        super(stack, request, response);
    
Methods Summary
public voidevaluateParams()

        super.evaluateParams();

        Form form = (Form) findAncestor(Form.class);
        if (form != null) {
            String encType = (String) form.getParameters().get("enctype");
            if (!"multipart/form-data".equals(encType)) {
                // uh oh, this isn't good! Let's warn the developer
                log.warn("Struts has detected a file upload UI tag (s:file) being used without a form set to enctype 'multipart/form-data'. This is probably an error!");
            }

            String method = (String) form.getParameters().get("method");
            if (!"post".equalsIgnoreCase(method)) {
                // uh oh, this isn't good! Let's warn the developer
                log.warn("Struts has detected a file upload UI tag (s:file) being used without a form set to method 'POST'. This is probably an error!");
            }
        }

        if (accept != null) {
            addParameter("accept", findString(accept));
        }

        if (size != null) {
            addParameter("size", findString(size));
        }
    
protected java.lang.StringgetDefaultTemplate()

        return TEMPLATE;
    
public voidsetAccept(java.lang.String accept)

        this.accept = accept;
    
public voidsetSize(java.lang.String size)

        this.size = size;