Jahangir Alam Jahangir Alam - 2 years ago 116
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download