Home Answers Viewqa JSP-Servlet problem running a servlet on tomcat.

 
 


Dhanush Dhanpal
problem running a servlet on tomcat.
3 Answer(s)      2 years and 3 months ago
Posted in : JSP-Servlet

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("<html>");
        out.println("<head>");
        out.println("<title>Servlet NewServlet</title>");  
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet NewServlet at " + request.getContextPath () + "</h1>");
        out.println("</body>");
        out.println("</html>");

}
}

my maping is like:

<servlet-mapping>
    <servlet-name>S1</servlet-name>
    <servlet-url>/hello</servlet-url>
</servlet-mapping>

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?


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("<html>");
        out.println("<head>");
        out.println("<title>Servlet NewServlet</title>");  
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet NewServlet at " + request.getContextPath () + "</h1>");
        out.println("</body>");
        out.println("</html>");

}
}

my maping is like:

<servlet-mapping>
    <servlet-name>S1</servlet-name>
    <servlet-url>/hello</servlet-url>
</servlet-mapping>

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 Pages:
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
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
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
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
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
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
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
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  
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
tomcat - Java Beginners
tomcat  can any body help me for installing apache tomcat and running the servlet program  Just go to the website www.sun.com in this website help mention regarding your problem
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
ecclipse_tomcat - JSP-Servlet
have java also installed.. How can I configure Tomcat for ecclipse...For running a small applcation..  Procedure to configure Tomcat in eclipse Go... runtime click on add button on the right side panel choose Apache Tomcat
tomcat cache - JSP-Servlet
tomcat cache  hai friends i have a query that is i want to remove the cache memory from Tomcat server Automatically using jsp without deleting... this is the major problem raising in my application please help me to sort out
Tomcat
Tomcat  I am using UBUNTU and I want to install tomcat to run servlet programs
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
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.
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.... - WebSevices
though if same problem occurs go to Action-Mappings & Servlet-Mapping RECODE...Tomcat....  Hi i am using tomcat5.0 & jdk1.5.The installation...;Suggession: Restart tomcat server and then try again. Before that check
Tomcat
Tomcat  why we get the error like HTTP Status 500 -.what is the solution for this problem
Tomcat
Tomcat  i have a problem in starting tomcat server.. May 12, 2011 12... resolving reference java.io.FileNotFoundException: D:\Workspace\conf\tomcat... Global JNDI Resources javax.naming.NamingException: D:\Workspace\conf\tomcat
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
TOMCAT
javax.servlet.ServletException: Error instantiating servlet class InsertServlet
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
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
connect jsp with tomcat - JSP-Servlet
connect jsp with tomcat  hello friends, i have severe problem in making connection between tomcat 6.0.18 and jsp pages.my system configuration... already set) ->tomcat 6.0.18 (c:/tomcat/tomcat6.0/) I have my site folder
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
Eclipse-Apache tomcat error
Eclipse-Apache tomcat error  Hi..I'v been trying to install apache tomcat 7 with eclipse helios to try web applications ..but unable to run...) required by Tomcat v7.0 Server at localhost are already in use. The server may
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
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
tomcat server start up error - Struts
tomcat server start up error   Hai friends..... while running tomcat server ,I got a problem..... Sep 5, 2009 4:49:08 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native
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
Tomcat Books
at the Apache Software Foundation. Tomcat implements the servlet... the configuration or servlet development with Tomcat, software architects.... Developers are also shown how to create Java web servers, how Tomcat runs a servlet
problem connect jsp and mysql - JSP-Servlet
problem connect jsp and mysql  hello, im getting an error while...-java-2.0.14.jar and placed it under both Tomcat 5.5\common\lib and Tomcat 5.5\webapps\ROOT... Software Foundation\Tomcat 5.5\common\lib\mysql-connector-java-2.0.14.jar
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
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
J2EE Tutorial - Running RMI Example
J2EE Tutorial - Running RMI Example    ...? 1) We require jndi package for running this program.  ... the classfiles in c:\jdk1.3\bin\rmicorba folder to    c:\tomcat
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
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
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
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
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
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 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
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
Tomcat installation problem - Hibernate Interview Questions
Tomcat installation problem   Hello
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
tomcat - JSP-Servlet
servlet using tomcat 5 from the start..   Hi friend, Set the classpath of the servlet-api.jar file in the variable CLASSPATH inside... the values as Variable Name: CLASSPATH Variable Value: C:\Program Files\Java\Tomcat

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.