Solved

Display XML/HTML files in TextArea

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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
trouble with PDF encryption using itext-1.3.1 17 88
maven project in eclipse 11 60
console vs log file 16 83
login jsp example 24 85
Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.
While it may be true that the internet is a place of possibilities, it is also a hostile environment lurking with many dangers. By clicking on the wrong link, trusting the wrong person or using a weak password, you are virtually inviting hackers to …
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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