0

The answer in this question suggests creating a ServletUtilities class to handle text conversion between Java strings and XML text.

Generally when you create a JEE web application you put together a class that handles general conversions like this in a class named ServletUtilities.

I did a bit of a google for ServletUtilities, but I can't find much about it.

Is having a ServletUtilities class a convention?

How common is it?

When should you have one?

When should it be used?

1
  • 1
    I think the author has mixed up the words "I" and "you".
    – tom
    Jan 29, 2014 at 10:16

1 Answer 1

3

Collecting static methods in classes called SomethingUtilities (or SomethingUtils or SomethingUtil) is a pretty widespread convention, but ServletUtilities as such is not.

Excessive use of such classes can be a sign that the author of the code has not really understood object orientation and is writing procedural code in an OO language, whereas moderate use of them just shows that for some tasks you really want standalone functions rather than classes.

Note that the code in the answer you cite is bad for a number of reasons:

  • The name of the class should be directly related to what the static methods do, and XML escaping has nothing to do with Servlets.
  • XML escaping is a very common task and potentially security-relevant, so you really shouldn't roll your own. Any XML parser or framework will have a way to do it that is almost certainly better than what you'll come up with on the fly. Or you can use Apache commons-lang which has StringEscapeUtils.escapeXml() (better class name, too!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.