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.
If you do not specify a base object or class for a method call, the method call is expected to be a member of the class that the method call logic is located in - or at least a superclass of that class.
Java is not like C/C++ where you have stand-alone functions. Java is fully object-oriented and every method must belong to a class.
That's where your error comes from. I can deduce that your sample code is in a class you created named "MySQLConnection" because the compiler cannot find a getServletContext method defined in your class definition.
The getServletContext() JEE method is a member method of class javax.servlet.http.GenericServlet and its descendents and one or two other servlet-related classes such as javax.servlet.http.HttpSession. So if you want the ServletContext, you either need to obtain it from the Servlet that is (presumably) calling MySQLConnection methods or from the HttpSession object for your webapp.
An IDE is no substitute for an Intelligent Developer.
posted 1 month ago
Hi Tim Moores,
Yes, thank you. By removing getServletContext() from the ScoutMain.generateE1 and all reference to it in the called program it now works. If I can ever catch the person who produced the GWT version I will ask them why it was in there.
Hi Tim Holloway,
I understand the first three paragraphs of your reply; however, struggling with the last. I obviously need some education in this area; which I will see to.
crispy bacon. crispy tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java