Create Thread In Java Web Application explains about implementing a background thread in a java web application so that you can do some logic behind these background thread.
You can achieve thread implementation in j2ee web application several ways. For example if you are using application servers like Jboss,Weblogic & Websphere, you have more possible ways to do this. But here we are targeting for both servlet containers like Tomcat, jetty etc and application servers like JBOSS, Weblogic etc.
Remove Whitespace From HTML / JSP / JSF explains about implementing a servlet filter for removing whitespace & blank lines from your html/jsp/jsf output, which will reduce the payload and improve the overall web application performance
If you need a solution for below questions
How To Remove Whitespace From Response In Your Java Web Application?
How To Remove Whitespace From JSP/JSF And HTML?
then servlet filter will be the right choice, because by using servlet filter, we can implement this in a single place rather than on implementing every page
if you dont know about Servlet Filter, you can follow servlet filter Tutorial Here I am using, whitespace removing filter available from http://balusc.blogspot.in/2007/12/whitespacefilter.html
By using this filter you can strip/trim whitespace & newline characters from your html/jsp/jsf pages without losing actual contents
Java GZIP Compression Filter Example explains about implementing a GZIP compression filter for optimizing web application performance
How To Compress HTML Content Using Gzip Servlet Filter?
Here we are discussing about implementing Gzip Compression Filter using Java Servlet Filter, if you don't know about Servlet Filter, you can follow servlet filter Tutorial
By implementing GZIP compression, will dramatically improve web application performance and reduce download time.
For availing GZIP compression, your browser must support GZIP compression, you need to set Accept-Encoding request header
HttpSessionListener Example explains about How to use HttpSessionListener in a web application
What is HttpSessionListener?
For knowing about HttpSessionListener, First we must understand session. Http protocol is a "stateless" protocol. The word stateless means Http protocol can't persist the information in between client and server. When a client sends a request for any resource, server receive the request and process the request and returns response. After returning the response the server terminates the connection. When a client forwards a request for a particular resource, server consider each and every request as a separate request. In order to avoid this burden we use session. With the help of session tracking when a client request for any pages or resources container creates a session id for that particular request and return back the session id to the client along with the response object.
When I Use HttpSessionListener
Whenever a session created or destroyed, servlet container will invoke HttpSessionListener
javax.servlet.http.HttpSessionListener interface has following methods:
sessionCreated(HttpSessionEvent event) It will notify when the session is created. sessionDestroyed(HttpSessionEvent event) It will notify when the session gets invalidated.
ServletContextListener Example explains about How to use ServletContextListener in a web application.
The listener ServletContextListener interface for receiving notification events about ServletContext lifecycle changes.
For the entire web application, there will be only one ServletContext.
ServletContext is created when a new deployment is made after that this ServletContext will be used by all the jsp's and servlet's in the web application.
ServletContextListener has the following two methods:
public void contextInitialized(ServletContextEvent event) public void contextDestroyed(ServletContextEvent event)
Java Servlet Filter Tutorial explains step by step details of creating a Servlet Filter using Eclipse
Servlet filter filter dynamically manipulate both requests as well as responses and to modify the object contained in the requests or responses
Typically Servlet Filters do not create responses, but they provide universal operations which can be a part of any type of JSP or servlet
Here we are showing an example of hitCounter, so that we can count the exact number of visitors for a site. Here hitcount variable is increased on each request.
You can see the below example, which is demonstrating Servlet Filter Tutorial
HttpSessionBindingListener Example explains about how to use HttpSessionBindingListener in a web application.
The listener HttpSessionBindingListener is an interface extending from base interface java.util.EventListener interface. This interface will notify an object when it is bound to or unbound from a session.
javax.servlet.http.HttpSessionBindingListener interface has following two methods:
valueBound(HttpSessionBindingEvent event). valueUnBound(HttpSessionBindingEvent event).
You can see the below example, which is demonstrating HttpSessionBindingListener Example
Servlet Listener Example explains step by step details of implementing a Servlet Listener
Servlet Listener is helpful for listening various events inside a servlet container, such as add an attribute in a session, create a session, to manipulate these events you need to configure listener class in web.xml
Please see the following Java Servlet Listener Example