Please read the last line as servletcontext.setAttribute("Country","USA");
On Tuesday, June 7, 2016 at 7:42:17 AM UTC-4, Ravi B wrote:
>
> Hello,
> I am doing the homework for servlet_basics2 chapter from the
> WebProgramming Basics course. I'm trying to declare a variable of
> ServletContext class type as follows:
>
> ServletContext servletcontext = request.getServletContext();
> servcontext.setAttribute("Country", "USA");
>
>
> I am getting an error as follows: The method getServletContext() is
> undefined for the type HttpServletRequest.
>
> The example program "hello_scope_context" has the exact same declaration
> and it works fine, but when I declare it, it's giving me this error. Can
> you help? Thanks. Here is my code:
>
> ------------------
> package hwservlets;
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
>
> public class GreetingServlet extends HttpServlet {
> @Override
> public void doGet(HttpServletRequest request, HttpServletResponse response)
> throws ServletException, IOException {
> response.setContentType("text/html");
> response.setBufferSize(8192);
>
> PrintWriter out = response.getWriter();
>
> // Set Servlet wide scope attribute to be accessible by any servlet
> ServletContext servletcontext = request.getServletContext();
> servcontext.setAttribute("Country", "USA");
> -----------------------------
>
--
You received this message because you are subscribed to the Google Groups
"JPassion.com: Java Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/jpassion_java.
For more options, visit https://groups.google.com/d/optout.