Hi Sri so if the config is configured something like /WEB-INF/classes/struts-fileupload.xml <action name="doUpload" class="org.apache.struts2.showcase.fileupload.FileUploadAction" method="upload"> <result name="success">uploadSuccess.jsp</result> <result name="error">uploadError.jsp</result> </action>
and the jsp defines the acceptable content-type and a name to call it.. <s:file name="upload" accept="text/*" /> org.apache.struts2.portlet.example.fileupload.FileUploadAction.java { private String fileName; //this is the FULL pathname with filename // since we are using <s:file name="upload" .../> the file name will be obtained through getter/setter of <file-tag-name>FileName public String getUploadFileName() { return fileName; } public void setUploadFileName(String fileName) { this.fileName = fileName; } // since we are using <s:file name="upload" ... /> the File itself will be obtained through getter/setter of <file-tag-name> public File getUpload() { java.io.File file; try { //try to create the file with the previously provided filename file= new java.io.File( filename ); } catch(java.lang.NullPointerException excp) { return ERROR; } if(file.canRead()) return SUCCESS; else return ERROR; } public void setUpload(File upload) { this.upload = upload; } } I didnt test with the templateDir attribute.. HTH/ M- ----- Original Message ----- Wrom: FPEGAUTFJMVRESKPNKMBIPBARHDMNNSKVFVWRKJVZC To: "Struts Users Mailing List" <user@struts.apache.org> Sent: Wednesday, February 06, 2008 8:50 PM Subject: STRUTS 2: File tag problem Hello, I am using file tag works fine if a file is selected using browse button or the path is entered manually. But if file name/path is rubbish the form is not submitted at all, nothing happens. 1. How do I control this - show error like invalid filename? 2. Or else how to disable manual entry, only browse button works??????? 3. I tried javascript options like onKeypress to reset value to null - didnt help. Please help. Regards, Srikanth < s:form action = "/createEnt2.do" method = "POST" enctype = "multipart/form-data" validate = "true" > s:form action = "/createEnt2.do" method = "POST" enctype = "multipart/form-data" validate = "true" > < s:file name = "dc" id = "dc" accept = "text/*" label = "Digital Certificate" onkeydown = "return reset1();" /> < s:file name = "dc" id = "dc" accept = "text/*" label = "Digital Certificate" onkeydown = "return reset1();" /> </ </ s:form > </ </ s:form > function reset1() reset1() { var thisForm = document.forms[0]; thisForm.dc.value = 'all' ; window.alert( "sfds" ); thisForm = document.forms[0]; thisForm.dc.value = 'all' ; window.alert( "sfds" ); 'all' ; window.alert( "sfds" ); "sfds" ); } Java ########################### private File dc ; private String uploadContentType ; //The content type of the file private File dc ; private String uploadContentType ; //The content type of the file private String uploadContentType ; //The content type of the file private String uploadFileName ; //The uploaded file name /** private String uploadFileName ; //The uploaded file name /** /** * @return the dc * @return the dc */ */ public File getDc() { return dc ; } /** public File getDc() { return dc ; } /** return dc ; } /** /** * @param dc the dc to set * @param dc the dc to set */ */ public void setDc(File dc) { this . dc = dc; } /** public void setDc(File dc) { this . dc = dc; } /** this . dc = dc; } /** /** * @return the uploadContentType * @return the uploadContentType */ */ public String getUploadContentType() { return uploadContentType ; } /** public String getUploadContentType() { return uploadContentType ; } /** return uploadContentType ; } /** /** * @param uploadContentType the uploadContentType to set * @param uploadContentType the uploadContentType to set */ */ public void setUploadContentType(String uploadContentType) { this . uploadContentType = uploadContentType; } /** public void setUploadContentType(String uploadContentType) { this . uploadContentType = uploadContentType; } /** this . uploadContentType = uploadContentType; } /** /** * @return the uploadFileName * @return the uploadFileName */ */ public String getUploadFileName() { return uploadFileName ; } /** public String getUploadFileName() { return uploadFileName ; } /** return uploadFileName ; } /** /** * @param uploadFileName the uploadFileName to set * @param uploadFileName the uploadFileName to set */ */ public void setUploadFileName(String uploadFileName) { this . uploadFileName = uploadFileName; } public void setUploadFileName(String uploadFileName) { this . uploadFileName = uploadFileName; } this . uploadFileName = uploadFileName; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]