*
The moose likes Tomcat and the fly likes Servlets are not accessible but jsps are accessible. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Servlets are not accessible but jsps are accessible." Watch "Servlets are not accessible but jsps are accessible." New topic
Author

Servlets are not accessible but jsps are accessible.

Narasimha Rao B.
Ranch Hand

Joined: Aug 26, 2002
Posts: 205
Hi,

Please help me out resolving the below issues - Just now i have installed tomcat 5.0, through the url i couldn't access any of my own servlets and also examples that were installed through tomcat installation but through the url i could access the jsps. Here is the tree structure of my servlet class file,
Installation_directory/webapps/ch1/WEB-INF/classes/Ch1Servlet.class
In the URL i am giving the path as,
http://localhost:8080/ch1/Ch1Servlet
I am getting the error as "The requested resource (/ch1/Ch1Servlet) is not available."
Even this problem persist with the tomcat examples, One of the servlet class is located at --
install_directoty\webapps\servlets-examples\WEB-NF\classes\HelloWorldExample
I am trying to access this servlet through -
http://localhost:8080/servlets-examples/HelloWorldExample
but i am getting the error -
"The requested resource (/servlets-examples/HelloWorldExample) is not available."
But i could access successfully jsps, please help me out in resolving the issue.
Thanks in Advance


Narasimha
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
I think both of those problems are due to the fact that the servlets are not in packages. Prior to Tomcat 4 you were able to address servlets that are not in packages by means of the "invoker" servlet. This "convenience" has caused vast frustration for people starting in servlets since the invoker is now off by default in Tomcat. See this JavaRanch FAQ on the invoker.
All classes used in servlets should be in packages - of course the directory path under WEB-INF/classes must reflect that.
Bill
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Hi Narasimha

I have some useful points for Tomcat...and am sending the same to you.
Check them and out and try again.

The things that we have to look into while creating our own web apps are

1. The directory structure is proper
say some c:\Tomcat\webapps\OwnApp
2. Then inside our application, we need to create a web-inf
say c:\Tomcat\webapps\OwnApp\WEB_INF
3. Then we can arrange our own things here in this space

a. Java Script Files
say c:\Tomcat\webapps\OwnApp\WEB_INF\script - say

b. CSS
say c:\Tomcat\webapps\OwnApp\WEB_INF\css - Say

c. Images
say c:\Tomcat\webapps\OwnApp\WEB_INF\Images - say

d. Of course our servlets will be in the classes folder

say c:\Tomcat\webapps\OwnApp\WEB_INF\classes.

e. And beans in a package
say c:\Tomcat\webapps\OwnApp\WEB_INF\classes\mypack\mybeans\com\SomeBeanClass

And don't forget to have ur own web.xml configured for ur new servlets....

Cheers,
Swamy
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlets are not accessible but jsps are accessible.