Solved

Display XML/HTML files in TextArea

Posted on 2002-07-16
3
1,454 Views
Last Modified: 2008-01-09
Dear Expert,
Please advice me by code example to show how to display XML/HTML files from client-side hard driver in a textarea.

Here is my jsp page:
<HTML>
     <HEAD>
     <meta name="GENERATOR" content="IBM WebSphere Page Designer V3.5.3 for Windows">
     <meta http-equiv="Content-Style-Type" content="text/css">
     <link rel="stylesheet" href="xmlGenerator.css">
     <script language="JavaScript" src="/art/javascript/xmlGenerator.js"></script>
     <TITLE>Validate XML Document</TITLE>
     </HEAD>
     <BODY bgcolor="#FFFFFF">
     <%@ include file="./include/topbar.inc" %>
     <FORM name="View" method="POST"><B>Select XML File: </B>
        <INPUT type="File" name="userFile" size="20">
        <INPUT type="submit" name="btnOpen" value="Open"><BR><BR>
     <textarea rows="20" cols="62" name="xmlDocument" WRAP="off"></textarea><BR><BR>
     <INPUT type="button" value="Validate">
        <INPUT type="submit" name="btnUpdate" value="Update">
        <INPUT type="submit" name="btnClose" value="Close">
     </FORM>
     </BODY>
</HTML>

0
Comment
Question by:DevelHelper
3 Comments
 
LVL 1

Expert Comment

by:boolee
ID: 7158713
I think u need to read a file selected by client and display that file in the text area. I am not sure u can do it using javascript because webpages are prevented from accessing disk. U may require to read this file using ur JSP and display it in the text area in the next page.
0
 

Author Comment

by:DevelHelper
ID: 7159280
Dear expert,

I have found the solution for this question. I would like to post my answer for others.

<%@ page import="java.net.*,java.io.*"%>
<%!
   String fileOutput;
%>
<%
   String file = request.getParameter("userFile");
   if (file != null) {
      URL url = new URL("file:///" + file);
      URLConnection conn = url.openConnection();
      StringBuffer buffer = new StringBuffer();
      BufferedReader input = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      String str = "";
      while ((str = input.readLine()) != null ) {
         buffer.append(str).append("\n");
      }
      fileOutput = buffer.toString();
   }
%>

<HTML>
   <HEAD>
      <TITLE>Validate XML Document</TITLE>
   </HEAD>
   <BODY>
      <FORM name="View" method="POST" action="viewXMLDocument.jsp">
         <B>Select XML File: </B>
         <INPUT type="File" name="userFile" size="20">
         <INPUT type="submit" name="btnOpen" value="Open">
         <BR><BR>
         <textarea rows="20" cols="62" name="xmlDocument" WRAP="off"><%= (fileOutput != null) ? fileOutput : "" %></textarea>
         <BR><BR>
         <INPUT type="button" value="Validate">
         <INPUT type="submit" name="btnUpdate" value="Update">
         <INPUT type="submit" name="btnClose" value="Close">
      </FORM>
   </BODY>
</HTML>
0
 

Accepted Solution

by:
ComTech earned 0 total points
ID: 7159476
This question has been asnwered, and will be placed in PAQ.

Regards,

ComTech
Community Support Administrator  
Experts-Exchange  
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The question appears often enough, how do I transfer my data from my old server to the new server while preserving file shares, share permissions, and NTFS permisions.  Here are my tips for handling such a transfer.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question