java - init method is calling again and again in servlet -
the init
method gets called again , again on every request in servlet. here code:
public class personinfocontroller extends httpservlet { private static final long serialversionuid = 1l; public personinfocontroller() { super(); } public void init() throws servletexception { connection connection = database.getconnection(); system.out.println("init method"); } protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { list<personinfoservicei> mylist = new arraylist(); personinfoservicei instance = new personinfoserviceimpl(); mylist = instance.getdata(); string jsonstring = new gson().tojson(mylist); request.setattribute("list", jsonstring); requestdispatcher rd = request.getrequestdispatcher("showdata.jsp"); rd.forward(request, response); } public void destroy() { system.out.println("the destory"); } }
according code init() should call once when servlet load on first request. after destruction init() called again on new request. in between service method called. code having no logical mistakes. calling init method outside servlet? can attach deployment descriptor?
Comments
Post a Comment