problem running a servlet on tomcat.

problem running a servlet on tomcat.

i have followed the steps given here. on typing "http://localhost:8080" i do get the apache tomcat page. i suppose that should mean that my tomcat server is up and running. but whn i try to run my servlet that is placed in the directories as it has been mentioned here, the browser responds "HTTP Status 404 - /java_mail/hello" wht could be the problem?

please help me out of this...

View Answers

February 25, 2011 at 12:36 PM

Put servlet-api.jar inside the lib folder of apache tomcat.

1)create a servlet.

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

public class HelloWorld extends HttpServlet{ 
  public void doGet(HttpServletRequest request, HttpServletResponse response)
                                   throws ServletException,IOException{
    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    pw.println("<html>");
    pw.println("<head><title>Hello World</title></title>");
    pw.println("<body>");
    pw.println("<h1>Hello World</h1>");
    pw.println("</body></html>");
  }
}

2)Go to the webapps folder of your apache tomcat and create a web application folder but it should having an appropriate name like examples.

3)Create web.xml and classes folder inside the WEB_INF folder of web application folder.

4)Copy the servlet to the classes folder.

5)Edit the web.xml to include servlet?s name and url pattern.

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

6)Compile your servlet.

7)Run Tomcat server by clicking the startup.bat file. This is located inside the bin folder of apache tomcat.

8)Open the browser and type the following url:

http://localhost:8080/webapplicationfolder_name/HelloWorld

For more information, visit the following link:

Servlet Tutorials


February 26, 2011 at 10:20 PM

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class servlet1 extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

        out.println("&lt;html&gt;");
        out.println("&lt;head&gt;");
        out.println("&lt;title&gt;Servlet NewServlet&lt;/title&gt;");  
        out.println("&lt;/head&gt;");
        out.println("&lt;body&gt;");
        out.println("&lt;h1&gt;Servlet NewServlet at " + request.getContextPath () + "&lt;/h1&gt;");
        out.println("&lt;/body&gt;");
        out.println("&lt;/html&gt;");


} 
}

my maping is like:

&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;S1&lt;/servlet-name&gt;
    &lt;servlet-url&gt;/hello&lt;/servlet-url&gt;
&lt;/servlet-mapping&gt;

The folder locations are as below:

webapps>jmail>WEB-INF(contains web.xml)>classes>(contains servlet1.java)

I have started the server using the startup.bat file. and have checked if the server is running by typing "localhost:8080" in my browser and it seems to be working fine. but when i type "localhost:8080/jmail/hello" It shows: Apache Tomcat/6.0.20

Apache Tomcat/6.0.20> HTTP Status 404 - /jmail/hello
 type Status report 
 message /jmail/hello
description The requested resource
  (/jmail/hello) is not available.
Apache Tomcat/6.0.20Apache Tomcat/6.0.20
Apache Tomcat/6.0.20

i cant understand whats wrong. is it the server that might be creating issues?

Ads









Related Tutorials/Questions & Answers:
problem running a servlet on tomcat.
problem running a servlet on tomcat.  i have followed the steps given here. on typing "http://localhost:8080" i do get the apache tomcat page. i suppose that should mean that my tomcat server is up and running. but whn i try
error of HTTP Status 404 while running servlet on apache tomcat server
error of HTTP Status 404 while running servlet on apache tomcat server  i have followed the steps given here.Also hava put servlet-api in lib folder... the apache tomcat page. It mean that my tomcat server is up and running. but whn i
Advertisements
apache tomcat problem - JSP-Servlet
apache tomcat problem  hi, i am trying to run apache tomcat. but it is showing "The CATALINA_HOME environment variable is not defined correctly...\;"; i installed my apache tomcat in c: whats wrong with this  
tomcat problem
tomcat problem  error like requested(rootdirectory/urlpattern) resources are not available getting while running servlet on tomcatserver
Running and deploying Tomcat Server
Running and deploying Tomcat Server  HI Somebody has given the solution but it doesn't work out. kindly tell the solution for my problem which i... for servlet is like this Apache Software Foundation/Tomcat 5.0/webapps/ i created
About running the Tomcat Server
About running the Tomcat Server   HI I want to run a simple program on servlet and the application is a simple program Hello world to print on Internet browser. And the directory for servlet is like
servlet problem
servlet problem  wheni m deploying an servlet application im getting trouble context [/filename] startup failed due to previous error in tomcat 6.0.
Running problem with NoughtsAndCrossesGame in blank
Running problem with NoughtsAndCrossesGame in blank  Hi i was having problem created NoughtsAndCrossesGame in end the it works but i runs the gui in blank. Its another way to solve it /* * To change this template, choose
Servlet problem
connectivity code it works but problem is with servlet page. My servlet code...Servlet problem  Hello, I am very shocked about this mysterious problem from last three month and now i hope rose india developers
problem in servlet program
problem in servlet program  Dear Sir, I have a problem to insert the Blob type data like as video file, audio file in the database using Servlet and html code
exception in thread main while running servlet
exception in thread main while running servlet  I got exception in thread main no such method error while running servlet. I have added...\Tomcat 6.0\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation
Java Servlet Problem - JSP-Servlet
Java Servlet Problem  I have a servlet class that implemets..., but in the attributeReplaced() method, i want to perform a redirect to another servlet... method. Please help!!  Hi friend, Please explain problem
tomcat server problem
tomcat server problem  hello rose india, my name is raju. I am placing a problem with tomcat5.5 server. when i am trying to execute my project I have deployed my project in tomcat and then i tried to execute first it showed me
java web application without running tomcat
java web application without running tomcat  I did a project by using jsp,html,javascript,css,tomcat,editplus and MSAccess as backend..i created set up file by using NSIS tool..but the problem when i will the project to some
Version of tomcat>servlet dependency
List of Version of tomcat>servlet dependency
Version of tomcat>servlet-api dependency
List of Version of tomcat>servlet-api dependency
problem at the time of execution - JSP-Servlet
problem at the time of execution  when i was running web applications the exception i.e 404 resource is not available what it means and where it occures what is the solution   Hi Friend, This error occurs when
problem regarding tomcat server 6.0
problem regarding tomcat server 6.0  Jul 27, 2012 10:39:19 PM... Tomcat Native library which allows optimal performanc e in production environments... Foundation\Tomcat 6.0\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDO WS\system32;C:\WINDOWS;C
The Currently Running Servlet is showing some Previously run Servlet's Output
The Currently Running Servlet is showing some Previously run Servlet's... for example, I have executed the ParameterServlet servlet where the output... am executing another different servlet, It is showing the same output
java servlet connectivity problem with access
java servlet connectivity problem with access  Import java.sql javax.servlet //all packages entered try { Class.forName...=con.createStatement(); ^ i am confused what is the problem
Trouble in running Dos Command from Java Servlet
Trouble in running Dos Command from Java Servlet  Hello All, I have... find the specified file. The above line of codes are in one servlet and from servlet I wants to run specified DOS Command. Can anyone help me out here ? I
servlet redirect problem help needed
servlet redirect problem help needed  package p; import...=getServletContext().getRequestDispatc‚?¶ re.forward(req, resp); } } this servlet is calling by a jsp..there is no problem,in this servlet the if condition always
servlet redirect problem help needed
servlet redirect problem help needed  package p; import...=getServletContext().getRequestDispatc‚?¶ re.forward(req, resp); } } this servlet is calling by a jsp..there is no problem,in this servlet the if condition always
tomcat - Servlet Interview Questions
tomcat  Hi Deepakji, I am swamy,when tomcat memory is fulled with web applications how we can increase memory of tomcat.is it possible. Thank You, Thanks&Regards, Swamy
Version of geronimo>geronimo-servlet-examples-tomcat dependency
List of Version of geronimo>geronimo-servlet-examples-tomcat dependency
problem in record viewing in jsp - JSP-Servlet
and servlet and back end mysql actually what is my problem is i have to everytime...problem in record viewing in jsp  hai i send the code can you please find where is the problem it is not showing any error but i cannot able to view
Problem in record viewing in jsp - JSP-Servlet
Problem in record viewing in jsp  hai i have developed... . no problem all are working but in view part alone some problem i dont know what... please help me how to solve this problem i am not getting any error
Problem while using tomcat 6.0 in eclipse with struts application
Problem while using tomcat 6.0 in eclipse with struts application  Hi please provide solution for the following problem org.apache.jasper.JasperException: java.lang.ClassCastException
Maven Dependency geronimo-servlet-examples-tomcat >> 5.5.12
You should include the dependency code given in this page to add Maven Dependency of geronimo >> geronimo-servlet-examples-tomcat version5.5.12 in your project
tomcat
tomcat   i downloaded and installed taomcat server but my servlet hasnotbeen running on it and im getting the message like "requested resources... the following links: http://www.roseindia.net/quickguide/tomcat
servlet
servlet  hi sir,this is ashok.i installed tomcat 6.0 and jdk-150.i checked the server it's working but when execute servlet program for the .class... sir hoew to resolve this problem
Tomcat
Tomcat  I am using UBUNTU and I want to install tomcat to run servlet programs
Working with Tomcat Server
Apache Tomcat is a famous Servlet container developed at  Apache... a web application folder (servlet-examples) under tomcat webapps directory. ...-pattern> </servlet-mapping> 5.  Run Tomcat Server
problem in creating web application using servelet, jsp, jdbc and xml - JSP-Servlet
problem in creating web application using servelet, jsp, jdbc and xml  Using Servlet, JSP, JDBC and XML create a web application for a courrier...; Hi friend, For solving the problem visit to : http://www.roseindia.net
Tomcat
Tomcat  When i want to run the servlet program in tomcat i got the following errors type Status report message Servlet InsertServlet is not available description The requested resource (Servlet InsertServlet is not available
Null pointer exceptation-Java Servlet web application,Problem connecting with MYSQL database
Null pointer exceptation-Java Servlet web application,Problem connecting...,since i try to configure this out for 1 week,i dont find any solution for my problem... the project in WAR file and then i upload to my hosting. The problem come when my
How Run JSP in Apache TomCat Server? - JSP-Servlet
How Run JSP in Apache TomCat Server?  How to Run JSP in Apache Tomcat... program there. You can also check compete tomcat tutorial at http://www.roseindia.net/quickguide/tomcat/index.shtml Thanks
Problem
(); echoSocket.close(); } } this is my code, compiled with no errors, but when running giving... that the server (something like EchoServer) is up and running.   Thanx i got the answer, i just turned off the firewall & its running fine
Problem
with no errors, but when running giving "java.net.connectexception connection...) is up and running
JSP code problem - JSP-Servlet
TOMCAT
TOMCAT  When i am deploy the servlet class file in tomcat server i.... exception javax.servlet.ServletException: Error instantiating servlet class... in the Apache Tomcat/6.0.32 logs. Apache Tomcat/6.0.32 my servlet code
Maven Dependency servlet >> 4.0.6
You should include the dependency code given in this page to add Maven Dependency of tomcat >> servlet version4.0.6 in your project
Servlet
.   Hello Friend, Follow these steps: Put servlet-api.jar inside the lib folder of apache tomcat. 1)create a servlet. import java.io.*; import...Servlet  I want to know the steps to write a simple servlet program
Maven Dependency servlet-api >> 5.0.16
You should include the dependency code given in this page to add Maven Dependency of tomcat >> servlet-api version5.0.16 in your project
Maven Dependency servlet-api >> 5.0.18
You should include the dependency code given in this page to add Maven Dependency of tomcat >> servlet-api version5.0.18 in your project
Maven Dependency servlet-api >> 5.5.12
You should include the dependency code given in this page to add Maven Dependency of tomcat >> servlet-api version5.5.12 in your project
Servlet
these steps after compiling the servlet 1)Run Tomcat server by clicking the startup.bat... the same error <web-app> <servlet> <servlet-name>InsertServlet</servlet-name> <servlet-class>InsertServlet</servlet
JAVA CLASSPATH PROBLEM
servlets and problem raise for classpath. I had a problem with servlet to call... of apache tomcat. 1)create a servlet. import java.io.*; import javax.servlet....-mapping> 6)Compile your servlet. 7)Run Tomcat server by clicking the startup.bat
Download Tomcat
engine. Catlina is a Servlet container of Tomcat. Coyote : Coyote... is compiled as Servlet. Components that are released with Tomcat 7 version...Download Tomcat In this section we will discuss about downloading tomcat
stop the running hidden server
stop the running hidden server  Port 8080 required by Tomcat v6.0 Server at localhost is already in use. The server may already be running in another process, or a system process may be using the port. To start this server you

Ads