Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: how to get value path file from jsp form- input type file

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to get value path file from jsp form- input type file

    hello , i have problem which i need to get path file if i select from my pc. from my code the value that i could get just name of the file not full path of the file. here is my code.
    i hope could somebody help me to pass the value input type file from form1.jsp file to attach.jsp file.

    form1.jsp
     <FORM name="FileForm"  ACTION="attach.jsp" METHOD=POST >
                <br><br><br><center>
                    <table border="0" bgcolor=#ccFDDEE><tr>
     
                            <td colspan="2" align="center"><B>UPLOAD THE FILE</B>
     
                                </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center"> </td>
                        </tr>
                    <tr>
                        <td><b>Choose the file To Upload:</b></td>
                        <td>
                            <INPUT NAME="file1" TYPE="file" >
    </td></tr>
     
     
     
     
                    <tr><td colspan="2" align="center">
                            <input type="submit" value="Send File"> </td>
                    </tr>
                    <tr>
     
                    </tr>
                    </table>
                        </center>
                                </FORM>

    attach.jsp

       String filename = request.getParameter("file1");           
     
              System.out.println(filename);
              System.out.println(request.getParameter("email"));
              DataSource source = new FileDataSource(filename);
              messageBodyPart.setDataHandler(new DataHandler(source));
              messageBodyPart.setFileName(filename);
              multipart.addBodyPart(messageBodyPart);
     
              m.setContent(multipart);
     
              // Send the message
            //transport.send(m);
               System.out.println("Msg Send ....");


  2. #2
    Member
    Join Date
    Sep 2011
    Posts
    32
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: how to get value path file from jsp form- input type file

    Quote Originally Posted by meeGoreng View Post
    hello , i have problem which i need to get path file if i select from my pc. from my code the value that i could get just name of the file not full path of the file.
    Unfortunately, we couldn't get absolute path of the file on client. Why? Because it is security restriction in most browsers. My recent test shows that FireFox and Chrome returns only the file name, while IE 6 returns the whole absolute path.

    java memory
    Last edited by namhm; December 4th, 2011 at 06:54 PM.

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: how to get value path file from jsp form- input type file

    Are you sure, you placing the files at the correct directory of your local server (say tomcat or whatever you using)?

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to get value path file from jsp form- input type file

    actually i need pass the file that i select from my pc and then sent to my email. it means i cannot upload that file? i need save the file in to server first then server will pass the file to the email?
    it is correct ??

  5. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: how to get value path file from jsp form- input type file

    Kindly check the following links.
    May be these help you....
    1

    2

    3

    4

Similar Threads

  1. WHY AM I HAVING TO PUT THE ENTIRE FILE PATH?!?!
    By CameronHussey in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 7th, 2011, 05:32 AM
  2. locating the path to a jar file within a program
    By nemo in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 2nd, 2011, 05:41 PM
  3. Making computer independent file path
    By Javabeginner in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: September 2nd, 2010, 03:56 PM
  4. How to change File Type of a File Using java
    By akash169 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: March 31st, 2010, 02:58 AM
  5. Replies: 8
    Last Post: January 6th, 2010, 09:59 AM