简体   繁体   English

Java Servlet-2.3在Websphere Liberty Profile 8.5.5.6中不起作用

[英]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. 我们有一个Java Web应用程序在IBM Websphere Liberty概要文件服务器中运行。 We have recently developed a Java Servlet which is responsible to generate JFreeCharts using Java library. 我们最近开发了一个Java Servlet,它负责使用Java库生成JFreeCharts。

Code in web.xml 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 index.html文件中的代码

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

Code in GraphicsServlet.java 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. 此Servlet实现了doGet方法,并且该方法中的业务逻辑使用JFreeCharts生成图表图像文件(.png),并且此图像作为响应以流的形式返回。

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. 访问应用程序时,默认情况下显示index.html文件,并且此页面上的部分需要显示JFreeChart生成的图表。

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. 使用浏览器的开发人员工具,我发现当请求发送到* .img Url时,将显示404错误。 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. 接下来,我试图找出该Servlet是否确实已部署到服务器上,或者是否有机会在.war文件中丢失,然后检查了Websphere中的部署文件夹,并找到了已部署的Servlet。 Next, I tried to check if Servlet is up and running. 接下来,我尝试检查Servlet是否已启动并正在运行。 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. 从一个新的浏览器,我发送了一个测试请求,例如http:// localhost:9080 / myapp / summary / chart.img ,它在屏幕上返回了404错误。

I wanted to know why servlet is not getting up. 我想知道为什么servlet没有启动。 So, I implemented the init() method of HttpServlet in my GraphicsServlet and written a print statement. 因此,我在GraphicsServlet中实现了HttpServlet的init()方法,并编写了一条打印语句。 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. 最后,我尝试注释掉doGet方法的每一行,即使我在屏幕上收到404错误。

Problem Description : I want to know why the GraphicsServlet is not getting up. 问题描述 :我想知道为什么GraphicsServlet没有起床。 Please let me know if there are any techniques to know the reason behind the failure of GraphicServlet. 请让我知道是否有任何技术可以知道GraphicServlet失败的原因。

Update 1: I tried removing the configuration in web.xml and annotated the GraphicServlet with @WebServlet annotation. 更新1:我尝试删除web.xml中的配置,并使用@WebServlet注释对GraphicServlet进行注释。 Now, I am able to see those print statements and it is now confirmed that GraphicServlet is up and running when annotation is used. 现在,我可以看到这些打印语句,并且现在可以确认使用注解时GraphicServlet已启动并正在运行。 So, I started looking at web.xml DOCTYPE tag. 因此,我开始查看web.xml DOCTYPE标记。 The version of Web app DTD was very old. Web应用程序DTD的版本非常旧。 It was 2.3 version, and the Java version we installed is 1.8. 它是2.3版本,而我们安装的Java版本是1.8。 Can anyone here let me know whats the problem with WebApp-2.3 ? 有人可以让我知道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. 更新2:我从GraphicServlet中删除了@WebServlet批注,并再次尝试了xml配置,还将web.xml文件中的Web应用版本从2.3更改为3.1(也为3.0)。 The GraphicServlet is still not up and running. GraphicServlet仍未启动并运行。

Update 3: I have noticed that javaee-7.0 feature is being used in the Websphere server.xml file. 更新3:我注意到Websphere server.xml文件中正在使用javaee-7.0功能。

Thanks for your patience. 谢谢你的耐心。

Maybe you should change your servlet mapping in web.xml to be like this: 也许您应该更改web.xml中的servlet映射,如下所示:

/summary/*.img /summary/*.img

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM