Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6348149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:22:00+00:00 2026-05-24T21:22:00+00:00

I am trying to read a xml in the jsp and pass the same

  • 0

I am trying to read a xml in the jsp and pass the same over network as char[] to the applet but i am getting
java.io.StreamCorruptedException : invalid stream header :3C3F786D

my jsp :

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import = "java.util.*" %> 
<%@ page import = "java.io.*" %> 
<%@ page trimDirectiveWhitespaces="true" %> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<%  String xmlname=(String)request.getAttribute("xmlname");
     int ch;    
    System.out.println("the value of the xml is "+xmlname);
    String filepath="C:/Users/ashutosh_k/idoc/docRuleTool/WebContent/data/Malaria.xml";
    FileReader fis = new FileReader(new File(filepath));
    char bin[] = new char[(int) new File(filepath).length()];
    fis.read(bin);
    response.getWriter().write(bin);
    fis.close();
%>
</body>
</html>

My applet code :

package com.vaannila.utility;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import prefuse.util.ui.JPrefuseApplet;

public class dynamicTreeApplet extends JPrefuseApplet {

    private static final long serialVersionUID = 1L;
    public static int i = 1;

    public void init() {
        System.out.println("the value of i is " + i);
        URL url = null;
        try {
            url = new URL("http://localhost:8080/docRuleTool/XmlResponseReading.jsp");
            URLConnection con = url.openConnection();
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setUseCaches(false);
            //con.setRequestProperty("Content-TYpe", "application/octet-stream");
            ObjectOutputStream oos =  new ObjectOutputStream(con.getOutputStream());
            oos.writeObject("Malaria");
            oos.flush();
            oos.close();
            InputStream ois =  con.getInputStream();
        //  ByteArrayOutputStream bos = new ByteArrayOutputStream();
            while (true) {
                byte b[] = new byte[1024];
                int retval = ois.read(b);
                if (retval < b.length) {
                    if (retval > 0) {
                        byte b1[] = new byte[retval];
                        System.arraycopy(b, 0, b1, 0, retval);

                        ois.read(b1);
                        System.out.println(new String(b1));
                    }
                    break;
                } else {
                    ois.read(b);
                    System.out.println(new String(b));

                }

            }

//          ByteArrayInputStream bis = new ByteArrayInputStream(ois.toByteArray());
            this.setContentPane(dynamicView.demo(ois, "name"));
            ois.close();

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (FileNotFoundException f) {
            f.printStackTrace();

        } catch (IOException io) {
            io.printStackTrace();
        }
        ++i;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:22:01+00:00Added an answer on May 24, 2026 at 9:22 pm

    You have many many problems in your code:

    • You’re sending XML inside an HTML page to your client. You shouldn’t have html markup around your XML. Else it’s not XML anymore.
    • you’re using scriptlets in your JSPs. JSPs should be used to generate markup, and nothing else. Put the code that reads request parameters, reads a file, etc. in a servlet, where Java code can be properly written, parsed, refactored and designed rather than in JSPs. JSPs should contain markup, JSP tags and EL expressions. Not Java code.
    • You’re using the platforme default encoding to read an XML file, which is perhaps encoded in some other encoding. You should read the XML file as bytes, and send it to the response OutputStream. An XML file defines its encoding, so the receiver’s XML parser can use the appropriate encoding to transform the stream of bytes into an XML document
    • You don’t read the file properly. A single call to fis.read doesn’t guarantee that the whole file has been read. Read the javadoc of the methods you’re using, and rea the Java tutorial about IO.
    • You’re using an ObjectOutputStream to send an HTTP request parameter. An ObjectOutputStream is used to send serialized objects. It’s not used to send HTTP parameters. The URL should be http://localhost:8080/docRuleTool/XmlResponseReading.jsp?xmlname=Malaria, and you shouldn’t send anything in the connection’s output stream. You should learn how HTTP works.
    • the code which reads from the inputstream (in the applet) is also wrong. Read the Java tutorial about IO.
    • once again, in the applet, you’re using the default platform encoding to transform a byte array into a String. Use an XML parser to read your XML.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to read the xml file but somehow i am getting this
I'm trying to read a XML file and output the values, but i'm getting
I am trying to read the following xml stream but am really struggling. <channelSnapshot
I have a really simple XML file that I'm trying to read, but I
I'm trying to read xml fields (with actionscript 3), but the problem is that
I'm trying to read an xml document but the XmlReader.ReadToNextSibling does not work as
Im currently trying to read an XML file and populate an observable collection, but
I'm trying to read XML that is being pushed to my java app. I
i am trying to read a xml file with following tag, but the sax
I m trying read XML data using XML parser from Url( https://....etc ). But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.