wood burning stoves 2.0*
The moose likes Servlets and the fly likes Unable to execute Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Unable to execute Servlet" Watch "Unable to execute Servlet" New topic
Author

Unable to execute Servlet

Jigeshs Shahs
Greenhorn

Joined: May 28, 2009
Posts: 26
Hi all,
I m unable to run servlet..
it gives the following error

The requested resource (Servlet Chapter1 Servlet is not available) is not available.

ch1servlet.class is the class file which is stored on F:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF\Classes\com\examples

web.xml is strored on F:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF

The ch1servlet source file is as follow as

package com.examples;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class ch1servlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException
{
PrintWriter out =response.getWriter();
java.util.Date today=new java.util.Date();
out.println("<html>"+ "<body>"+ "<h1>Chapter1 Servlet </h1>"+ "<br>"+today+"</body>"+"</html>");

}
}


web.xml file is as follow as

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

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.
-->

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>

<!-- JSPC servlet mappings start -->

<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>com.examples.ch1servlet</servlet-class>
</servlet>

<servlet-mapping>
<url-pattern>/Serv1</url-pattern>
<servlet-name>Chapter1 Servlet</servlet-name>
</servlet-mapping>

<!-- JSPC servlet mappings end -->

</web-app>


really cant figure out what is the problem
please help
Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
What is the URL that you used? (to access the servlet)


Blog
Nandhakumar Soundarrajan
Greenhorn

Joined: Apr 24, 2009
Posts: 23
Hi Jigeshs,

To execute the servlet, you need to use the URL as shown below.

http://<host_name>:<port_no>/<application_name>/<servlet's URL pattern defined in the web.xml file>

in your case i guess it would be (I am assuming you have installed tomcat on you local PC and using port 8080)

http://localhost:8080/ch1/Serv1

Hope this helps.


Thanking the green horns sincerely,
Nandha
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
The "not available" result could be due to errors when the server attempted to create an instance of your servlet. The log files should show an error trace.

Bill
Jigeshs Shahs
Greenhorn

Joined: May 28, 2009
Posts: 26
I have used URL as http://localhost:8080/ch1/Serv1 but still cant figure out whats is wrong in it.
gives the same error.

and regarding The "not available" result could be due to errors when the server attempted to create an instance of your servlet. The log files should show an error trace. didnt got what you are trying to say..

which log file will provide me the error i information i.e. any naming convention given to that log file and how to resolve it.

I have checked out 1 log file starts with local which gives the following information.

Jul 1, 2009 7:43:36 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Chapter1 Servlet
java.lang.ClassNotFoundException: com.examples.ch1servlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1095)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
Jul 1, 2009 7:43:43 PM org.apache.catalina.core.StandardWrapperValve invoke
INFO: Servlet Chapter1 Servlet is currently unavailable

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
So - its exactly what I said, the server could not create an instance of the servlet for the exact reason stated in the log:

java.lang.ClassNotFoundException: com.examples.ch1servlet


Something is wrong with the directory layout, the web.xml or the location of the servlet class.

What part dont you understand?

Bill
Jigeshs Shahs
Greenhorn

Joined: May 28, 2009
Posts: 26
ch1servlet.class is the class file which is stored on F:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF\Classes\com\examples

web.xml is strored on F:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF

I have used URL as http://localhost:8080/ch1/Serv1

so what else I can do other than this?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

F:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF\Classes\com\examples


It should be classes.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
sandip sangale
Greenhorn

Joined: Jun 22, 2009
Posts: 15
Hi....

You must store your class file in classes Folder and WEB.XML File in WEB-INF Folder
then try it
Janani Balaji
Greenhorn

Joined: Jul 10, 2009
Posts: 3
Hi,

Even i get the same error when trying to execute the servlet. I use Tomcat6.0 and Jre 6. My directory structure seems correct (similar to Jigeshs's ) and i have the .class file and the web.xml file in the proper place.

Also while trying to compile my java file, i had to manually override the classpath setting to include servlet-api.jar. The entry i had made in the environment variable seems to have no effect.

Not sure where the problem might be. Any help is appreciated.

Thanks,
Janani
Janani Balaji
Greenhorn

Joined: Jul 10, 2009
Posts: 3
Hi,

I got the problem solved. There was a problem with the xml version i was using in my web.xml. After changing that it worked fine.

But still not sure why the classpath i set in the environment variable doesnt get recognized.

Janani
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Janani Balaji wrote:But still not sure why the classpath i set in the environment variable doesnt get recognized.

Containers completely ignore the system classpath.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Janani Balaji
Greenhorn

Joined: Jul 10, 2009
Posts: 3
Thanks a lot!!
 
Don't get me started about those stupid light bulbs.
 
subject: Unable to execute Servlet