# Custom servlets on the Gateway

**URL:** <https://forum.inductiveautomation.com/t/custom-servlets-on-the-gateway/2994>\
**Category:** Module Development\
**Created:** [June 6, 2011, 2:23pm UTC](https://forum.inductiveautomation.com/t/custom-servlets-on-the-gateway/2994 "2011-06-06T14:23:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cgz](https://avatars.discourse-cdn.com/v4/letter/c/8dc957/32.png) [@cgz](https://forum.inductiveautomation.com/u/cgz)\
**Post date:** [June 6, 2011, 2:23pm UTC](https://forum.inductiveautomation.com/t/custom-servlets-on-the-gateway/2994/1 "2011-06-06T14:23:11Z")

</div>

I’m investigating how to make Gateway instances communicate with each other.  
I didn’t find anything advanced or anything obvious, useful for my purpose.

At the moment, I am thinking of making a custom servlet as a module. The weather  
example shows that it shouldn’t be a problem to contact the servlet, but  
how do configure the servlet to serve requests?

Thanks!

---

<div class="post-metadata">

**Author:** ![Kevin.McClusky](https://avatars.discourse-cdn.com/v4/letter/k/47e85d/32.png) [@Kevin.McClusky](https://forum.inductiveautomation.com/u/Kevin.McClusky)\
**Post date:** [June 6, 2011, 4:22pm UTC](https://forum.inductiveautomation.com/t/custom-servlets-on-the-gateway/2994/2 "2011-06-06T16:22:06Z")

</div>

You can use a basic class that you write that extends HttpServlet. You don’t have to write anything Ignition-specific to use servlets.

The basic servlet looks something like MyServlet.java here:

[javabeanz.wordpress.com/2009/02/ … et-filter/](http://javabeanz.wordpress.com/2009/02/11/how-to-write-a-simple-servlet-filter/)

You implement doGet() and/or doPost(), and can use information in the request object to decide what to send back in the response.

There are plenty of examples on this online as well.

In your module hook, as in the example, do a context.addServlet(servletName, servletClass);

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [July 21, 2011, 10:00pm UTC](https://forum.inductiveautomation.com/t/custom-servlets-on-the-gateway/2994/3 "2011-07-21T22:00:03Z")

</div>

That’s right - one more thing. Invariably your servlet will want access to the Context. Add a function like this:

`private GatewayContext getContext() {
	GatewayContext context = (GatewayContext) getServletContext().getAttribute(GatewayContext.SERVLET_CONTEXT_KEY);
	return context;
}`
