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

  • Home
  • SEARCH
  • 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 3314516
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:14:31+00:00 2026-05-17T22:14:31+00:00

Currently working through a tutorial on JOX included within Sams Teach Yourself JavaServer Pages

  • 0

Currently working through a tutorial on JOX included within Sams Teach Yourself JavaServer Pages 2.0 with Apache Tomcat in 24 Hours

Either the com.wutka.jox has changed or the author missed a crucial ingredient.

When I try to execute:

java "hu/flux/xml/XMLTestClient" "http://localhost:8080/SamsTeachYourselfJSP/joxparse" "d:\education\java\SamsTeachYourselfJSP\WebContent\test.xml"

My CMD console displays:

Sending: d:\education\java\SamsTeachYourselfJSP\WebContent\test.xml
To: http://localhost:8080/SamsTeachYourselfJSP/joxparse

Received:


null

And my Eclipse console displays:

Can't convert bean to String: null
java.lang.NullPointerException
    at hu.flux.xml.TestBean.toString(TestBean.java:144)
    at hu.flux.xml.JOXParseServlet.doPost(JOXParseServlet.java:50)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at hu.flux.logging.SessionRecorder.doFilter(SessionRecorder.java:61)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:242)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at hu.flux.timing.TimingFilter.doFilter(TimingFilter.java:62)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:242)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:163)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:556)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:401)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:267)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:245)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:260)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
Returning String: null

Here is the current code for the servlet:

package hu.flux.xml;

import java.io.*;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import com.wutka.jox.*;
import com.wutka.jox.test.*;


/**
 * Servlet implementation class JOXParseServlet
 */
@SuppressWarnings("unused")
@WebServlet("/JOXParseServlet")
public class JOXParseServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public JOXParseServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
        com.wutka.jox.test.TestBean newBean = new com.wutka.jox.test.TestBean();
        BufferedReader requestReader = request.getReader();
        JOXBeanReader reader = new JOXBeanReader(requestReader);
        reader.readObject(newBean);

        // This servlet just sends a plain text response.
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();

        String beanString = null;
        try { beanString = newBean.toString(); }
        catch (Exception exc)
        {
            System.err.println("Can't convert bean to String: " + exc.getMessage());
            exc.printStackTrace();
        }

        System.out.println ("Returning String: " + beanString);
        out.println(beanString);
    }

}

Neither the XMLTestClient, nor test.xml are likely to be the problem, as they both work successfully with a Sax parser and a Dom parser.

However, in case it is useful or interesting to see them, here they are:

<!-- test.xml -->
<?xml version="1.0" encoding="UTF-8"?>
    <name>
        <first>Brian</first>
        <last>Kessler</last>
    </name>

////////////////////////////////////////////

/**
 *  XMLTestClient.java
 */
package hu.flux.xml;
import java.io.*;
import java.net.*;

/**
 * @author Brian Kessler
 *
 */
public class XMLTestClient {

    /**
     * 
     */
    public XMLTestClient() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @param args
     */
    public static void main(String[] args) 
    {
        try
        {
            // args[1] is the name of the file to send.

            System.out.println("\n\nSending: " + args[1]);
            System.out.println("To: " + args[0]);
            System.out.println("\nReceived:\n\n");

            try
            {
                File f = new File(args[1]);
                int contentLength = (int) f.length();

                // args[0] is the URL to send the file to.
                URL url = new URL(args[0]);
                URLConnection conn = url.openConnection();

                // Tell the URLConnection that this is an XML file.
                conn.setDoOutput(true);
                conn.setRequestProperty("content-type", "text/xml");
                conn.setRequestProperty("content-length", ""+contentLength);

                FileInputStream in = new FileInputStream(f);

                byte[] buffer = new byte[4096];
                int len;

                OutputStream out = conn.getOutputStream();

                // Send the XML file to the servlet.
                while ((len = in.read(buffer)) > 0)
                    { out.write(buffer, 0, len); }

                InputStream resp = conn.getInputStream();

                // Read the response back from the servlet.
                while ((len = resp.read(buffer)) > 0)
                    { System.out.write(buffer, 0, len); }

            }
            catch (Exception exc) 
            {
                System.err.println("Missing file argument: " + exc);
                exc.printStackTrace();
            }
        }
        catch (Exception exc) { exc.printStackTrace(); }
    }

}
  • 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-17T22:14:32+00:00Added an answer on May 17, 2026 at 10:14 pm

    The problem was with TestBean.

    In the context of the book, it seemed that this could be some sort of generic bean.

    In fact, the getters and setters in the bean need to match the contents of the XML.

    The toString() failed because the bean wasn’t being populated with data.

    Once I created a bean to match the XML and included a custom toString(), I was able to get this servlet working. 🙂

    Here is a working bean:

    /**
     * 
     */
    package hu.flux.user;
    
    /**
     * @author Brian Kessler
     *
     */
    public class NamedPerson extends Person
    {
        private String firstName = "";
        private String lastName = "";
    
    
        public String getFirst() { return this.firstName; }
        public void setFirst(String firstName) {this.firstName = firstName;}
    
        public String getLast() { return this.lastName; }
        public void setLast(String lastName) {this.lastName = lastName;}
    
        public String toString() {return (this.firstName + " " + this.lastName);}
    }
    

    Also, in the servlet, I needed to change:

    com.wutka.jox.test.TestBean newBean = new com.wutka.jox.test.TestBean();
    

    to

    Person newBean new Person();
    

    Cheers to Teja Kantamneni for putting me on the track to the right answer. 🙂

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

Sidebar

Related Questions

I'm currently working through an assignment that deals with Big-O and running times. I
I'm currently working through the excercises in 'The C Programming Language'. Here's one of
I'm working through Practical Web 2.0 Appications currently and have hit a bit of
I've been working through the Stanford iPhone Coding course and currently hooking into the
I'm learning haskell. Currently working through 99 questions , a little bit stuck on
I am new to android development and am currently working my way through the
I am currently working through Accelerated C++ and have come across an issue in
I'm working through SICP. Currently, in the first chapter, I'm having problems getting Racket
I currently working on an issue tracker for my company to help them keep
I am currently working on a project and my goal is to locate text

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.