aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem in excuting Basicservlet" Watch "problem in excuting Basicservlet" New topic
Author

problem in excuting Basicservlet

chinna kumar
Greenhorn

Joined: Sep 29, 2004
Posts: 18
Hi,
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.*;
import java.io.*;
public class BasicServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
ServletContext context=getServletContext();
String username=(String)context.getAttribute("username");
if(username==null)
{
// username=new String("kumar");
context.setAttribute("username",new String("kumar"));
}
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<head><title>BasicServlet</title></head>");
out.println("<body>");
out.println("The Current UserName Is:::::"+username);
}
public static void main(String[] args)
{
System.out.println("???/");
}
}



please help me out...


Regards
Chinna
Praful Thakare
Ranch Hand

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

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


<!-- The mapping for the invoker servlet -->
<!--
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
-->


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

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

Thanx A Lot

Chinna
David O'Meara
Rancher

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!

Dave
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

To put it mildly, un-commenting the invoker servlet is starting off on the wrong foot:
http://faq.javaranch.com/view?InvokerServlet


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in excuting Basicservlet