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
Solved

Display XML/HTML files in TextArea

Posted on 2002-07-16
3
1,486 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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