An Immediate problem: "getServletContext() "

Joined
Sep 17, 2009
Messages
1
Reaction score
0
Hi There;
I am new to JSP, I am currently using Eclipse Java EE IDE for Web Developers. Build id: 20090621-0832 .I am getting this error in every line that contains "getServletContext()": "The method getServletContext() is undefined for the type UserSSNServer"

Here is the source code:

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.
	[B][COLOR="Red"]	context = getServletContext();[/COLOR][/B]
//Above line is the error point.
		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));
				[B][COLOR="Red"]rd = getServletContext().getRequestDispatcher("/servlet/UserProfileServer");[/COLOR][/B]
//Above is another error point.
				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 .");
		}
		
	}
	
}
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top