hi i am new to servlet. i am learning myself using headfirst jsp and servet. i have read the first chapter in that book. and i tried the example given in that first chapter. i followed the steps like in that book . while running the servlet i am getting error like HTTP Status 404 - /Ch1/Serv1 type Status report message /Ch1/Serv1
description The requested resource (/Ch1/Serv1) is not available.
1. i have created directory structure Project1 which has src,classes,etc as sub directory. 2. src has source file 3.etc has web.xml 4.i have build another directory structure under tomcat tomcat->webapps->Ch1->WEB-INF->classes 5.web-inf has a web.xml and the folder classes, which has class file of the source 6.i started the web server while running its showing error
can you please any one do the needful. and tell me if any alternative method is there
There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
---------------------------------------------------- please ensure that <servlet-class> tag contains a valid relative path of the actual servlet class you are requesting for.
Putting it simple:
Ch1> WEB-INF>web.xml classes>serv1.class then <servlet> <servlet-name>Chapter1Servlet</servlet-name> <servlet-class>Ch1/Serv1</servlet-class> </servlet>
It is the fully-qualified class name of the servlet
Moreover, you are advised to put your servlets (like anything else) in packages. Don't put them directly under WEB-INF/classes, or you may get strange behaviours. Make some packages. Like "WEB-INF/classes/servlets"
For example, jsp:useBean does not work correctly with classes in the default package. So I think it's good practice to use packages. It's only an advice though
Originally posted by Jothi Shankar Kumar Sankararaj: Satou,
Why is that we get Strange behaviors when we don't put our servlets in packages??
Strange because you can get away with it for some types of objects but not others. There are specific reasons for this (explained here) but it's much simpler just to package everything than it is to understand all the reasoning that goes behind it.