Hi Martin, Thanks for the reply. I didnt quite get what you are trying to say. My code is exactly similar to the example you given except the implementation for method "public File getUpload()". In your example it return SUCCESS and ERROR which are strings but it should return File. I have only one line "return dc". Please help if I am missing something here. I tried to give some logic to getFileName() and getDc() (=getUpload()) methods but the issue is still there, if crap is typed into file field - nothing happens when submit is clicked.
Regards, Srikanth -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, 7 February 2008 1:50 PM To: Struts Users Mailing List Subject: Re: STRUTS 2: File tag problem 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]