
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...

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:

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?

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?
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.