Jahangir Alam Jahangir Alam - 1 year ago 73
Java Question

config has a private access in GenericServlet

i am trying to upload an image (.jpg) file using common io in Servlet. While writing the following code ---

File savedFile = null;
savedFile = new File(config.getServletContext().getRealPath("/") + "/temp/" + fileName);

NetBeans is giving the error -- "config has a private access in GenericServlet".

Kindly help me out to resolve the issue.


I believe you are extending generic servlet or one of its sub classes. So In your class you can not directly access its config variable as it is declared privately.

so if you want to access config then use getServletConfig() method and if you want to access context then use `getServletContext() method