Solved

Display XML/HTML files in TextArea

Posted on 2002-07-16
3
1,410 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
Comment Utility
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
Comment Utility
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
Comment Utility
This question has been asnwered, and will be placed in PAQ.

Regards,

ComTech
Community Support Administrator  
Experts-Exchange  
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
J2SE 5.0 metadata 1 44
servlet init param and contect param 3 53
using if condition without JSTL 2 101
countXY challenge 28 115
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now