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 764607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:45:21+00:00 2026-05-14T16:45:21+00:00

I use the following method to send out an object from a servlet :

  • 0

I use the following method to send out an object from a servlet :

  public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException
  {
    String Full_URL=request.getRequestURL().append("?"+request.getQueryString()).toString();

    String Contact_Id=request.getParameter("Contact_Id");
    String Time_Stamp=Get_Date_Format(6),query="select from "+Contact_Info_Entry.class.getName()+" where Contact_Id == '"+Contact_Id+"' order by Contact_Id desc";

    PersistenceManager pm=null;
    try
    {
      pm=PMF.get().getPersistenceManager();

      // note that this returns a list, there could be multiple, DataStore does not ensure uniqueness for non-primary key fields
      List<Contact_Info_Entry> results=(List<Contact_Info_Entry>)pm.newQuery(query).execute();

      Write_Serialized_XML(response.getOutputStream(),results.get(0));
    }
    catch (Exception e) { Send_Email(Email_From,Email_To,"Check_License_Servlet Error [ "+Time_Stamp+" ]",new Text(e.toString()+"\n"+Get_Stack_Trace(e)),null); }
    finally { pm.close(); }
  }

  /** Writes the object and CLOSES the stream. Uses the persistance delegate registered in this class.
   * @param os The stream to write to.
   * @param o The object to be serialized.
   */
  public static void writeXMLObject(OutputStream os,Object o)
  {
    // Classloader reference must be set since netBeans uses another class loader to loead the bean wich will fail in some circumstances.
    ClassLoader oldClassLoader=Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(Check_License_Servlet.class.getClassLoader());

    XMLEncoder encoder=new XMLEncoder(os);
    encoder.setExceptionListener(new ExceptionListener() { public void exceptionThrown(Exception e) { e.printStackTrace(); }});
    encoder.writeObject(o);
    encoder.flush();
    encoder.close();

    Thread.currentThread().setContextClassLoader(oldClassLoader);
  }

  private static ByteArrayOutputStream writeOutputStream=new ByteArrayOutputStream(16384);

  /** Writes an object to XML.
   * @param out The boject out to write to. [ Will not be closed. ]
   * @param o The object to write.
   */
  public static synchronized void writeAsXML(ObjectOutput out,Object o) throws IOException
  {
    writeOutputStream.reset();
    writeXMLObject(writeOutputStream,o);
    byte[] Bt_1=writeOutputStream.toByteArray();
    byte[] Bt_2=new Des_Encrypter().encrypt(Bt_1,Key);
    out.writeInt(Bt_2.length);
    out.write(Bt_2);
    out.flush();
    out.close();
  }
  public static synchronized void Write_Serialized_XML(OutputStream Output_Stream,Object o) throws IOException { writeAsXML(new ObjectOutputStream(Output_Stream),o); }

At the receiving end the code look like this :

  File_Url="http://"+Site_Url+App_Dir+File_Name;
  try
  {
    Contact_Info_Entry Online_Contact_Entry=(Contact_Info_Entry)Read_Serialized_XML(new URL(File_Url));
  }
  catch (Exception e)
  {
    e.printStackTrace();
  }

  private static byte[] readBuf=new byte[16384];

  public static synchronized Object readAsXML(ObjectInput in) throws IOException
  {
    // Classloader reference must be set since netBeans uses another class loader to load the bean which will fail under some circumstances.
    ClassLoader oldClassLoader=Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(Tool_Lib_Simple.class.getClassLoader());

    int length=in.readInt();
    readBuf=new byte[length];

    in.readFully(readBuf,0,length);
    byte Bt[]=new Des_Encrypter().decrypt(readBuf,Key);
    XMLDecoder dec=new XMLDecoder(new ByteArrayInputStream(Bt,0,Bt.length));
    Object o=dec.readObject();
    Thread.currentThread().setContextClassLoader(oldClassLoader);
    in.close();
    return o;
  }

  public static synchronized Object Read_Serialized_XML(URL File_Url) throws IOException { return readAsXML(new ObjectInputStream(File_Url.openStream())); }

But I can’t get the object from the Java app that’s on the receiving end, why ? The error messages look like this :

java.lang.ClassNotFoundException: PayPal_Monitor.Contact_Info_Entry
Continuing ...
java.lang.NullPointerException: target should not be null
Continuing ...
java.lang.NullPointerException: target should not be null
Continuing ...
java.lang.NullPointerException: target should not be null
Continuing ...
  • 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-14T16:45:21+00:00Added an answer on May 14, 2026 at 4:45 pm
    java.lang.ClassNotFoundException: PayPal_Monitor.Contact_Info_Entry
    

    That class should be also present in the runtime classpath of the receiving side.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.