• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can i restrict the selecting file type to XML and TXT in file upload..

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using Struts Upload Bean. I am also using html:file tag in the JSP. Now when i click on the browse button, A file dialogue window appears. The problem id the i want to show only text and xml files in the dialog box. Now the files of type combo box in the dialogue box is showing *.*, *.html, *.pictures (jpg/gif) options. In place of this i need to show only txt and xml files. How can i restrict the file type to XML and TXT

Regards,
Sudheesh...
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, there is unfortunately no such posibility.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try javscript validation some what like this

function checkFileExtension() {
//get the file extension in a variable
var extension = document.FBITT.ffAttachment.value;
var isValid = false;
var strExtensions="";
//alert("ext before while:"+ extension);
//substring
while(extension.indexOf('.') != -1) {
//alert("gkmkc");
//alert(extension.length);
//alert(extension.indexOf('.'));
extension = extension.substring((extension.indexOf('.')+1), extension.length);
//alert("ext :"+ extension);
//alert("ext :"+ extension);
}
//alert("ext after while:"+ extension);

//iterate and valiadte against the arraylist in the formbean
<%
//i hate to do this, but alas.. may i think of a better way given the time...
sg.gov.sco.gebiz.webitt.formbean.itts.FBITT fbFBITT = (sg.gov.sco.gebiz.webitt.formbean.itts.FBITT) request.getSession(false).getAttribute("FBITT");
for(int i=0; i<fbFBITT.getArrValidFileExtensions().size(); i++) {
%>
var validExtensionU = '<%=((String)fbFBITT.getArrValidFileExtensions().get(i)).toUpperCase()%>';
var validExtensionL = '<%=((String)fbFBITT.getArrValidFileExtensions().get(i)).toLowerCase()%>';
strExtensions = strExtensions + validExtensionL + ", ";
//make this case independent in java script
//alert(validExtension)
if(extension==validExtensionU || extension == validExtensionL) {
//set isValid to true, though redundant
isValid = true;
}
<% } %>

if(isValid==false) {
alert("Please select a file with one of the following file extension:\n"+strExtensions.substring(0, strExtensions.length-2));
}
//alert("isValid :"+isValid);
return isValid;
} //checkFileExtension-ends
 
Sudheesh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sirs,
Thank you very much for your replies. Infact I am planning to call a validation function to check the file extension using Java Script. Anyway thank you very mush for your suggestions...

Regards

Sudheesh K S
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic