Solved

Display XML/HTML files in TextArea

Posted on 2002-07-16
3
1,520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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