Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 17th, 2009, 04:21 PM
gozlemci gozlemci is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 1 gozlemci User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 40 sec
Reputation Power: 0
A problem: "getServletContext() "

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 red line.

I am using Eclipse Java EE IDE for Web Developers. Build id:
20090621-0832
Here are the class:

Code:

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 ."); 
                } 
        } 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > A problem: "getServletContext() "


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap