[英]How to hit a servlet class with ServletContextListener from Jsp page button click
I have a servlet implementing ServletContextListener.Now as per my need i have to send some parameters from jsp page submit button click to this servlet but it is not hitting the servlet file on submit button click.. 我有一个实现ServletContextListener的servlet。现在,根据我的需要,我必须从jsp页面的提交按钮单击中发送一些参数到此servlet,但是在单击提交按钮时不会击中servlet文件。
Here is my Servlet code.. 这是我的Servlet代码。
@WebListener()
public class MyContext implements ServletContextListener {
Timer timer = new Timer();
@Override
public void contextInitialized(ServletContextEvent event) {
Calendar date = Calendar.getInstance();
date.set(
Calendar.DAY_OF_MONTH, 12);
date.set(Calendar.HOUR, 00);
date.set(Calendar.MINUTE, 11);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
timer.schedule(
new MyTask(),
date.getTime(),
1000 * 60 * 60 * 24 * 7);
}
@Override
public void contextDestroyed(ServletContextEvent event) {
timer.cancel();
}
} }
And here is my JSP page.. 这是我的JSP页面。
<form action="/MyContext/" method="GET">
<label>Set Date: </label>
<input type="text" name="date" id="date">
<label>Set Time: </label>
<input type="text" name="time" id="time">
<input type="Submit" name="Submit" value="Submit" id="Submit">
</form>
This is my web.xml file .. 这是我的web.xml文件。
<servlet>
<servlet-name>MyContext</servlet-name>
<servlet-class>MyContext</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyContext</servlet-name>
<url-pattern>/MyContext</url-pattern>
</servlet-mapping>
<listner>
<listner-class>
MyContext
</listner-class>>
</listner>>
Please guys help me .. Thanks in advance... 请大家帮我..在此先感谢...
The class MyContext implementing ServletContextListener is not a Servlet that process your requests. 实现ServletContextListener的MyContext类不是处理您的请求的Servlet。 Listeners wait for some events to happen and gives us a handlers method to handle the event. 侦听器等待某些事件发生,并为我们提供处理程序的方法来处理该事件。 In the case of ServletContextListener we can handle the initialization and destruction of the ServletContext. 对于ServletContextListener,我们可以处理ServletContext的初始化和销毁。 Refer this post to get a better understanding. 请参阅这篇文章以获得更好的理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.