-1

I have an issue trying to use getServletContext() on the server-side. This is marked as an error (underlined in red) and the hover over error is "The method getServletContext() is undefined for the type MySQLConnection" and the quick fix is to create the mothod.

I am using some code that was generated by someone else for gwtJava. I am now trying to use this in a JEE project. Unfortunately I have not been able to get help from the person who originally created this code and I am not a programmer and am learning as I go.

public static void printE1(String activity, String activityNo,
        String groupFormation, String location, String startTime,
        String startDateString, String startFrom, String finishTime,
        ...

try {
    ScoutMain.generateE1(getServletContext(), activity, activityNo,
    groupFormation, location, startTime,
    startDateString, startFrom, finishTime,
    ...

The ScoutMain.generateE1 has:

public static void generateE1(ServletContext ctx,
    String activity, String activityNo,
    String groupFormation, String location, String startTime,
    ...

I have looked at:

Different ways to get Servlet Context

Why getservletcontext isn't found?

And the getServletContext() documentation, which I found very confusing.

I think I may be missing an import; however, cannot find which one.

Glyn
  • 1,933
  • 5
  • 37
  • 60
  • 1
    You can call getServletContext() usually only in methods of descendant classes of HttpServlet class. Please check what class method called this method. – Ansar Ozden Jan 14 '19 at 17:28

1 Answers1

0

I received help from some and the answer was that this was not needed anyway. I have removed it from the calling the program and all references to it in the called program and all works.

I sort of understand what Ansar Ozen is saying; however, not fully. I obviously need to do a lot of training in this area.

Glyn
  • 1,933
  • 5
  • 37
  • 60