5 Replies Latest reply on Oct 30, 2003 10:35 AM by 843810

    Servlet Error

    843810
      Hi,
      I am trying to run Servlet prog for the 1st time but its giving me following error:

      HTTP Status 404-
      /Servlets/Bra

      The requested resource(/servlets/Brat) is not available.

      I have installed the Brat.java file in the following folder :
      e:\e-data\tomcat40\examples\servlets

      If I try o run JSP file its running fine so I feel here is no prob with Tomcat server.

      I have written the following code in my servlet file:

      import javax.servlet.*;
      import java.io.*;
      public class Brat extends GenericServlet
      {
      publc void init (ServletConfig sc)
      throws ServletException
      {
      System.out.println("I don wana wake up");
      }
      public void service (ServletRequest req, ServletResponse res)
      throws ServletException
      {
      try{
      ServletOutputSream sos=res.getOutputStream();
      sos.println("I dont wanna do anyhing");
      sos.close();
      }
      catch(IOException ioe) {ioe.printStackTrace();}
      }


      public void desroy()
      {
      System.out.println("I dont wana go to bed");
      }
      }
      I am using the following URL:
      localhost:8080/examples/servlets/Brat

      Can somebody help me with this prob.?

      Zulfi.
        • 1. Re: Servlet Error
          843810
          I have installed the Brat.java file in the following folder :
          e:\e-data\tomcat40\examples\servlets
          Is this a typo error when posting?
          (Of course you have to install Brat.class not your source file Brat.java)

          If that's the reason for your problem, it is easy to solve.
          If not, i dont't have any ideas.

          Greetings.
          • 2. Re: Servlet Error
            843810
            Thanks for your advise. I have stored the compile java i.e
            class file in the servlet folder but sill I am getting the same tomcat server error. I have also modified the web.xml file but is sill giving me the error.
            Web.xml file is:
            <?xml version="1.0" encoding="ISO-8859-1"?>

            <!DOCTYPE web-app
            PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
            "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

            <web-app>

            <!-- Define servlet-mapped and path-mapped example filters -->
            <filter>
            <filter-name>Servlet Mapped Filter</filter-name>
            <filter-class>filters.ExampleFilter</filter-class>
                 <init-param>
                 <param-name>attribute</param-name>
                 <param-value>filters.ExampleFilter.SERVLET_MAPPED</param-value>
                 </init-param>
            </filter>
            <filter>
            <filter-name>Path Mapped Filter</filter-name>
            <filter-class>filters.ExampleFilter</filter-class>
                 <init-param>
                 <param-name>attribute</param-name>
                 <param-value>filters.ExampleFilter.PATH_MAPPED</param-value>
                 </init-param>
            </filter>
            <filter>
            <filter-name>Request Dumper Filter</filter-name>
            <filter-class>filters.RequestDumperFilter</filter-class>
            </filter>

            <filter>
            <filter-name>Compression Filter</filter-name>
            <filter-class>compressionFilters.CompressionFilter</filter-class>

            <init-param>
            <param-name>compressionThreshold</param-name>
            <param-value>10</param-value>
            </init-param>
            <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
            </init-param>
            </filter>

            <!-- Define filter mappings for the defined filters -->
            <filter-mapping>
            <filter-name>Servlet Mapped Filter</filter-name>
                 <servlet-name>invoker</servlet-name>
            </filter-mapping>
            <filter-mapping>
            <filter-name>Path Mapped Filter</filter-name>
                 <url-pattern>/servlet/*</url-pattern>
            </filter-mapping>

            <!--
            <filter-mapping>
            <filter-name>Compression Filter</filter-name>
            <url-pattern>/CompressionTest</url-pattern>
            </filter-mapping>
            -->

            <!--
            <filter-mapping>
            <filter-name>Request Dumper Filter</filter-name>
            <url-pattern>/*</url-pattern>
            </filter-mapping>
            -->

            <!-- Define example application events listeners -->
            <listener>
            <listener-class>listeners.ContextListener</listener-class>
            </listener>
            <listener>
            <listener-class>listeners.SessionListener</listener-class>
            </listener>

            <!-- Define servlets that are included in the example application -->
            <servlet>
            <servlet-name>
            snoop
            </servlet-name>
            <servlet-class>
            SnoopServlet
            </servlet-class>
            <!--
            <init-param>
            <param-name>foo</param-name>
            <param-value>bar</param-value>
            </init-param>
            -->
            <run-as>
            <description>Security role for anonymous access</description>
            <role-name>tomcat</role-name>
            </run-as>
            </servlet>
            <servlet>
            <servlet-name>
            servletToJsp
            </servlet-name>
            <servlet-class>
            servletToJsp
            </servlet-class>
            </servlet>
            <servlet>
            <servlet-name>
            CompressionFilterTestServlet
            </servlet-name>
            <servlet-class>
            compressionFilters.CompressionFilterTestServlet
            </servlet-class>

            </servlet>



                 <servlet>
                 <servlet-name>
                      Brat
                 </servlet-name>
                 <servlet-class>
                      Brat
                 </servlet-class>
                 </servlet>

                 <servlet-mapping>
                 <servlet-name>
                      Brat
                 </servlet-name>
                 <url-pattern>
                 /Brat
                 </url-pattern>
                 </servlet-mapping>

                 <servlet-mapping>
            <servlet-name>
            CompressionFilterTestServlet
            </servlet-name>
            <url-pattern>
            /CompressionTest
            </url-pattern>
            </servlet-mapping>

            <servlet-mapping>
            <servlet-name>
            snoop
            </servlet-name>
            <url-pattern>
            /snoop
            </url-pattern>
            </servlet-mapping>
            <servlet-mapping>
            <servlet-name>
            servletToJsp
            </servlet-name>
            <url-pattern>
            /servletToJsp
            </url-pattern>
            </servlet-mapping>

            <taglib>
            <taglib-uri>
                 http://java.apache.org/tomcat/examples-taglib
            </taglib-uri>
            <taglib-location>
            /WEB-INF/jsp/example-taglib.tld
            </taglib-location>
            </taglib>

            <resource-ref>
            <res-ref-name>mail/session</res-ref-name>
            <res-type>javax.mail.Session</res-type>
            <res-auth>Container</res-auth>
            </resource-ref>

            <security-constraint>
            <display-name>Example Security Constraint</display-name>
            <web-resource-collection>
            <web-resource-name>Protected Area</web-resource-name>
                 <!-- Define the context-relative URL(s) to be protected -->
            <url-pattern>/jsp/security/protected/*</url-pattern>
                 <!-- If you list http methods, only those methods are protected -->
                 <http-method>DELETE</http-method>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
                 <http-method>PUT</http-method>
            </web-resource-collection>
            <auth-constraint>
            <!-- Anyone with one of the listed roles may access this area -->
            <role-name>tomcat</role-name>
                 <role-name>role1</role-name>
            </auth-constraint>
            </security-constraint>

            <!-- Default login configuration uses form-based authentication -->
            <login-config>
            <auth-method>FORM</auth-method>
            <realm-name>Example Form-Based Authentication Area</realm-name>
            <form-login-config>
            <form-login-page>/jsp/security/login/login.jsp</form-login-page>
            <form-error-page>/jsp/security/login/error.jsp</form-error-page>
            </form-login-config>
            </login-config>

            <!-- Environment entry examples -->
            <!--env-entry>
            <env-entry-description>
            The maximum number of tax exemptions allowed to be set.
            </env-entry-description>
            <env-entry-name>maxExemptions</env-entry-name>
            <env-entry-value>15</env-entry-value>
            <env-entry-type>java.lang.Integer</env-entry-type>
            </env-entry-->
            <env-entry>
            <env-entry-name>minExemptions</env-entry-name>
            <env-entry-value>1</env-entry-value>
            <env-entry-type>java.lang.Integer</env-entry-type>
            </env-entry>
            <env-entry>
            <env-entry-name>foo/name1</env-entry-name>
            <env-entry-value>value1</env-entry-value>
            <env-entry-type>java.lang.String</env-entry-type>
            </env-entry>
            <env-entry>
            <env-entry-name>foo/bar/name2</env-entry-name>
            <env-entry-value>true</env-entry-value>
            <env-entry-type>java.lang.Boolean</env-entry-type>
            </env-entry>
            <env-entry>
            <env-entry-name>name3</env-entry-name>
            <env-entry-value>1</env-entry-value>
            <env-entry-type>java.lang.Integer</env-entry-type>
            </env-entry>
            <env-entry>
            <env-entry-name>foo/name4</env-entry-name>
            <env-entry-value>10</env-entry-value>
            <env-entry-type>java.lang.Integer</env-entry-type>
            </env-entry>

            <!-- EJB Reference -->
            <ejb-ref>
            <description>Example EJB Reference</description>
            <ejb-ref-name>ejb/Account</ejb-ref-name>
            <ejb-ref-type>Entity</ejb-ref-type>
            <home>com.mycompany.mypackage.AccountHome</home>
            <remote>com.mycompany.mypackage.Account</remote>
            </ejb-ref>

            <!-- Local EJB Reference -->
            <ejb-local-ref>
            <description>Example Local EJB Reference</description>
            <ejb-ref-name>ejb/ProcessOrder</ejb-ref-name>
            <ejb-ref-type>Session</ejb-ref-type>
            <local-home>com.mycompany.mypackage.ProcessOrderHome</local-home>
            <local>com.mycompany.mypackage.ProcessOrder</local>
            </ejb-local-ref>


            </web-app>

            Name of my servlet is Brat.

            Zulfi.
            • 3. Re: Servlet Error
              843810
              I have changed my web.xml file. Its small now:

              <?xml version="1.0" encoding="ISO-8859-1"?>

              <!DOCTYPE web-app
              PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
              "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

              <web-app>
              <servlet>
              <servlet-name>Brat</servlet-name>
              <servlet-class>Brat</servlet-class>
              </servlet>
              <servlet-mapping>
              <servlet-name>Brat</servlet-name>
              <url-pattern>/Brat</url-pattern>
              </servlet-mapping>
              </web-app>

              My URL is:

              http://localhost:8080/examples/Brat

              & I have copied Brat.class in the webapps,
              webapps/examples, webapps/examples/servlets direcories but still its complaining about its location. I am getting following errors at different imes:




              HTTP Status 503 - Servlet Brat is currently unavailable
              The requested service (Servlet Brat is currently unavailable) is not currently available.


              A Servlet Exception Has Occurred
              Exception Report:

              javax.servlet.ServletException: Wrapper cannot find servlet class Brat or a class it depends on
                   at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:797)
                   at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:602)
                   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
                   at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
                   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
                   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:225)
                   at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
                   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
                   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
                   at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2252)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
                   at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
                   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:446)
                   at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
                   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
                   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
                   at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
                   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
                   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
                   at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:875)
                   at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:952)
                   at java.lang.Thread.run(Thread.java:484)

              Root Cause:

              java.lang.ClassNotFoundException: Brat
                   at org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:1111)
                   at org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:976)
                   at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:792)
                   at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:602)
                   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
                   at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
                   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
                   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:225)
                   at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
                   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
                   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
                   at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2252)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
                   at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
                   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:446)
                   at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
                   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
                   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
                   at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
                   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
                   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
                   at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:875)
                   at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:952)
                   at java.lang.Thread.run(Thread.java:484)

              Can somebody plz help me?
              Zulfi.
              • 4. Re: Servlet Error
                843810
                This prob. is solved now.

                Zulfi.
                • 5. Re: Servlet Error
                  843810
                  I have a sort of the same problem! can you tell me how you solved it?

                  Thx!
                  frascic