You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2004/01/08 17:20:45 UTC

cvs commit: jakarta-struts/web/examples/upload upload.jsp upload-utf8.jsp display.jsp

husted      2004/01/08 08:20:45

  Added:       web/examples/upload upload.jsp upload-utf8.jsp display.jsp
  Log:
  Place web assets for upload module under examples.
  
  Revision  Changes    Path
  1.1                  jakarta-struts/web/examples/upload/upload.jsp
  
  Index: upload.jsp
  ===================================================================
  <%@ page import="org.apache.struts.action.*,
                   java.util.Iterator,
                   org.apache.struts.webapp.upload.UploadForm, 
                   org.apache.struts.Globals" %><%@ taglib uri="/tags/struts-bean" prefix="bean" %><%@ taglib uri="/tags/struts-html" prefix="html" %><%@ taglib uri="/tags/struts-logic" prefix="logic" %>
  <html>
    <head>
      <title>File Upload Example</title>
    </head>
    <body>
      <!-- Find out if the maximum length has been exceeded. -->
      <logic:present name="<%= Globals.ERROR_KEY %>" scope="request">
        <%
                ActionErrors errors = (ActionErrors) request.getAttribute(Globals.ERROR_KEY);
                //note that this error is created in the validate() method of UploadForm
                Iterator iterator = errors.get(UploadForm.ERROR_PROPERTY_MAX_LENGTH_EXCEEDED);
                //there's only one possible error in this
                ActionError error = (ActionError) iterator.next();
                pageContext.setAttribute("maxlength.error", error, PageContext.REQUEST_SCOPE);
            %>
      </logic:present>
      <!-- If there was an error, print it out -->
      <logic:present name="maxlength.error" scope="request">
        <font color="red">
          <bean:message name="maxlength.error" property="key" />
        </font>
      </logic:present>
      <logic:notPresent name="maxlength.error" scope="request">Note that the maximum allowed size of an uploaded file for this application is two megabytes. See the /WEB-INF/struts-config.xml file for this application to change it.</logic:notPresent>
      <br />
      <br />
      <!--
              The most important part is to declare your form's enctype to be "multipart/form-data",
              and to have a form:file element that maps to your ActionForm's FormFile property
      -->
      <html:form action="upload-submit.do?queryParam=Successful" enctype="multipart/form-data">Please enter some text, just to demonstrate the handling of text elements as opposed to file elements:
      <br />
      <html:text property="theText" />
      <br />
      <br />Please select the file that you would like to upload:
      <br />
      <html:file property="theFile" />
      <br />
      <br />If you would rather write this file to another file, please check here: 
      <html:checkbox property="writeFile" />
      <br />
      <br />If you checked the box to write to a file, please specify the file path here:
      <br />
      <html:text property="filePath" />
      <br />
      <br />
      <html:submit /></html:form>
    </body>
  </html>
  
  
  
  1.1                  jakarta-struts/web/examples/upload/upload-utf8.jsp
  
  Index: upload-utf8.jsp
  ===================================================================
  <%@ page contentType="text/html; charset=utf-8" %><%@ taglib uri="/tags/struts-html" prefix="html" %>
  <html>
    <head>
      <title>utf-8 upload page</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    </head>
    <body>
      <!--
              The most important part is to declare your form's enctype to be "multipart/form-data",
              and to have a form:file element that maps to your ActionForm's FormFile property
      -->
      <html:form action="upload-submit.do" enctype="multipart/form-data">Please enter some text, just to demonstrate the handling of text elements as opposed to file elements:
      <br />
      <html:text property="theText" />
      <br />
      <br />Please select the file that you would like to upload:
      <br />
      <html:file property="theFile" />
      <br />
      <br />If you would rather write this file to another file, please check here: 
      <html:checkbox property="writeFile" />
      <br />
      <br />If you checked the box to write to a file, please specify the file path here:
      <br />
      <html:text property="filePath" />
      <br />
      <br />
      <html:submit /></html:form>
    </body>
  </html>
  
  
  
  1.1                  jakarta-struts/web/examples/upload/display.jsp
  
  Index: display.jsp
  ===================================================================
  <b>The Text</b><%= request.getAttribute("text") %>
  <br />
  <b>The Query Parameter</b><%= request.getAttribute("queryValue") %>
  <br />
  <b>The File name</b><%= request.getAttribute("fileName") %>
  <br />
  <b>The File content type</b><%= request.getAttribute("contentType") %>
  <br />
  <b>The File size</b><%= request.getAttribute("size") %>
  <br />
  <b>The File data</b>
  <br />
  <hr />
  <pre>
  <%= request.getAttribute("data") %>
  </pre>
  <hr />
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org