Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 28th, 2005, 05:16 AM
Registered User
 
Join Date: Apr 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ruchilalla
Default restrict the uploaded file to ACCEPT ONLY XML FIL

I need to restrict the uploaded file to only accept an xml file
in an html form tried writing
 <INPUT TYPE="file" NAME="myFile1" accept="text/xml"> but accepts all types of files

 
Old April 28th, 2005, 06:43 AM
Authorized User
 
Join Date: Apr 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jmukesh Send a message via Yahoo to jmukesh
Default

You need to check the file type through javascript.

/*To check file extensions */


function checkFileExtension( parafilevalue ){
  var file = parafilevalue.split('.');
  var validType = false;

  if( file.length < 2 ){
   return false;
  }

  var fileext = file[1].toLowerCase();
  if( fileext == 'xml' ) {
   validType = true;
  }

return validType;

 }



 
Old April 29th, 2005, 02:55 AM
Registered User
 
Join Date: Apr 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ruchilalla
Default

sending my code :unable to get the desired result,after adding the script i am still able to upload all types of files


<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="netui-tags-databinding.tld" prefix="netui-data"%>
<%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
<%@ taglib uri="netui-tags-template.tld" prefix="netui-template"%>
<netui:html>
    <head>
        <title>
            Web Application Page
        </title>

    </head>

     <body>


       <FORM NAME="myForm"
   ACTION="http://localhost:7008/IntgAppWeb/fwdservlet"
   ENCTYPE="multipart/form-data"
   METHOD="post">
   <INPUT type="file" name="myFile1" accept="text/xml" >

   <INPUT TYPE="submit" VALUE="Upload File" onclick="">
</FORM>
    </body>
</netui:html>




THANX

 
Old April 29th, 2005, 07:19 AM
Authorized User
 
Join Date: Apr 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jmukesh Send a message via Yahoo to jmukesh
Default

Hi

Check the code below

<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="netui-tags-databinding.tld" prefix="netui-data"%>
<%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
<%@ taglib uri="netui-tags-template.tld" prefix="netui-template"%>
<netui:html>
    <head>
        <title>
            Web Application Page
        </title>
    <script language="javascript">
    function checkFileExtension( parafilevalue ){
      var file = parafilevalue.split('.');
      var validType = false;

          if( file.length < 2 ){
           return false;
          }

          var fileext = file[1].toLowerCase();
          if( fileext == 'xml' ) {
               validType = true;
          }

        return validType;

     }

    function validateForm(){

        if( ! checkFileExtension(document.myForm.myFile1.value)) {
            alert('Please upload file with extension .xml');
            return false;
        }
        document.myForm.submit();

    }

    </script>


    </head>

     <body>


       <FORM NAME="myForm" ACTION="http://localhost:7008/IntgAppWeb/fwdservlet" ENCTYPE="multipart/form-data"
   METHOD="post">
   <INPUT type="file" name="myFile1" accept="text/xml" >

   <INPUT TYPE="button" VALUE="Upload File" onclick="validateForm()">
</FORM>
    </body>
</netui:html>







Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get Path of uploaded file in JSP murulikblr JSP Basics 0 April 17th, 2007 02:05 AM
Problem in adding the new element into the XML fil Somesh C# 3 February 6th, 2007 06:41 AM
Set the flag to the already uploaded fil kumanan .NET Framework 1.x 0 September 1st, 2006 10:13 AM
deleting a file after it is been uploaded yts007 Dreamweaver (all versions) 1 August 16th, 2006 01:05 AM
unable to restrict uploaded file to xml ruchilalla J2EE 2 July 14th, 2005 04:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.