每个连接都会调用 Servlet init
我正在使用 Tomcat 7。我正在编写一个 servlet,但我注意到用户发出的每个请求都会调用 init。我正在创建带有注释的 servlet,如下所示。我希望 Servlet 在启动时自行初始化一次,然后不再初始化。但使用此代码,每个连接都会调用它。如果我遗漏了一些非常明显的东西,请告诉我。谢谢。
@WebServlet(urlPatterns={"/Tesing"}, loadOnStartup=1)
public class Testing extends HttpServlet {
// ...
}
I'm using Tomcat 7. I'm writing a servlet but I notice the init is being called for every request the user makes. I'm creating the servlet with annotations as seen below. I want the servlet to init itself once on startup and never again. But with this code its being called for every connection. If I'm missing something really obvious please let me know. Thanks.
@WebServlet(urlPatterns={"/Tesing"}, loadOnStartup=1)
public class Testing extends HttpServlet {
// ...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现问题...似乎我的 init 的最后一次调用抛出了异常,因此 servlet 没有得到初始化。在每次远程连接时,它都尝试重新连接,但由于相同的异常而失败。
Found the issue ... it seems the very last call of my init was throwing an exception and as such the servlet was not getting initialized. Upon every remote connection it was trying to reconnect but failing on the same exception.