File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes problem in excuting Basicservlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem in excuting Basicservlet" Watch "problem in excuting Basicservlet" New topic

problem in excuting Basicservlet

chinna kumar

Joined: Sep 29, 2004
Posts: 18
am trying to access servlet thru browser using using url: http://localhost:8080/venu/servlet/BasicServlet , it says not servlet not available.

this is my code

directory struture is....webapps/venu/WEB-INF/classess, under classes i have placed this servlet.

import javax.servlet.*;
import javax.servlet.http.*;
public class BasicServlet extends HttpServlet
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
ServletContext context=getServletContext();
String username=(String)context.getAttribute("username");
// username=new String("kumar");
context.setAttribute("username",new String("kumar"));
PrintWriter out=res.getWriter();
out.println("The Current UserName Is:::::"+username);
public static void main(String[] args)

please help me out...

Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 642
try doing the following

open tomcat\conf\web.xml
uncomment following entry
restart tomcat
invoke the servlet again

<!-- The mapping for the invoker servlet -->

All desirable things in life are either illegal, banned, expensive or married to someone else !!!
chinna kumar

Joined: Sep 29, 2004
Posts: 18
hi Praful Thakare,
it works!!!

Thanx A Lot

David O'Meara

Joined: Mar 06, 2001
Posts: 13459

He's quite right, but just to clarify:

The correct way to execute a Servlet is to map it to a URL and then access it through that URL eg /venu/MyServlet
Accessing servlets as /venu/servlet/ClassName is a horrible old thing that they are trying to get people away from. By default it is disabled, but following the instructions above you can enable the invoker Servlet in Tomcat which allows you to access Servlets in this way.

The invoker Servlet is a special Servlet mapped to /venu/servlet/*, looks at what you asked to invoke and calls it. The big problem is that if you forget to turn it off it allows direct access to all servlets as long as the client knows the servlet class name. This can be a security risk or cause instable applications when used in production, but is OK when learning, as long as you learn how to map Servlets soon!

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

To put it mildly, un-commenting the invoker servlet is starting off on the wrong foot:

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: problem in excuting Basicservlet
jQuery in Action, 3rd edition