• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Unable to execute Servlet

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the URL that you used? (to access the servlet)
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



It should be classes.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi....

You must store your class file in classes Folder and WEB.XML File in WEB-INF Folder
then try it
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Janani Balaji
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot!!
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic