Show file content in jsp

i want to get an xml file and give the client user.maybe in the jsp i write the XML content to notepad.But i don't know how can i open notepad and write the content to it.
pls tell me the the right way! thanks a lot a lot!

Why don't you use Java Script to reference the xml file and open it in a new window from your JSP?
String browserFilePath = request.getContextPath() + "/some_directory/myfile.xml";
then in your jsp
<% if (...???) { %>
<Script>window.open('<%=browserFilePath%>')</Script>
{% } %>

Similar Messages

  • Reading RTF file content from JSP which stored in database as image format

    <%@page import="java.sql.*" %>
    <%@page import="java.net.*" %>
    <%@page import="java.io.*" %>
    <%@page import="java.*" %>
    <%@page import="javax.swing.*" %>
    <%@page import="javax.swing.text.*" %>
    <%@page import="javax.swing.text.rtf.*" %>
    <%
         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection con=DriverManager.getConnection("jdbc:sqlserver://local:1433;databaseName=database;user=sa");
         Statement st=con.createStatement();
         ResultSet rs=st.executeQuery("select Document from docrev where UniqeId ='199207' ");//("select data from rtfdata");227317
         rs.next();
         byte bt[]=rs.getBytes(1);
         InputStream fi = new ByteArrayInputStream( bt );
         RTFEditorKit rtf = new RTFEditorKit();
         JEditorPane editor = new JEditorPane();
         editor.setEditorKit( rtf );
         rtf.read( fi, editor.getDocument(), 0 );
         Document d=editor.getDocument();
         String str=d.getText(0,d.getLength());
         /*OutputStream fo=new FileOutputStream("temp3.rtf");
         fo.write(str.getBytes());*/
    %>
    <html>
    <body>
    <p><textarea name=myarea style="background:#FFCC99" cols=100 rows=50><%=str%></textarea>
    </body>
    </html>
    Edited by: Santhu538 on Oct 23, 2007 10:16 PM
    Edited by: Santhu538 on Oct 23, 2007 10:25 PM
    Edited by: Santhu538 on Oct 23, 2007 10:26 PM

    Please use code tags while posting code. See the code button above the text area?
    It's a good practise not to mix jdbc code in your jsp (mvc and all that you see)
    Finally you'll have to quickly decide on your front end - jsp or swing. It looks like the former, but then with the code you have posted, the server is apt to pop up some windows prompting the user who has logged on (to the server) to choose the files for the client :)
    ram.

  • How to display an xml file contents in jsp as tree view

    hi,
    Iam trying to read an xml file and display the structure in jsp as tree view, can any one help me

    Use a [XML or DOM parser|http://java-source.net/open-source/xml-parsers] to read a XML file into a tree structure of Java objects.
    Use the [Collections API|http://java.sun.com/docs/books/tutorial/collections/index.html] to get hold of the relevant elements in a tree structure.
    Use JSTL´s [c:forEach|http://java.sun.com/javaee/5/docs/tutorial/doc/bnakh.html] tag to iterate over a Collection in JSP.
    Use HTML´s [<ul>/<li>|http://www.w3.org/TR/REC-html40/struct/lists.html#h-10.2] or [<dl>/<dt>/<dd>|http://www.w3.org/TR/REC-html40/struct/lists.html#h-10.3] tags to represent a tree in HTML.

  • Show file content

    hi folks,
    one more try
    in wd abap i can make an upload of an file, are there any (besides office and pdf) viewers available to view those files in a wd abap application.
    kind regards,
    oliver

    Why don't you use Java Script to reference the xml file and open it in a new window from your JSP?
    String browserFilePath = request.getContextPath() + "/some_directory/myfile.xml";
    then in your jsp
    <% if (...???) { %>
    <Script>window.open('<%=browserFilePath%>')</Script>
    {% } %>

  • 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

  • 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-

  • WHEN OPENING A FILE WITH FIREFOX MULTIPLE FILES KEEP OPENING IN RAPID SUCCESSION WITHOUT SHOWING ANY CONTENT AND THIS DOES NOT STOP AND I CANNOT SAY HOW MANY FILES I HAVE

    THERE IS A PROBLEM IN OPENING ANY FILE. WHEN OPENING - A RAPID SUCCESSION OF FILES OPEN, ONE ATOP THE NEXT, WITHOUT SHOWING FILE'S CONTENT. THIS CONTINUES FOR QUITE A WHILE. I MUST TURN OFF COMPUTER. IT IS NOT POSSIBLE TO CHOOSE ANY OTHER FUNCTION WHILE THIS IS HAPPENING, IE : WHEN OPENING A FILE. AS IN , I CANNOT OPEN GOOGLE OR MAIL, ETC. AND THE FILES KEEP OPENING AS UNTITLED. SO I AM NOT ABLE TO OPEN ANY ONE FILE, AND SEE ITS CONTENT, THEY JUST KEEP STACKING LIKE EMTY PAGES ONE ON TOP OF THE NEXT.

    THANK YOU
    THAT DOES NOT SEEM TO BE THE ANSWER
    I HAVE A MAC
    BOUGHT IN 2008
    AND I DO NOT SEE THAT I HAVE A STUCK KEY
    PERHAPS I AM NOT UNDERSTANDING WHAT YOU MEAN

  • I have multiple libraries in iPhoto. When I follow the instructions User/Pictures/iPhoto library/Show package contents/Master /Duplicate I have no problem. When I go thru the same sequence but with iPhoto Galapagos I cannot duplicate its master file. What

    I have multiple libraries in iPhoto. When I follow the instructions:  User/Pictures/iPhoto library/Show package contents/Master /Duplicate I have no problem importing these image. When I choose the file titled...Pictures/iPhoto Galapagos I am unable to show package contents/Master and duplicate the images in this file. What am I doing wrong?
    Thanks

    have multiple libraries in iPhoto. When I follow the instructions:  User/Pictures/iPhoto library/Show package contents/Master /Duplicate I have no problem importing these image. When I choose the file titled...Pictures/iPhoto Galapagos I am unable to show package contents/Master and duplicate the images in this file. What am I doing wrong?
    Thanks

  • How to show the file contents in a streaming manner on the browser

    Hi,
    I have a log file which gets appended to by another program.
    I need to show the contents of this log file in the browser window but in a streaming manner. Reading the file in one shot and refreshing the page every few seconds is not a solution as it makes the browser hang when the file size is huge. A unix tail functionality is also acceptable but it should be streaming. Would a servlet or applet do the trick?
    Please advise!

    is your log file present on web/application server? if yes, you can do the following:
    1. create a web page containing text area. (for displaying log file)
    2. use XmlHttpRequstObject (Ajax) for querying the next available data from Servlet.
    On the Serverside:
    You can store the the FileScanner object in session scope. and use it to read the next available data and send it as response.
    On the client Side(webpage/javascript)
    read the contents of the response and append it to textarea.
    In Simple words, I'd say AJAX is the way to go.

  • How to convert a text file content to String in JSP?

    Hi,
    I need to read the content of a text file and convert it into String and display it on to a JSP file.
    But the codings below don't work. Please advise me on how can i display the text file content.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    File adCheck = new File("list.txt");
    fis = new FileInputStream(adCheck);
    int Length = adCheck.length();
    byte arr[] = new byte[Length];
    int dataRead = 0;
    int totalData = 0;
    while(totalData <Length)
         dataRead = fis.read(arr,totalData,Length);
         totalData += dataRead;
    String Content = new String(arr);//byte array converted to String
    arr = null;

         InputStreamReader in=new InputStreamReader(fis);
          StringWriter out=new StringWriter();
          char[] buffer=new char[8192];
          int sizeRead;
          while ( ( sizeRead=in.read(buffer, 0, 8192) ) != -1 )
            out.write(buffer, 0, sizeRead);
         String content=out.toString();

  • Want to display the contents of a text file in a jsp

    hi
    i am new to jsp, i want to display the contents of a text file in a jsp file ,whenever jsp file is loaded from browser.
    -thanx

    i had come up with the code
    <!-- form.jsp -->
    <%@ page import="java.io.*, java.lang.*" %>
    <%@ page language="java" %>
    <html>
    <head>
    <title>Display</title>
    </head>
    <body>
    <%
    String sample[100];
    String line;
    %>
    <%! int i=0; %>
    <%!File f1 = new File("c:\\file.txt"); %>
    <% try { %>
    <%!FileReader fi = new FileReader(f1); %>
    <% } catch(FileNotFoundException io) { } %>
    <%!BufferedReader in = new BufferedReader(fi); %>
    <%
    while((line=in.readLine())!= null)
    sample= line;
    i++;
    in.close();
    %>
    i will display sample here
    </body>
    </html>
    but i am getting error
    display_jsp.java:16: unreported exception java.io.FileNotFoundException;
    must be caught or declared to be thrown
    FileReader fi = new FileReader(f1);
    ^
    plz help
    -thanx

  • Concatenated PDF file does not show all content.

    When I concatenate 2 single page pdf file into one pdf file, the concatenated page does not show all the content. It misses the last line on the 2nd page.
    However the thumbnails view shows the missing line correctly.
    Also, if I view the concatenated pdf into another pdf view, it shows the content correctly.

    Upon further research in the merged pdf file, it appears the merged pdf file has 2 references to the same field "UFE_ISSUE_DATE".
    If I edit the pdf file in the text editor and change one of the field name to "UFE_ISSUE_DATE_TEST", then the pdf gets rendered correctly with date value shown correctly!
    So, we decided to use 2 different field names in each of the individual pdf for this field only.
    But, what causes confusion is that we do have several other fields with same field name in each of the individual pdf file, but upon merge they appear correctly. Searching for such field name in the merged pdf file via text editor, I can see only 1 reference. Not sure, why this particular field "UFE_ISSUE_DATE" has 2 references in the merged pdf file.
    Any one has any thoughts?

  • How do i "show package contents" on .webtemplate files that have arrow

    Hi,
    Quick question:
    How do i "show package contents" on .webtemplate files that have a small arrow attached on the file icon. Its a template a downloaded from 11mystics.com (free). When i right click the icon there is no "show package contents" available on the drop down menu....
    Thanx!

    When you bring up the contextual menu for the icon, choose "Show Original". This will take you to where the original file is and you should be able to "Show Package Contents" on it.

  • My I-Pad screen is black, I tried to sync and restore I-Pad, it showes the contents on the computer and pulling out pictures and other files, but screen is black. what can I do?

    My I-Pad screen is black!! I tried to sync and restore I-Pad, it showes the contents on the computer and pulling out pictures and other files, but screen is black. I don't know what happened! what can I do?

    I have this problem as well...however, resetting/restoring did not take place when I followed the same instructions but got nothing on the screen.  Thanks in advance.

  • I used tag to show PDF file inside my JSP page, It is working properly in IE but nothing shows in Mozilla. What should I do?

    I've used to display a PDF file inside my JSP page. It is working fine in IE. However, many of users of this application are using Mozilla and the platform is Ubuntu so it is vital that the file is shown in Mozilla as well. How can I solve this problem.
    == This happened ==
    Every time Firefox opened
    == I run my jsp page

    Such conditional code will only work in IE and not in other browsers like Firefox.
    You can ask questions and advice about web development at the mozillaZine Web Development/Standards Evangelism forum.<br />
    A good place to ask questions and advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.<br />
    The helpers at that forum are more knowledgeable about web development issues.<br />
    You need to register at the mozillaZine forum site in order to post at that forum.<br />
    See http://forums.mozillazine.org/viewforum.php?f=25

Maybe you are looking for

  • Not updating status of Purchase requisition status

    Dear Friends, Our client has got third party software interface with SAP.We create Purchase requisitions in SAP,doc type-NB and PRs are also created in Third party software and it will create Purchase requisitions with starting with number ZR in SAP

  • Hp photo creations

    hp photo creations no se pudo cargar la pagina y se produjo un error server time out

  • Error 405 resource not allowed!!

    i trying build web services with: --netbeans 4.1 beta --sun java application server 8 --jwsdp 1.5 --os: windows xp pro i try a simple web services hellows...when i build the web services is successfuly....but when i open in internet explorer is error

  • FB4 not opening after entering Serial Number

    I made a fresh XP installation on an empty and formated partition today. SP3 and all MS updates installed. System, audio, video etc. drivers are installed, then Firefox, Safari, Crome and WAMP, that's it, nothing more. I installed FB4 beta and it ran

  • TS4050 I cannot see historical calendar entries in icloud calendars, any thoughts?

    I cannot see historical calendar entries in icloud calendars, any thoughts?