Hi,

Your class is not (yet) a servlet! In order to be one (and to inherit 
"getServletContext()" method) it must extend 
"javax.servelt.http.HttpServlet"
-- 
Hope it helps
mihai

gozlemci a écrit :
> Hi there;
> I am writing the code in book :"Professional JSP" by Wrox Press Ltd.
> and I got the following error. Could you please help me?
> Error description : "The method getServletContext() is undefined for
> the type UserSSNServer" In every line that contains
> "getServletContext"
>
> I am using Eclipse Java EE IDE for Web Developers. Build id:
> 20090621-0832
>
> Here are the class:
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import javax.servlet.GenericServlet;
> import sun.reflect.generics.tree.BaseType;
> import mfc.SSNList;
> import mfc.CustomerInfoBean;
> import mfc.Constants;
> import javax.servlet.http.HttpServlet;
>
> public class UserSSNServer {
>
>       private static String cName = "UserSSNServer";
>       private boolean debugFlag = true;
>
>       public void init() throws ServletException
>       {
>               String mName = new String(cName + ".init()");
>               System.out.println(mName + "start.");
>               System.out.println(mName + "end.");
>
>       }
>
>       public void processRequestType(HttpServletRequest request
>                       ,HttpServletResponse response) throws ServletException ,
> IOException
>       {
>               String mName = new String(cName + ".processRequestType(): ");
>               System.out.println(mName + "start.");
>               String reqTypeStr = (String) request.getParameter("reqType");
>               System.out.println(mName + "reqTypeStr = " + reqTypeStr);
>
>               int requestType = Constants.ERROR;
>
>               if(reqTypeStr == null)
>               {
>                       throw new ServletException (mName + "reqType was 
> null.");
>
>               }
>               requestType = Integer.parseInt(reqTypeStr);
>               switch(requestType)
>               {
>
>               case Constants.CREATE_VALID_SNN_LIST:
>                       createSSNList(request,response);
>                       break;
>
>               default:
>                       System.out.println(mName + "default case.");
>                       throw new ServletException(mName + "default case 
> reached.");
>
>               }
>               System.out.println(mName + "end.");
>
>       }
>
>       @SuppressWarnings("unchecked")
>       public void createSSNList(HttpServletRequest request,
> HttpServletResponse response) throws ServletException, IOException
>       {
>
>               String mName = new String(cName + ".createSSNList(); ");
>               System.out.println(mName + "start. ");
>               ServletContext context = null;
>
>               //construct the object that creates the SSN list.
>               SSNList ssnList = new SSNList();
>               ArrayList ssnArrayList = ssnList.getSSNList();
>
>               // up the Arraylist into the servlet context so others may 
> retrieve.
>               context = getServletContext();
>               context.setAttribute("ValidSSNList", ssnList.getSSNList() );
>               HttpSession session = request.getSession();
>
>               CustomerInfoBean customerInfo = (CustomerInfoBean)
> session.getAttribute("customerInfo");
>
>               StringBuffer errorMsgBuff = new StringBuffer("error message 
> was: ");
>
>               if(customerInfo == null)
>               {
>                       errorMsgBuff.append("could not get UserINfo bean from 
> the
> session.");
>                       session.setAttribute("errorMsg", 
> errorMsgBuff.toString());
>               //      redirectToResource(request,response,"/mutualFundCo/jsp/
> sorry.jsp");
>
>               }
>
>               String ssn = customerInfo.getSsn();
>
>               if (ssn == null) {
>
>                       System.out.println("SSN was not in the 
> customerInfoBean.");
>
>               }
>               else {
>
>                       System.out.println(mName + "validate SSN");
>                       RequestDispatcher rd = null;
>
>                       if(ssnArrayList.contains(ssn) == true)
>                       {
>
>                               request.setAttribute("reqType", Integer.toString
> (MAKE_PROFILE_REQUEST));
>                               rd = 
> getServletContext().getRequestDispatcher("/servlet/
> UserProfileServer");
>                               rd.forward(request, response);
>
>
>                       }else
>                       {
>
>                               errorMsgBuff.append("The social security number 
> you have entered :
> '" + ssn +
>                                               "' was not found.Please call 
> 1-800-MFC-HELP");
>
>                               redirectToResource(request, response, 
> "/mutualFundCo/jsp/
> sorry.jsp");
>                       }
>                       System.out.print(mName + "end .");
>               }
>
>       }
>
> }
>
> >
>
>
>   

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to