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:
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: