From browse button of input type=file, can I show the content of a file

Hi all,
I am using, input type=file, where browse button appears. I am having a text area. My requirement is after I select the browse button, I need to show the content of the file in the text area. As of now I 've handled by having another button 'show', which should be pressed after browse done. But, How to handle it in the browse button itself, how will I get that action event from browse button. Plz help.
Regards,
Sam

I think someone asked a very similar question here,
http://forum.java.sun.com/thread.jsp?forum=45&thread=501889
check the thread, it may help you.
-S-

Similar Messages

  • FILE UPLOAD PROBLEM SHOWING THE CONTENTS IN THE SAME BROWSER WINDOW

    Hi,
    This is amit Joshi
    I have uploaded content using input tag of type file and posted to jsp as multipart/form-data type
    in that jsp i am using following code to display the content in browser but only first content is displayed How can i modify it to show all content in the file ..
    <html>
    <head>
    <title>File Upload Display</title>
    </head>
    <body>
    <%
    //ServletOutputStream sout=response.getOutputStream();
    StringBuilder strBuilder = new StringBuilder();
    int count=0;
    String f;
    f=request.getParameter("filedb");
    DBManager dbm = new DBManager();
    //dbm.createTable("mms3");
    //log.info("In JSP : "+ f);
    //dbm.insert_data(f,"mms3");
    %>
    <%
    if (ServletFileUpload.isMultipartContent(request)){
    ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
    List fileItemsList = servletFileUpload.parseRequest(request);
    strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append('\r').append('\n').append("<xpage version=\"1.0\">").append('\r').append('\n');
    String optionalFileName = "";
    FileItem fileItem = null;
    Iterator it = fileItemsList.iterator();
    ServletOutputStream outputStream=null;
    while (it.hasNext()){
    FileItem fileItemTemp = (FileItem)it.next();
    if (fileItemTemp.isFormField()){
    %>
    <b>Name-value Pair Info:</b>
    Field name: <%= fileItemTemp.getFieldName() %>
    Field value: <%= fileItemTemp.getString() %>
    <%
    if (fileItemTemp.getFieldName().equals("filename"))
    optionalFileName = fileItemTemp.getString();
    else
    fileItem = fileItemTemp;
    if (fileItem!=null){
    String fileName = fileItem.getName();
    %>
    <b>Uploaded File Info:</b>
    Content type: <%= fileItem.getContentType() %>
    Field name: <%= fileItem.getFieldName() %>
    File name: <%= fileName %>
    <%
    if(fileItem.getContentType().equals("image/jpeg")) { %>
    File : <p><%
         //response.setContentType("image/gif");
         byte[] bArray=fileItem.get();
         response.setContentType("image/jpeg");
         outputStream=null;
         outputStream= response.getOutputStream();
         outputStream.write(bArray);
         outputStream.flush();
         outputStream.close();
    else if(fileItem.getContentType().equals("text/plain"))
         %> File : <%= fileItem.getString() %>
    <%
    byte[] bArray=fileItem.get();
    response.setContentType("text/plain");
         outputStream = response.getOutputStream();
         out.println();
         outputStream.write(bArray);
         outputStream.flush();
         outputStream.close();
    %> </p> <%
    %>
    </body>
    </html>
    Edited by: Amit_Joshi on Nov 13, 2007 10:58 PM

    Well Well Well..
    That would not work...
    What you have to do is save the uploaded file content on to a location and then pass the fileName as a request parameter to a deidicated which displays the contents of that file.
    Just as an example
    <html>
    <head>
    <title>File Upload Display</title>
    </head>
    <body>
    <%
    //ServletOutputStream sout=response.getOutputStream();
    StringBuilder strBuilder = new StringBuilder();
    int count=0;
    String f;
    f=request.getParameter("filedb");
    DBManager dbm = new DBManager();
    //dbm.createTable("mms3");
    //log.info("In JSP : "+ f);
    //dbm.insert_data(f,"mms3");
    %>
    <%
    if (ServletFileUpload.isMultipartContent(request)){
    ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
    List fileItemsList = servletFileUpload.parseRequest(request);
    strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append('\r').append('\n').append("<xpage version=\"1.0\">").append('\r').append('\n');
    String optionalFileName = "";
    FileItem fileItem = null;
    Iterator it = fileItemsList.iterator();
    ServletOutputStream outputStream=null;
    while (it.hasNext()){
       FileItem fileItemTemp = (FileItem)it.next();
    %>
    Name-value Pair Info:
    Field name: <%= fileItemTemp.getFieldName() %><br/>
    Field value: <%= fileItemTemp.getString() %><br/>
    <%
    if (fileItemTemp.getFieldName().equals("filename"))
        optionalFileName = fileItemTemp.getString();
    if(!fileTempItem.isFormFiled()){
       String fileName = fileItem.getName();
       fileItem.write(optionalFileName);
    %>
    Uploaded File Info:
    Content type: <%= fileItem.getContentType() %><br/>
    Field name: <%= fileItem.getFieldName() %><br/>
    File name: <%= fileName %><br/>
    <%
    if(fileItem.getContentType().equals("image/jpeg") || fileItem.getContentType().equals("image/pjeg")) {
    %>
      <img src="FileServlet?fileName=<%=optionalFileName%>"   
    <%
    %>
    </body>
    </html>a sample code snippet for FileServlet.
    String fileName =  request.getParameter(fileName);
      File file = new File(fileName);
       if(!file.exists())
         return;
      // If JSP
      String mimeType = application.getMimeType("fileName");
           If you are using servlet
           String mimeType = this.getServletContext().getMimeType(fileName);
         response.setContentType(mimeType);  
         response.setHeader("Content-Disposition","inline;filename=\\"+fileName+"\\");
      BufferedOutputStream out1 = null;
      InputStream in = null;
      if(mimeType == null)
         mimeType = "application/octet-stream";
      try{
         in = new FileInputStream(f);
         response.setContentLength(in.available());
         BufferedOutputStream out1 = new BufferedOutputStream(response.getOutputStream(),1024);
         int size = 0;
         byte[] b = new byte[1024];
         while ((size = in.read(b, 0, 1024)) > 0)
            out1.write(b, 0, size);
      }catch(Exception exp){
      }finally{
          if(out1 != null){
             try{
                out1.flush();               
                out1.close();
             }catch(Exception e){}
          if(in != null){
            try{in.close();}catch(Exception e){}
      } Hope that might answer your question :)
    However,this is not the recommended way of doing this make use of MVC pattern.Would be a better approach.
    you might think of googling on this and can findout what is the best practise followed for problems of this sort
    REGARDS,
    RaHuL

  • Showing the content of a file in an effective way

    Hi all, I am in a novice level in Java and all i want is to recieve the content of a text file.
    Here is my code
    import java.io.*;
    public class FileReader
    public static void main(String[] args)
    throws IOException
    FileInputStream theFile=
    new FileInputStream("text.txt");
    FilterInputStream myfile=
    new FilterInputStream(theFile);
    int c;
    while ((c = myfile.read()) != -1)
    {System.out.print(c);}
    theFile.close();
    The Error
    D:\java\Java3d Project\FileReader.java:12: FilterInputStream(java.io.InputStream) has protected access in java.io.FilterInputStream
    new FilterInputStream(theFile);
    ^
    1 error
    What is wrong? I want to be able to chack whether the "1" in my text file is integer or not.
    Thanks in advance

    Here is my code then
    import java.io.*;
    public class FileReader
    public static void main(String[] args)
    throws IOException
    FileInputStream theFile=
    new FileInputStream("text.txt");
    BufferedInputStream myfile=
    new BufferedInputStream(theFile);
    String c=new String();
    while ((c = myfile.readLine()) != -1)
    {System.out.print(myfile);}
    theFile.close();
    The Error
    D:\java\Java3d Project\FileReader.java:16: cannot resolve symbol
    symbol : method readLine ()
    location: class java.io.BufferedInputStream
    while ((c = myfile.readLine()) != -1)
    ^
    D:\java\Java3d Project\FileReader.java:16: operator != cannot be applied to java.lang.String,int
    while ((c = myfile.readLine()) != -1)
    ^
    2 errors
    What have i done wrong? Is there any relevant issue?
    My target is to read the file text.txt which has its data in a well-structured manner. That means if i look in the beginning of each line then the first character must be integer. I want my program to determine if the particilar character in my text.txt is integer or not.

  • How to search the content of TPL files?

    Hi. I have a folder with hundreds of template "tpl" files that I'm needing to search the file contents of but using the regular search of that folder is unable to search the content of the tpl files, is it possible to do so?
    Thanks!,
    Wesley

    I assume there's not a "scan all files" with Spotlight?
    I don't think that would be possible in the specific case of content searches. Here's my understanding:
    EasyFind searches the files themselves when it looks for content, which makes it slow but very flexible.
    In contrast, Spotlight searches a pre-existing index when it looks for things - it can be instructed to search the index in various ways, but if the desired information is not in the index in the first place, it won't be found. Indexing the content of every file in the system is not feasible, so only the contents of certain file types get indexed. I found the following in [this Wikipedia article|http://en.wikipedia.org/wiki/Spotlight_%28software%29]:
    Aside from basic information about each file like its name, size and timestamps, the mdimport daemon can also index the content of some files, when it has an Importer plug-in that tells it how the file content is formatted. Spotlight comes with importers for certain types of files, such as Microsoft Word, MP3, and PDF documents. Apple publishes APIs that allow developers to write Spotlight Importer plug-ins for their own file formats.[3]
    So unless you'd care to write your own Spotlight Importer plug-in for tpl files, I think you are out of luck!

  • How to store the content of a file in oracle table.

    Hello,
    I have a .xml file in unix , how can i upload the content of that file into a column of a table in oracle?

    Did you look at the link posted in response to the OP? At a quick look, it seems fairly reasonable to me.
    John

  • Can I copy the content of my Apple TV to a new Mac?

    I have lost my entire iTunes library from a house fire, but I have my Apple TV with over 14,000 songs on it. Most from my also lost cd collection.
    Can I copy the content of my Apple TV to my new Mac? If so, how

    Not without doing things that void the warranty. You can always disassemble it, put the hard drive into an enclosure and copy things off it that way. Not for the faint of heart.

  • In making a "highlights" movie, using clips from different imported iMovie events, can I delete the larger iMovie event file from the Events browser and still work w the smaller clips in the Projects browser w/o having the larger files still loaded?

    I have sucessfully imported 150 Sony digital 8mm movies (each one hour in length) into iMovie as 150 iMovie events. I have since successfully converted them from their original 13 Gb (.dv) file to an exported smaller 1.3 Gb (.4mv "large file") movie that I am happy with, using the iMovie projects browser. So now I have 150 " .4mv" movies on my internal HD as well as about half of my original raw data " .dv " movies on my internal hard drive.
    Due to their large size (over 2 Tb), I do not have all the larger raw data (.dv) files on my 2Tb internal drive, just about half of them. What I want to do now is to create a new project in the Projects browser for each of my kids, and reload, starting with Tape #1, each of these larger files and do a highlights movie for each of my kids, wherein I pick out smaller clips from each 1 hour .dv iMovie event and paste them into the appropriate kid's Highlights project in the Projects browser.
    Here's my question: If I load the first 5 large files back onto my internal HD, and paste in various shorter clips into each of my kids' Highlights project, and then if I delete those first 5 large files (they are backed up on 2 other 3Tb external HDs), can I keep doing this (reloading the next 5 large .dv files to work with), and ultimately take each of my kid's Highlights project and export as a .4mv movie EVEN THOUGH the earlier large .dv files are no longer on my internal HD, OR does my iMac need to have all these larger files loaded on my internal HD for me to eventually export each of my kid's Highlights project to a .4mv movie?
    I have a 2011 era 27" iMac desktop w 2Tb HD internal and 250 Gb flash drive, and Lion OSX and iMovie 11.

    Thanks. I tested it out and you were correct. I loaded 2 .dv movies from my external HD back onto my internal HD, and got them re-imported into iMovie, took a few short clips from each of the 2 iMovie events and pasted them into a new project in the Project Browser. Then I deleted these 2  "source clips" from my internal HD, closed iMovie and then re-opened it and found that iMovie would NOT export the smaller clips for a "highlights" .4mv movie without the "source clips" being available.
    I read your link on Quicktime. It talks about mostly trimming, which is what I did with each iMovie event before I took each one as a project to export as a smaller .4mv file. But if I use Quicktime (do I need QT Pro or basic), what advantage is it to me to use QT over iMovie (I must admit I am a novice at iMovie and have never used QT or QT Pro as a tool)? Will it then convert any edits I make to a .m4v movie or do I need iMovie to do that?
    Does QT allow trimming multiple segments out of a movie during one edit session, or can you only do 1 at a time? By that I mean that, for example, when I use Sonys Picture Motion Browser for my .mts movies, you can only set one Start and one End point for each edit/trim you do: it does not allow you to set multiple Start Stop points like iMovie allows in its Event or Project browser. You can only do one "trim" at a time, save it and then reopen to do another trim. not very useful.

  • Can I download a file in different sessions or should it be in a single session? In other words can I pause the download of a file, shutdown/restart my system and then resume download from where I left off? Or will it start from the very beginning?

    Can I download a file in different sessions or should it be in a single session? In other words can I pause the download of a file, shutdown/restart my system and then resume download from where I left off? Or will it start from the very beginning?

    If a server supports resuming downloads then the download should continue where it left off.<br />
    You can test that by simple starting a large download and wait a minute or so before pausing it.<br />
    Then you can close and restart Firefox and see if resuming works.
    You can set the pref browser.download.manager.quitBehavior to 2 on the about:config page.<br />
    That will make Firefox ask for confirmation if you want to cancel the download if you close Firefox.
    See:
    * http://kb.mozillazine.org/browser.download.manager.quitBehavior

  • How to "select a Directory" from Browse button

    Hi all,
    I am new to Swing API.
    All I want is to create a TextField and a Browse button.
    User has to select a directory from Browse button and upon selection of the directory and clicking OK, the directory should be placed into TextField.
    Hope this is not new............
    Help me do this.....
    Thanks in advance
    Sreedhar

    Take a look at JFileChooser. You can build a JFileChooser instance that will allow the user to select DIRECTORIES_ONLY (hint, take a look at the constants), it should do the trick ... (even though it's pretty ugly alright)

  • Just got a new mac computer and none of the music from my old computer's itunes transfered when I transfered the contents of the hard drive.  Now I'm trying to transfer music from my ipod and can't get all the files....help?

    Just got a new  computer and none of the music from my old computer's itunes transfered when I transfered the contents of the old hard drive.  Now I'm trying to transfer music from my ipod and can't get all the files....help please?

    The iphone is not a storage/backup device.
    It has always been very basic to always maintain a backup copy of your computer for this very occasion.
    Have you failed to do this?
    If so, not good, then you can transfer itunes purchases:  File>Devices>Transfer Purchases
    You may be able to purchase a third partyn program to get the rest ( not supported by Apple)

  • How can I copy the whole directory of files from PC to iPad?

    How can I copy the whole directory of files from PC to iPad ?

    Get an app that reads PDF's, such as iBooks or GoodReader or Readdle Docs, then use the file transfer part of iTUnes to get those files to your iPad, through iTunes. ( I have no experience with goodreader, but with ReaddleDocs you can move the files, then create folders to put them in to keep them organized)

  • I am trying to open up my iTunes from my Mac. It says "You can't open the application iTunes because it is not supported on this type of Mac." What do I do?

    I am trying to open up my iTunes from my iMac. It says "You can't open the application iTunes because it is not supported on this type of Mac." What do I do? I've already force closed all other apps.

    Well, obviously the problem isn't with the other apps, it's with the type of Mac you have. What type of Mac do you have?

  • How can I locate the original .CR2 /  Raw file from Photos in finder?

    How can I locate the original .CR2 /  RAW file from Photos in the finder window? I would like to know a easier way to open my files and use them in Photoshop than having to go to the Pictures folder, right clicking "show packaged contents", and manually searching for my CR2's / RAW's. It is also ridiculous to have to export the RAW file to my desktop, and then take it into Photoshop or another photo editing program.  I was able to do this in iPhoto and find I cannot do so in Photos. Please help? Can you please consider adding a right click function that says "Show Original file in Finder". That would make it so much easier and better for those of us who want a simple way to access the original files and use them in other editing programs. At least with iPhoto you could go to the top menu / preferences and find your items.

    http://www.apple.com/feedback/macosx.html is the place for feature requests and feedback
    Rather than use the 'Show package Contents route, the supported and safer way is to export the unmodfied original.

  • I paired my old LG phone using bluetooth exchange and uploaded all of the Voice Memo files from it to my macbook and I can't find the file, where would it be located ?

    I paired my old LG phone using bluetooth exchange and uploaded all of the Voice Memo files from it to my macbook and I can't find the file, where would it be located ?

    You cannot update iPhone 4 to IOS 8.1.2, the highest you can update is IOS 7.1.2.
    Unless you've iPhone 4S (looks similar to iPhone 4)

  • How To Fetch the Content of a File from Client's PC?

    In my JSP I have this:
         <input type="file" name="filename">for visitors of the web page to browse their PCs' directories to select a file to upload (when the Submit button is clicked).
    What appears in the text field will be a file name. How do I get both the file name and the content of that file to be saved in the database?

    From http://www.htmlhelp.com/reference/html40/forms/input.html:
    A form that includes a file INPUT must specify METHOD=post and ENCTYPE="multipart/form-data" in the <FORM> tag. CGI libraries such as CGI.pm allow simple handling of such forms.
    Form-based file upload is unsupported by many currently deployed browsers. Authors should provide alternative methods of input where possible.
    The following example allows the user to upload an HTML document for validation:
    <FORM METHOD=post ACTION="/cgi-bin/validate.cgi" ENCTYPE="multipart/form-data">
    <P>Select an HTML document to upload and validate. If your browser does not support form-based file upload, use one of our alternate methods of validation.</P>
    <P><INPUT TYPE=file NAME="html_file" ACCEPT="text/html"></P>
    <P><INPUT TYPE=submit VALUE="Validate it!"></P>
    </FORM>
    Your servlet would then have to process whatever data is put into that parameter. You can look at O'Reilly's servlet utilities, or one of the other other links here:
    http://www.google.com/search?q=java+servlet+file+upload&sourceid=opera&num=0&ie=utf-8&oe=utf-8

Maybe you are looking for

  • I need a copy of the binary file /bin/cat

    I called apple support and the server section is closed so I was wondering if anyone could help me replace the actual cat command file as I accidentally deleted mine.

  • How can I adjust my gps location?

    How can I adjust my gps location?  When I ask Siri to remind me of something when I get home, it would not work  I learned by accident while taking a walk that I have to go past my driveway to the far edge of my property for location services to reco

  • Where can I download and install AquaLogic.WCFilter.dll from?

    I have installed Oracle Webcenter's Accelerator for .Net and trying to browse the WSRP webservice (http://<MyIIS-Defaultwebsite>/wsrpproducer/1.0/WSRPBaseService.asmx) installed in my IIS but getting the following error. [NullReferenceException: Obje

  • How to write "icalcs /deny everyone:(CI)(OI)W" command (on win7) with win xp?

    Hello, i want to know how to write a command like "icacls dir /deny everyone:(CI)(OI)W" on windows xp. Afaik there is no icacls on windows xp, so i guess this should be done with just cacls? I want to lock a folder through cmd, but i cannot manage to

  • In auto provising scenario how i can recived incoming calls on PAP2

    HI    i need help reagrding , when i use PAP with auto -provising with my VOIP service provider what are ther differnt profile parameters need to set in profile which is store at service provider provising server . plz give me detail list of such par