I'm new to working with Tomcat or jsp and servlets. In my jsp file is a form which calls out to a servlet like so: <form name="order" action="/trial/Ecom/ChocServlet" method="POST"> ..and this is fairly common I spose.
The compiled class file lies beside the jsp file i.e. in tha SAME folder as the jsp file. But when I try to access it through the jsp page, it give me an error "The requested resource (/trial/Ecom/ChocServlet) is not available."
Do I have to do something like servlet mapping in the web.xml file? Is that whats wrong? I dont understand how to do this whole mapping thingie.. I have tried going through many many pages looking for how to fix this. And have tried searching through thi forum as well. Help on how to get my servlet to work would be GREATLY appreciated.
ok this will take some time..but here it is. I will explain first the tomcat directory structure and then deploying a servlet on tomcat as well.
1. Download tomcat from here
2. Install tomcat. On my windows 2000 box after installation the tomcat root dorectory is at this location C:\tomcat5.5.15
It may be different on your machine.
if you go in the root directory, there are some directories you want to know to be the least. Mind you there are several more directories in there but these are which u may be working with mostly.
----------------\conf ----> it has server..xml file that contains configurations
----------------\webapps ----> this is where a new application may be dropped.(A complete webapplication contains a root folder, WEB-INF folder, classes folder and a web.xml file)
if you go to webapps folder, you will see that it has a folder named "ROOT", this is the folder where there are default html pages that are served when u start your tomcat server. jsp's could be here or in any other web application folders.
For a simple testing of a servlet you can use the default web-inf folder that is in the ROOT folder.
Here is example jsp page, a servlet and part of the web.xml file for our testing.
for this testing I will place mytest.jsp in the ROOT folder and servlet in the classes folder like below
Now make sure that you have exact structure as above( ofcourse file names could be the files names that you actually have on your machine)
Here is the entry that you require in the web.xml to access this servlet.
See in the first part in element servlet, you are letting the server know that there is a servlet that u want to use, therefore server will recognise that name.<servlet-name>, this value must always be the same as in url-mapping elements <servlet-name> element.
Then you must tell tomcat that where this file is at, i n this case we know its here,
so since there is no package the path to this class file ins as below
Now we need to set the mapping for the servlet so that we can tell tomcat how the above servlet may be accessed.
The first element is the servlet name which points to a class file in the tomcats web-inf dir
The second element is the pattern which you want to type in the browser window to access this servlet.For our purposes we can say the url-pattern is as below
there you go, Now reboot the tomcat.
And you can access the servlet by typing the following in the browser window (tomcat installation by default sets the port:8080 for itself)
From Browser. http://localhost:8080/servlets/mytestServlet
or as in your case your forms action elements value
javax.servlet.ServletException: Wrapper cannot find servlet class HelloServlet.class or a class it depends on
post the web.xml part here both servlet and mapping elements.
Second post the locations where jsps are and where web-inf is and where web.xml is and where the servlet is.
Seems like the path to servlet is wrong in web.xml
well, i uninstalled everything. and reinstalled it all (for the gazillionth time.. ok ok maybe the 3th time) :P and did everythign exactly the way i'd been doing it for the past two days.. (exactly how uve laid down up there) but this time i didnt forget to ask Allah and it worked!! subhaaanallah..
thanks again for all ur help. it cleared everything up.
i'm afraid you're mistaken and ull realise one day that grey areas DONT EXIST. "innahu 3ala kulli shai2in qadeer" what if i forget one darned semicolon, over and over again. no black and white eye could find that if that is not His Will programming may be black n white, and if thats the case, then i have a splash of colours with me! take care!