Re: Help with Java servlet : getServletContext().



On Fri, 2005-04-29 at 10:56 -0700, Vidya wrote:
> Hi Ross,
> I did include the javax.servlet.http.HttpServlet.
> Here is more code...if it helps.

Firstly those imports - You don't need to specifically name the classes
if you're using the javax.something.* syntax - that automatically
imports all public classes in the package. So for this app, all the
javax.servlet.whatever entries could removed, to leave only:

javax.servlet.*;
javax.servlet.http.*;

Most apps can get by with only javax.servlet.ServletContext, and the
servlet.http.* classes. Once your program is up and running, it's a good
idea to remove wildcard definitions but for now, it will make management
easier :)

Okay, so, importing it is part one of the process. The method you sent
looks like it's part of the servlet? Now. I bet your class definition
says:

[public] class YourClass implements Servlet

or maybe 'extends GenericServlet' in place of 'implements Servlet'.
Instead, it should be:

[public] class YourClass extends HttpServlet

You will then be able to override one/both of doGet(HttpServletRequest,
HttpServletResponse) and doPost(HttpServletRequest, HttpServletResponse)
to process get/post requests. Notice these both pass in a ready-to-use
request, with the parameters and what-not, and a response ready for you
to output to.

These methods then do whatever processing they need to, and use the
methods in [Http]ServletResponse to communicate with the client.

Hope this is helpful :)

Ross

--
[Ross A. Bamford] [ross AT the.website.domain]
Roscopeco Open Tech ++ Open Source + Java + Apache + CMF
http://www.roscopec0.f9.co.uk/ + info@xxxxxxxxxxxxxxxxxx


.