• 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 run servlet in tomcat

 
Ranch Hand
Posts: 115
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,
I am new to using tomcat so kindly bear with me.I have just started preparing for scwcd and i am using head first as my guide.
I have followed the instructions exactly as they directed on page 30-31 of the book,but i am unable to view the output in the browser.

All i can see is the error Http status-404 on the browser.
Please help me,i am fed up of checking the code and trying different methods again and again.Please help
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the directory structure of your web application? Have you configured url mappings in web.xml properly?
 
sumedha rao
Ranch Hand
Posts: 115
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes the directory structure is correct.i have followed the same directory structure as given in the book-tomcat->webapps->ch1->WEB-INF(inside this is web.xml)->classes(inside this is Ch1Servlet.class).The compilation was successful but maybe there is some problem at runtime...please help i have been trying since a few hrs but no success
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally I haven't gone through the book, so tough to say what is there on page 30-31. Could you please show your web.xml and how you are trying to invoke the servlet i.e the url to invoke the servlet?
 
sumedha rao
Ranch Hand
Posts: 115
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
web.xml:-


Ch1Servlet.java:-


steps after compiling:
Start->all programs->Tomcat->Configure Tomcat

Launch the browser
http://localhost:8080/ch1/Serv1
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something looks wrong with your web.xml, when I used it tomcat says some unsupported encoding exception. The following worked for me, could you please try with the following once

 
sumedha rao
Ranch Hand
Posts: 115
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am still getting the same error..i really cant understand whats the problem..is the web.xml code different for different versions of tomcat? i am using version 6.0.29
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that tomcat console or log displaying any error when you start tomcat?
 
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



This mistake happens frequently - if fact if you browse this forum often you will see numerous examples.

ALL classes used in servlet should be explicitly placed in a package because when the JVM sees a class without a package it looks in the "current" directory. You have no control over the current directory in the servlet environment.

Bill
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For me it has worked without package as well. I may be wrong, but as far as I know not the current directory rather it looks into WEB-INF\classes.
 
sumedha rao
Ranch Hand
Posts: 115
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey the output is displayed now!!! I stopped the tomcat service and restarted it from the control panel and i can see the output now!!
Thanks a lot for spending your precious time in solving my problem!!!Thankyou so much
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Similar Problem i have::

My servlet_lifecycle.java file is:

//servlet programs demonstrating its life cycle

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

public class servlet_lifecycle extends HttpServlet{
int i;

public void init() throws ServletException
{
i=0; //initializing i value-- parameters
}

//incrementing i value in doGet

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

if(i==0)
{
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet's Life Cycle</title>");
out.println("</head>");
out.println("</body>");
out.println("</h1>i value initialized in init method</h1>" + "<h1>"+ i + "</h1>");
out.println("</body>");
out.println("</html>");
}
i=i+1;
if(i==10)
{
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet's Life Cycle</title>");
out.println("</head>");
out.println("</body>");
out.println("</h1>i value reaches 10, hence calling destroy method to reset it</h1>" + "<h1>"+ i + "</h1>");
out.println("</body>");
out.println("</html>");
destroy();
}


if(i<10)
{
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet's Life Cycle</title>");
out.println("</head>");
out.println("</body>");
out.println("</h1>i value incremented in doGet method</h1>" + "<h1>"+ i + "</h1>");
out.println("</body>");
out.println("</html>");
}
}

public void destroy()
{
i=0;
}


}


web.xml file is:
<?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_4.xsd"
version="2.4">

<description>
Servlet and JSP Examples.
</description>
<display-name>Servlet and JSP Examples</display-name>



<servlet>
<servlet-name>servlet_lifecycle</servlet-name>
<servlet-class>servlet_lifecycle</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servlet_lifecycle</servlet-name>
<url-pattern>/servlet_lifecycle</url-pattern>
</servlet-mapping>

</web-app>


Please help me.. i am new to servlets... i am geting error HTTP 503

HTTP Status 503 - This application is not currently available

type Status report

message This application is not currently available

description The requested service (This application is not currently available) is not currently available.

Apache Tomcat/6.0.32


 
All of the following truths are shameless lies. But what about 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