java web app- unable to see jsp file after adding content to web.xml for servlet context listener

622 Views Asked by At

I have added the following content to my web.xml for a servlet context listener---

 <listener>
 <listener-class>
 com.anyaservices.log4j.ApplicationServletContextListener
 </listener-class>
 </listener>

I have added this immediately after the end of "welcome-file-list"

The last line of the welcome-file-list node is given below--

 </welcome-file-list>

Now, I have made some changes to a servlet so that it can use the context listener... in addition to the servlet there is a "Hello.jsp" file that just displays a welcome message.

I have not made any changes to the JSP file. However after my code changes for the servlet context listener, when I try to go to Hello.jsp I get an error in Tomcat= The requested resource is not available.

What have I done wrong here? Why is the JSP file not being shown now?

EDIT-- I have posted the entire content of my web.xml below--

  <?xml version="1.0" encoding="UTF-8"?>
  <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <display-name>Test Web Application</display-name>
    <welcome-file-list>
      <welcome-file>index.html</welcome-file>
      <welcome-file>index.htm</welcome-file>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>default.html</welcome-file>
      <welcome-file>default.htm</welcome-file>
      <welcome-file>Hello.jsp</welcome-file>
    </welcome-file-list>
    <listener>
    <listener-class>
     com.test.log4j.ApplicationServletContextListener
    </listener-class>
  </listener>
    <servlet>
      <description>Used to run a single crawl job</description>
      <display-name>runsinglecrawljob</display-name>
      <servlet-name>runsinglecrawljob</servlet-name>
      <servlet-class>com.test.runsinglecrawljob</servlet-class>
    </servlet>
    <servlet-mapping>
      <servlet-name>runsinglecrawljob</servlet-name>
      <url-pattern>/runsinglecrawljob</url-pattern>
    </servlet-mapping>
    <servlet>
      <description>Home page</description>
      <display-name>home</display-name>
      <servlet-name>home</servlet-name>
      <servlet-class>home</servlet-class>
    </servlet>
    <servlet-mapping>
      <servlet-name>home</servlet-name>
      <url-pattern>/home</url-pattern>
    </servlet-mapping>
    <servlet>
      <description>Run a single crawl job after asking users for parameters of that       job</description>
      <display-name>runsinglejob</display-name>
      <servlet-name>runsinglejob</servlet-name>
      <servlet-class>com.test.runsinglecrawljob</servlet-class>
    </servlet>
    <servlet-mapping>
      <servlet-name>runsinglejob</servlet-name>
      <url-pattern>/runsinglejob</url-pattern>
    </servlet-mapping>

  </web-app>

The URL I am trying to access is http ://localhost:8080/test_web_app/Hello.jsp

1

There are 1 best solutions below

0
On

Tomcat handles JSP files through org.apache.jasper.servlet.JspServlet. Perhaps somehow your listener class is interfering with the operation of the JspServlet. There is no need to list all of those files in your welcome file list. Any jsp file inside the war should be available (but it should not be placed inside the WEB-INF or META-INF folders.)

I think you should check your log4j configuration. Did you initialize log4j with a log4j.properties file in WEB-INF/classes?