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?









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
tomcat problem - JSP-Servlet
found your problem.. http://www.roseindia.net/web-application-server/tomcat...tomcat problem  Hi! Rose India Team, I am unable to install the tomcat server. It stops at this stage during installation .......c:\program files
Advertisements
Tomcat installation problem - JSP-Servlet
Tomcat installation problem   Hello I have installed Tomcat and my startup and shutdown programs are working but the problem is i couldnt open...:\apache-tomcat-6.0.16; 2) Put the servlet-api.jar into lib folder of apache tomcat
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
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
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
servlet problem  wheni m deploying an servlet application im getting trouble context [/filename] startup failed due to previous error in tomcat 6.0.
Running threads in servlet only once - JSP-Servlet
Running threads in servlet only once  Hi All, I am developing... process while mail thread is running. these two separate threads has to run... them self immediately. how can resolve this problem. Thanks
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
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 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
problem with starting tomcat - IDE Questions
problem with starting tomcat  I'm running Eclipse 3.1with Tomcat 5.5 When I start Tomcat inside of Eclipse using the "Servers" tab, the "Console" window shows that Tomcat is running but the "Servers" window shows "starting
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
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
Servlet Problem - JSP-Servlet
Servlet Problem  Hii I am Ajay . I am makin g a project in java using servlets. I have a database in which I have stored images along with some other info(Name, address type). I want to display that info in text form along
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
Servlet compilation problem - Java Beginners
Servlet compilation problem  hi, m a beginner to servlet world... i m facing problem in servlet compilation problem.. i have set the classpath of servlet-api.jar . m using tomcat 6.0 i m unable to compile my servlet program
Servlet os running commands issues - Development process
Servlet os running commands issues  hello, i want the help regarding the running os commands through servlet. so please send it either on my personal email address or send it on the rose india servlet tutorial. thanx n
Jsp ,Servlet Problem - JSP-Servlet
to execute a servlet code on tomcat server... Thanking u... Santosh  ...Jsp ,Servlet Problem  hi, m new to jsp n Servlet. i really find ur... with oracle. it worked wonders. now i m starting jsp n servlet learning.. pls
Problem in running first hibernate program.... - Hibernate
Problem in running first hibernate program....  Hi...I am using eclipse ganymede and mysql.I have already configured mysql and did few sample..., It seems that your class has not been found.There may be problem in your
Servlet Problem proceed - JSP-Servlet
Servlet Problem proceed  Thank you fro your reply. But I couldnt find any serious error.Please see this. User is the package classes/User... problem then read more details. http://www.roseindia.net/servlets
servlet program problem - Java Beginners
servlet program problem   i used ur servlet example prg with xml file of helloworld program and i run dat program in tomcat, it shows only... file to run it  Hi Friend, Please clarify your problem. Thanks
servlet problem - Servlet Interview Questions
application folder and servlet in classes folder of apache tomcat. The web application...servlet problem   when i have perform action on submit button then there is no call servlet in my action i have done every effort in this programe
Version of tomcat>servlet dependency
List of Version of tomcat>servlet dependency
Servlet problem - JDBC
Servlet problem  Hii Everyone, I m Ajay. I m making a project using... SQL 2000 database and I have developed a servlet that accepts input from user but however. It gives problem sometimes while at others it works perfectly. I m
Tomcat server - Servlet Interview Questions
Tomcat server  Hello, I am Executing the Servlet application at the time am getting the message like HTTP STSTUS 404 plz tell me wht's this problem and show me the solution to me
Tomcat installation problem - Hibernate Interview Questions
Tomcat installation problem   Hello
Problem in Servlet - Servlet Interview Questions
Problem in Servlet  Sir, I have pointed everything in web.xml, path class path etc.. empController is my main servlet program and I called in form.... then some exception ..Servlet Exception: empContrller is not a servlet pgm
problem with starting tomcat - IDE Questions
problem with starting tomcat  Hi friends, Iam using eclipse 3.1 and tomcat 5.5 in my project. when iam going to start server it is giving like this: Timeout waiting for tomcat v5.5 server @localhost to start.Server did
problem with starting tomcat - IDE Questions
problem with starting tomcat  Hi friends, Iam using eclipse 3.1 and tomcat 5.5 in my project. when iam going to start server it is giving like this: Timeout waiting for tomcat v5.5 server @localhost to start.Server did
tomcat startup problem - IDE Questions
tomcat startup problem  hiiiiii My computer os is windows vista.i installed myecllipse ide with ecllipse 3.1 and tomcat 5.5.After configuring the tomcat server and deploying the project in server from myecllipse ide,when i try
logout problem.. - JSP-Servlet
logout problem..  hi... first of all thanks for ur... but their is some problem with the the logout,i m not able to logout when... done in the code i have used session object in project's servlet and jsp
servlet (tomcat server) and jar
servlet (tomcat server) and jar  how to create a jar file and where to place the jar file in tomecat server
logout problem?? - JSP-Servlet
logout problem??  sir, the logout code which u have send is not the proper solution coz,by using this code the browser get closed which shuold..., Please visit the following links: http://www.roseindia.net/quickguide/tomcat
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
problem in programming - JSP-Servlet
problem in programming  Hi! I am new with jsp. I am facing a problem in programming to calculate the time interval between login time and logout time of user
pagination problem - JSP-Servlet
using servlets in that i called a these methods,to call this servlet i created a html file i wrote one form to call this servlet. In this servlet i used doget...(),my problem is that where i have to put & how to do pagination? my code
pagination problem - JSP-Servlet
using servlets in that i called a these methods,to call this servlet i created a html file i wrote one form to call this servlet. In this servlet i used doget...(),my problem is that where i have to put & how to do pagination? my code
problem with starting tomcat - IDE Questions
problem with starting tomcat  Hi friends, Iam using eclipse 3.1 and tomcat 5.5 in my project. when iam going to start server it is giving like this: Timeout waiting for tomcat v5.5 server @localhost to start.Server did
servlet code problem - JSP-Servlet
servlet code problem  This is my JSP code index.jsp Sync... here!!!..., i want to pass the texbox value and file to servlet im stuck with this error plzz help me..., in servlet if i use request.getParameter() its
Schedular starting problem - Servlet Interview Questions
threading and using quartz.jar API). This was running fine. But since last 7 days it is not running.. The application is running on tomcat 5.0. Can any one please suggest me / guide me what will be the problem
servlet code problem - JSP-Servlet
servlet code problem  This is my JSP code index.jsp Sync Data Sync Data Please use the following input box to upload file or enter... to servlet im stuck with this error plzz help me..., thanks in advance....  
Java Problem - JSP-Servlet
Java Problem  What are the steps to run a java Servlet program.with examples  Hi Friend, Please visit the following link: http://www.roseindia.net/servlets/index.shtml Thanks
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
arraylist problem - JSP-Servlet
my code once again only in which i m facing the problem. /* * To change... servlet request * @param response servlet response...); } } this is giving an output in servlet page like: DST_Name: Code TeamLeader
Java Problem - JSP-Servlet
are necessary  Hi Friend, Steps: 1)First of all you need to install Tomcat on your system. 2)Then put your tomcat folder inside the C drive. 3)Set... the webapps folder of apache tomcat. 5)Create a jsp file 'hello.jsp'.You can put
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

Ads