DilipKumarC
DilipKumarC

Reputation: 15

Java Servlet-2.3 not working in Websphere Liberty Profile 8.5.5.6

We have a Java Web application running in IBM Websphere Liberty profile server. We have recently developed a Java Servlet which is responsible to generate JFreeCharts using Java library.

Code in web.xml

<servlet>
    <servlet-name>GraphicServlet</servlet-name>
    <servlet-class>com.test.GraphicServlet</servlet-class>
    <load-on-startup>10</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>GraphicServlet</servlet-name>
    <url-pattern>*.img</url-pattern>
</servlet-mapping>

Code in index.html file

<img src="summary/chart.img" height="100" width="100" />

Code in GraphicsServlet.java

This Servlet has doGet method implemented and the business logic in the method generates a chart image file(.png) using JFreeCharts and this image is returned as response in form of stream.

Application flow:

When application is accessed, index.html file is displayed by default and this page has a section where chart generated by JFreeChart needs to be displayed.

Scenario Description:

The Image file is not getting displayed when application is accessed. Using the browser's developer tools, I have found that 404 error is printed when a request is sent to *.img Url. Next, I tried to find out if that Servlet is really deployed on to the server or missed in the .war file by any chance, and I checked the deployment folder in websphere and found the Servlet deployed. Next, I tried to check if Servlet is up and running. From a new browser, I sent a test request like http://localhost:9080/myapp/summary/chart.img, it returned 404 error on to the screen.

I wanted to know why servlet is not getting up. So, I implemented the init() method of HttpServlet in my GraphicsServlet and written a print statement. I didnot get that print when the application finished loading. Finally, I tried with commenting out every line of doGet method, even then I received 404 Error on the screen.

Problem Description: I want to know why the GraphicsServlet is not getting up. Please let me know if there are any techniques to know the reason behind the failure of GraphicServlet.

Update 1: I tried removing the configuration in web.xml and annotated the GraphicServlet with @WebServlet annotation. Now, I am able to see those print statements and it is now confirmed that GraphicServlet is up and running when annotation is used. So, I started looking at web.xml DOCTYPE tag. The version of Web app DTD was very old. It was 2.3 version, and the Java version we installed is 1.8. Can anyone here let me know whats the problem with WebApp-2.3 ?

Update 2: I removed the @WebServlet annotation from GraphicServlet and again I tried with xml configuration and also changing the Web-app version from 2.3 to 3.1 (also 3.0) in web.xml file. The GraphicServlet is still not up and running.

Update 3: I have noticed that javaee-7.0 feature is being used in the Websphere server.xml file.

Thanks for your patience.

Upvotes: 0

Views: 1220

Answers (1)

tsolakp
tsolakp

Reputation: 5948

Maybe you should change your servlet mapping in web.xml to be like this:

/summary/*.img

Upvotes: 1

Related Questions