Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Dhanush Dhanpal
problem running a servlet on tomcat.
2 Answer(s)      3 years and 7 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...


Advertisement
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
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 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  
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
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
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
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
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
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
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 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
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 - 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
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
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
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
tomcat - JSP-Servlet
tomcat  i want to run my war file in server in tomcat... to how to assign static IP in tomcat.... i want to run my project in local-network... my project is in jsp
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 error - JSP-Servlet
Tomcat error  Sir I have Installed Tomcat 6.0 om my personel computer havind Operating system windows xp. But when I start the tomcat it gives the error :-this is non microsoft product please see event log . what might
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
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 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
Advertisements
 

 

 

DMCA.com