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:
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">
<!-- 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>
<!-- 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> -->
<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>
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 :
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.