File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes The requested resource (/mycode/AA) is not available Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "The requested resource (/mycode/AA) is not available" Watch "The requested resource (/mycode/AA) is not available" New topic
Author

The requested resource (/mycode/AA) is not available

Rashmi Pant
Greenhorn

Joined: Dec 19, 2007
Posts: 25
Hi,
Thanks to all of you as because of your support i am able to know about servlet.Today i have a new but very simple problem i think all of you must know solution for this but i do not.So hope you will also help me this time.
My problem is as :
I am just writting simple servlets i mean i m testing different servlet.
I am using jdk1.5 and Tomcat5.0.intallation directory for these are as :
C:\Program Files\Java\jdk1.5.0_12 &
C:\Tomcat5.0
I am able to run servlet properly.
I want to create a new folder under "C:\Tomcat5.0\webapps" and want to put my servlet under this atruture.I am going to tell you what i had done.
I created a folder mycode under C:\Tomcat5.0\webapps and after this i had created WEB-INF folder inside mycode dir so the directory structure is as:
C:\Tomcat5.0\webapps\mycode\WEB-INF
Now i created classes folder inside WEB-INF folder and place an web.xml file(just done copy past from different folder)inside WEB-INF folder.
So the WEB-INF folder contains classes and web.xml file.
After this i put a AA.class file(this is a simlpe servlet file) inside classes folder and added or modified the web.xml file as:

<servlet>
<servlet-name>AA</servlet-name>
<servlet-class>AA</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>AA</servlet-name>
<url-pattern>/mycode</url-pattern>
</servlet-mapping>

So the code for my web.xml file is as:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2004 The Apache Software Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

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

<web-app>

<display-name>Servlet 2.4 Examples</display-name>
<description>
Servlet 2.4 Examples.
</description>

<!-- 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>

<!-- Example filter to set character encoding on each request -->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>EUC_JP</param-value>
</init-param>
</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>


<!-- Example filter mapping to apply the "Set Character Encoding" filter
to *all* requests processed by this web application -->
<!--
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</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>AA</servlet-name>
<servlet-class>AA</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>AA</servlet-name>
<url-pattern>/mycode</url-pattern>
</servlet-mapping>


<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/protected/login.jsp</form-login-page>
<form-error-page>/jsp/security/protected/error.jsp</form-error-page>
</form-login-config>
</login-config>

<!-- Security roles referenced by this web application -->
<security-role>
<role-name>role1</role-name>
</security-role>
<security-role>
<role-name>tomcat</role-name>
</security-role>

<!-- 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>

</web-app>

Now when i am trying to run this servlet as :
http://localhost:8080/mycode/AA

I am getting following error message
HTTP Status 404 - /mycode/AA

--------------------------------------------------------------------------------

type Status report

message /mycode/AA

description The requested resource (/mycode/AA) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.28

Now please tell me what silly mistake i am doing.
Thanks to all
Rashmi
[ December 26, 2007: Message edited by: Bear Bibeault ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

First, I'm wondering if you're not misunderstanding one thing : you have set the description to "Servlet 2.4 Examples", but you are using a 2.3 web.xml. Check here if you want to know how to use a 2.4 web.xml.


This mapping is not correct. You don't need to include the root of your application in it. You want to declare it that way :

This maps http://localhost:8080/mycode/AA to your AA servlet. (and don't forget that you'd better put your servlets in packages)


[My Blog]
All roads lead to JavaRanch
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
<servlet-class>AA</servlet-class>


All classes used in servlets MUST be placed in packages in order to avoid mystery errors such as you experienced. The basic problem is that the JVM will look for a class in the "default" (ie none specified) package in the "current" directory - you have NO control over what a servlet container thinks is the current directory. Yes, I know that some older examples use the default directory, typically with the "invoker" servlet. This was a bad idea then and its a bad idea now.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The requested resource (/mycode/AA) is not available