# Adding servlets

**URL:** <https://forum.inductiveautomation.com/t/adding-servlets/7549>\
**Category:** Module Development\
**Created:** [November 11, 2013, 2:16pm UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549 "2013-11-11T14:16:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [November 11, 2013, 2:16pm UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/1 "2013-11-11T14:16:33Z")

</div>

Hi,  
Does any one have an idea about adding servlets using addServlet method in gateway?  
Some pointers to examples will be appreciated.  
Regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [November 17, 2013, 8:10am UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/2 "2013-11-17T08:10:12Z")

</div>

Hi,  
Even if you add a servlet ingateway context usign addServelet method, I don't see any server names in the server tab in Eclipse ! Where do I see the web.xml to see existing servlets in the gateway context and to add the new servlet for my module that I want to add?  
SAny help will be appreciated.  
Regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [November 17, 2013, 10:27am UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/3 "2013-11-17T10:27:41Z")

</div>

Let me tell you what I did.

i add the following lines in main/WEB-INF/web.xml file.  
  
HelloServlet  
com.pramanj.test.gateway.HelloServlet  
  
  
HelloServlet  
/HelloServlet

where servlet file HelloServlet.java (which just prints "Hello World") is added to the same package where my-module.java is added. The module builds successfully, but when I enter localhost:8088/HelloServlet , I get a page displaying the standard ignition main page, not the expected new page with HelloWorld! It it getting redirected to main page on whatever value to enter in the page?How to supress the redirection for HelloServlet page?  
PRAMAN

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [November 18, 2013, 3:53pm UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/4 "2013-11-18T15:53:37Z")

</div>

This should work:

[localhost:8088/main/HelloServlet](http://localhost:8088/main/HelloServlet)

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [November 19, 2013, 3:21am UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/5 "2013-11-19T03:21:06Z")

</div>

# No actually [localhost:8088/main/HelloServlet](http://localhost:8088/main/HelloServlet) also gives following error.!

HTTP Status 404 - /main/HelloServlet

type Status report

message /main/HelloServlet

description The requested resource is not available.  
Apache Tomcat/6.0.36

===========  
Should i change the url-mapping to /main/HelloServlet ?  
regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [November 19, 2013, 6:00am UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/6 "2013-11-19T06:00:12Z")

</div>

I’m using the following pattern:

```auto
<url-pattern>/HelloServlet/*</url-pattern>
```

I’m also using a Filter, but that shouldn’t matter. You should try compiling your java file and packaging it up into a jar file that goes in the main/WEB-INF/lib folder.

Also, don’t forget to restart the gateway every time you make a change to the web.xml (or the jar file).

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [November 19, 2013, 4:12pm UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/7 "2013-11-19T16:12:35Z")

</div>

Hello,  
I have a servlet working successfully in Ignition.

I didn’t do anything with web.xml or main/WEB-INF/lib folder.

I simply called context.addServlet and then I was able to access the servlet from: [localhost:8088/main/system/MyServlet](http://localhost:8088/main/system/MyServlet)

For example, in my GatewayHook.java:

```auto
    @Override
    public void setup(GatewayContext context) {
        context.addServlet("MyServlet", MyServlet.class);
    }
```

Nick

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [November 20, 2013, 5:02am UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/8 "2013-11-20T05:02:42Z")

</div>

Thanks a lot every one for the response. I will try it and see if it works. Looks like Ignition does a lot of intelligent things hiding the lower level details from developers. It will be nice if Kevin can comment on how exactly the addServlet method in Ignition works?  
regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [November 20, 2013, 1:58pm UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/9 "2013-11-20T13:58:02Z")

</div>

yes it seems to work. unfortunately its not properly documented.  
best regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [December 1, 2013, 8:24am UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/10 "2013-12-01T08:24:21Z")

</div>

Now having solved the calling servlet problem (mysteriously!) , next question is how to add an HTML page in the main:8088 web application? As per the \tomcat\webapps\ROOT\WEB-INF\web.xml file every thing gets redirected to DefaultContextRedirector servlet.

Any thoughts will be appreciated.  
Regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [December 3, 2013, 3:40pm UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/11 "2013-12-03T15:40:03Z")

</div>

You should try putting your HTML files in the same directory as the WEB-INF and then calling the request dispatcher from your servlet:

```auto
request.getRequestDispatcher("/WEB-INF/" + request.getPathInfo() + ".html").forward(request, response);
```

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [December 4, 2013, 7:48am UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/12 "2013-12-04T07:48:10Z")

</div>

Thanks for the tip, i will think it over and try. But my worry is if Ignition itself puts a filter on the http requests and redirects all http to its main page then my servlet will not be called atall! Or may be i should first invoke my servlet manually which will redirtect to other THML pages of maine.

Am i missing something here?

Best regards  
PRAMANJ

---

<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:** [October 23, 2022, 1:51am UTC](https://forum.inductiveautomation.com/t/adding-servlets/7549/13 "2022-10-23T01:51:13Z")

</div>

Split this topic on October 23, 2022, 1:51am UTC

A post was split to a new topic: [Adding Servlets Redux](https://forum.inductiveautomation.com/t/adding-servlets-redux/65570)
