# \[FEATURE\] Using servlet in custom module

**URL:** <https://forum.inductiveautomation.com/t/feature-using-servlet-in-custom-module/36753>\
**Category:** Module Development\
**Created:** [July 16, 2020, 9:39am UTC](https://forum.inductiveautomation.com/t/feature-using-servlet-in-custom-module/36753 "2020-07-16T09:39:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrea.morando](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/andrea.morando/32/8039_2.png) [@andrea.morando](https://forum.inductiveautomation.com/u/andrea.morando)\
**Post date:** [July 16, 2020, 9:39am UTC](https://forum.inductiveautomation.com/t/feature-using-servlet-in-custom-module/36753/1 "2020-07-16T09:39:33Z")

</div>

Dears,  
I would like to try using a servlet inside a custom module.  
I am able to add/remove the servlet in the gateway hook of the module, via:

> gatewayContext.getWebResourceManager().addServlet({servlet}.PATH, {servlet}.class);
> 
> gatewayContext.getWebResourceManager().removeServlet({servlet}.PATH);

I am wondering if I would be able to access, from the servlet, a class object instantiated in the startup of the module gateway hook.

Thank you.  
Best regards.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 16, 2020, 11:54am UTC](https://forum.inductiveautomation.com/t/feature-using-servlet-in-custom-module/36753/2 "2020-07-16T11:54:16Z")

</div>

You’ll have to use a static method in your Gateway Hook class to access a static field containing the object of interest. Store the object of interest in the static field during setup or startup.

---

<div class="post-metadata">

**Author:** ![andrea.morando](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/andrea.morando/32/8039_2.png) [@andrea.morando](https://forum.inductiveautomation.com/u/andrea.morando)\
**Post date:** [July 16, 2020, 3:45pm UTC](https://forum.inductiveautomation.com/t/feature-using-servlet-in-custom-module/36753/3 "2020-07-16T15:45:31Z")

</div>

Thank you, @pturmel. That’s the right approach.
