Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
...
</form-beans>
<form-bean name="uploadForm" type="yourpackage.UploadForm" />
</form-beans>
<action-mappings>
<action attribute="uploadForm"
input="/upload.jsp"
name="uploadForm"
path="/upload"
scope="request"
type="yourpackage.UploadSubmit">
<forward name="success" path="/uploadComplete.jsp" />
</action>
</action-mappings>
...
<html:form action="/uploadSubmit" enctype="multipart/form-data">
<html:file property="file"/>
</html:form>
package yourpackage
public class UploadForm extends ActionForm {
private FormFile file;
public FormFile getFile() {
return file;
}
public void setFile(FormFile file) {
this.file = file;
}
}
public class UploadSubmit extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
UploadForm uploadForm = (UploadForm) form;
Hashtable files = uploadForm.getMultipartRequestHandler().getFileElements();
FormFile theFile = (FormFile) files.get("file");
InputStream stream = theFile.getInputStream();
File saveToFile = new File(theFile.getFileName());
OutputStream bos = new FileOutputStream(saveToFile);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
stream.close();
return mapping.findForward("success");
}
}
...
InputStream stream = theFile.getInputStream();
//assuming text file being uploaded and default platform
//encoding
InputStreamReader reader = new InputStreamReader(stream);
while (true) {
char c = (char) reader.read();
if (c==-1) {
break;
}
System.out.print(c);
}
...
while (true) {
int c = reader.read();
if (c==-1) {
break;
}
System.out.print((char)c);
}