UI for file-upload
[nobr]Dear friends,
I am trying to create a user-interface for file upload using java.Th interface is a simple Jsp form. The code for this form is as given below:
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<html:form action="UploadFile"
enctype="multipart/form-data" method="post">
Type some text (if you like):
<input type="text" name="txt" size="30">
Please specify a file, or a set of files:
<input type="file" name="url" size="40">
<div>
<input type="submit" value="Send">
</div>
</html:form>
How should i get the file in a bean?
The following is the code for my ActionForm class:
package uploadApp;
import java.io.File;
import org.apache.struts.action.ActionForm;
publicclass UploadFileExperimentFormextends ActionForm{
privatestaticfinallong serialVersionUID = 1;
protected String txt;
protected File url =new File("");
public String getTxt(){
return txt;
}
publicvoid setTxt(String txt){
this.txt = txt;
}
public File getUrl(){
return url;
}
publicvoid setUrl(File url){
this.url = url;
}
}
The following is the code for my Action class:
package uploadApp;
import java.io.File;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
publicclass UploadFileExperimentActionextends Action{
public ActionForward perform (ActionMapping mapping, ActionForm form,HttpServletRequest req, HttpServletResponse res){
//Cast form to Action form
UploadFileExperimentForm uf = (UploadFileExperimentForm)form;
String txt_Display ="";
File url_Display =new File("");
url_Display = uf.getUrl();
txt_Display = uf.getTxt();
if((url_Display ==null)&& (txt_Display ==null)){
System.out.println("Null value");
return mapping.findForward("UploadFailure");
}
else{
System.out.println("Got a string.");
return mapping.findForward("UploadSuccess");
}
}
}
[/nobr]

