How to debug a servlet
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
I am trying to execute a simple Servlet but I am getting a "Requested Resource Not Available Error".
What I did was,
Installed tomcat 5.5.15 and set the java_home and catalina_home respectively to jdk and tomcat directories.
Developed a html page and dropped it in rootdir/webapps/root/first
Accessed it as, http://localhost:8080/first/index.html
I got the html output. So I assumed tomcat is working fine.
Later I wrote a sample servlet class, by name Hello.java and successfully compiled it. Placed it in rootdir/webapps/root/first/WEB-INF/classes directory.
Later, I wrote the web.xml file and deployed it in
rootdir/webapps/root/first/WEB-INF.
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hithere</url-pattern>
</servlet-mapping>
</web-app>
I tried to access it as http://localhost:8080/first/hithere
But it was not working and I got a requested resource not available error.
Is there anyway to debug my application. Everything seems to be right. This is driving me crazy.
Any input will be highly appreciated.
Thanks.
I am trying to execute a simple Servlet but I am getting a "Requested Resource Not Available Error".
What I did was,
Installed tomcat 5.5.15 and set the java_home and catalina_home respectively to jdk and tomcat directories.
Developed a html page and dropped it in rootdir/webapps/root/first
Accessed it as, http://localhost:8080/first/index.html
I got the html output. So I assumed tomcat is working fine.
Later I wrote a sample servlet class, by name Hello.java and successfully compiled it. Placed it in rootdir/webapps/root/first/WEB-INF/classes directory.
Later, I wrote the web.xml file and deployed it in
rootdir/webapps/root/first/WEB-INF.
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hithere</url-pattern>
</servlet-mapping>
</web-app>
I tried to access it as http://localhost:8080/first/hithere
But it was not working and I got a requested resource not available error.
Is there anyway to debug my application. Everything seems to be right. This is driving me crazy.
Any input will be highly appreciated.
Thanks.
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
I think root is something like a root application to Tomcat. If you put any page i.e. html/jsp in that directory or any other subdirectory of ROOT, it'll be accessible because no mapping is required. Please understand that you've not created a new web application by creating a directory under root. You have to have your directory under webapps and not under root i.e. at the same level as root.
You've also noticed that under root, there is a dir. called web-inf. So, root is a kind of web application and you need to create your own if you want to test anything. You can use root itself but then for deploying such servlets, you need to put the servlet classes under web-inf folder of ROOT and add the entries to the web.xml under that same.
I hope I've solved your problem!
I think root is something like a root application to Tomcat. If you put any page i.e. html/jsp in that directory or any other subdirectory of ROOT, it'll be accessible because no mapping is required. Please understand that you've not created a new web application by creating a directory under root. You have to have your directory under webapps and not under root i.e. at the same level as root.
You've also noticed that under root, there is a dir. called web-inf. So, root is a kind of web application and you need to create your own if you want to test anything. You can use root itself but then for deploying such servlets, you need to put the servlet classes under web-inf folder of ROOT and add the entries to the web.xml under that same.
I hope I've solved your problem!
Work Hard, Expect The Worst...<br /> <br />Bimal R. Patel<br />(SCJP 1.2, SCWCD 1.4)
stu ware
Greenhorn
Posts: 15
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
But when I created a directory at the same level as roots under webapps,
like rootdir/webapps/first/index.html
I am unable to access the index.html page as http://localhost:8080/first/index.html
I think http://localhost:8080/ is mapped to rootdir/webapps/root.
Nothing is working. It is so frustrating
. Is there any way to findout what is going wrong. I dont think the container is able to read the web.xml file.
Any help is highly appreciated.
like rootdir/webapps/first/index.html
I am unable to access the index.html page as http://localhost:8080/first/index.html
I think http://localhost:8080/ is mapped to rootdir/webapps/root.
Nothing is working. It is so frustrating
. Is there any way to findout what is going wrong. I dont think the container is able to read the web.xml file.Any help is highly appreciated.
stu ware
Greenhorn
Posts: 15
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi Bimal Patel,
Actually I was wrong. It worked when I placed my directory in webapps. I should have used webapps for my web application.
By the way, how to debug the servlets. Heard about log files. Where can I find them?
Any other techniques to debug......
Thanks for your help.
Actually I was wrong. It worked when I placed my directory in webapps. I should have used webapps for my web application.
By the way, how to debug the servlets. Heard about log files. Where can I find them?
Any other techniques to debug......
Thanks for your help.
Bimal Patel
Ranch Hand
Posts: 130
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
Your welcome! I know such kind of troubls while you're in the initial stages of learning servlets/jsp and web application fundamentals.
For debugging servlets, you can do that by remote debugging with any of the IDEs available. I would strongly suggest Eclipse. It is totally free and you can find the help with remote debugging from net. Let me know if I can help much.
You can download Eclipse from here.
[ February 07, 2006: Message edited by: Bimal Patel ]
[ February 07, 2006: Message edited by: Bimal Patel ]
Your welcome! I know such kind of troubls while you're in the initial stages of learning servlets/jsp and web application fundamentals.
For debugging servlets, you can do that by remote debugging with any of the IDEs available. I would strongly suggest Eclipse. It is totally free and you can find the help with remote debugging from net. Let me know if I can help much.
You can download Eclipse from here.
[ February 07, 2006: Message edited by: Bimal Patel ]
[ February 07, 2006: Message edited by: Bimal Patel ]
Work Hard, Expect The Worst...<br /> <br />Bimal R. Patel<br />(SCJP 1.2, SCWCD 1.4)
posted 19 years ago
Hi Vasu I saw your directory structure but i come to the conclussion that your directory structure is wrong.
Create the direcotory structure as i am writting. Please let me know if you have any issue.
Directory Structere:
<% Tomcat-Dir%>/webapps/first/WEB-INF/classes/Hello.java
Now in the web.xml make the entry as you specified in you post.:
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hithere</url-pattern>
</servlet-mapping>
</web-app>
Now deploy and run the tomcat and in the url please write:
http://localhost:8080/first/hithere
you would definatly get the expected output, sure.
cheers,
Chidanand Chauhan
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by vasu dupe:
Hi,
Later, I wrote the web.xml file and deployed it in
rootdir/webapps/root/first/WEB-INF.
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hithere</url-pattern>
</servlet-mapping>
</web-app>
I tried to access it as http://localhost:8080/first/hithere
Hi Vasu I saw your directory structure but i come to the conclussion that your directory structure is wrong.
Create the direcotory structure as i am writting. Please let me know if you have any issue.
Directory Structere:
<% Tomcat-Dir%>/webapps/first/WEB-INF/classes/Hello.java
Now in the web.xml make the entry as you specified in you post.:
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hithere</url-pattern>
</servlet-mapping>
</web-app>
Now deploy and run the tomcat and in the url please write:
http://localhost:8080/first/hithere
you would definatly get the expected output, sure.
cheers,
Chidanand Chauhan

posted 19 years ago
I know I sound like a broken record on this, but IMHO all classes used in servlets should be in a package. The directory structure under WEB-INF/classes must reflect the package structure.
Not using a package can result in strange and hard to debug problems.
Older servlet references may not emphasize this. See also the "invoker" servlet FAQ here at the ranch.
Bill
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I know I sound like a broken record on this, but IMHO all classes used in servlets should be in a package. The directory structure under WEB-INF/classes must reflect the package structure.
Not using a package can result in strange and hard to debug problems.
Older servlet references may not emphasize this. See also the "invoker" servlet FAQ here at the ranch.
Bill
| She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |









