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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:18:36+00:00 2026-05-31T08:18:36+00:00

I am pretty new to this whole servlet thing, so please correct me if

  • 0

I am pretty new to this whole servlet thing, so please correct me if I mix or use incorrect/confusing terms for things. I am however writing a blog ping server in Java using JAX-RS (Jersey), and I’m facing a problem where I have one servlet class that accepts REST input, and another servlet class that lists the same content.

Right now they are sharing their objects through a class that looks like this:

public class BlogPingUtils {

    private static final String LIST_OF_CHANGES = "listOfChanges";

    public static List<PingInfo> getListOfChanges(ServletContext context) {
        List<PingInfo> listOfChanges = (List<PingInfo>)context.getAttribute(LIST_OF_CHANGES);
        if(listOfChanges == null) listOfChanges = new ArrayList<PingInfo>();

        return listOfChanges;
    }

    public static void setListOfChanges(ServletContext context, List<PingInfo> listOfChanges) {
        context.setAttribute(LIST_OF_CHANGES, listOfChanges);
    }
}

This works in a small-scale development environment, but it feels dirty and probably wouldn’t work in a heavy-duty production environment because of concurrency issues and such. Also it’s not very flexible. What I would like to do is have an interface that would have methods for reading and writing data. Then I would inject an object of a class that implements this interface into these two servlets, so that they are actually using the same object for interacting with the data. This would then be backed by a synchronized list or database transactions or something.

What would be the preferred way to do this? Is it possible? My web.xml is very simple right now and looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
  <display-name>Blog Ping</display-name>

  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.vrutberg.blogping</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>
  • 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-31T08:18:37+00:00Added an answer on May 31, 2026 at 8:18 am

    Rather than a static class, I would design an Interface with your getters and setters, than create an implementation class.

    I would then register the singleton (or pool depending on your needs) implementation class with a thread-safe central repository visible by both servlets, such as JNDI.

    The servlets query the central repository and ‘cast’ to the interface.

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

Sidebar

Related Questions

I'm pretty new to this whole deployment thing. I've deployed my app once before
I am pretty new to this iPhone dev thing but so far I have
I'm pretty new to the whole DBus stuff so excuse me if this is
I'm pretty new to the whole node.js thing (as well as servers, javascript and
I am pretty new to the whole DI/IoC thing, so bear with me... I
I'm new at this whole Django thing and as such, I've decided to start
I'm pretty new to the whole Scala and Play thing so maybe my way
I am pretty new to the whole JavaScript thing. I have a gridview that
I'm pretty new at this. Tried to make sense of the manual page for
Ok, I'm pretty new to this and been struggling with what you guys may

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.