Blarg #21: DevelopMentor JWT links that need to be on-line
For those of you at DevelopMentor's Java Web Tier course, here are the links we used in class. If you weren't at this class and you want to learn about making websites with Java.... Ha, I bet DM loves me now!
Here are those links.
- Specifications: These are the documents you should use as references.
- HTTP Specification
- Servlet Specification
- Servlet API JavaDocs
- Servlet Specification
- JSP Specification
- JSP API JavaDocs
- JSTL References
- Jakarta Ant: The build tool
- To install: unzip the Ant code and set two system property values. One for "ANT_HOME" and one for "PATH". "ANT_HOME" should be the directory that has all the Ant files. The "PATH" variable should be the same as it was before but with a semi-colon ";" and "%ANT_HOME%/bin" appended.
- Jakarta Tomcat: The reference Servlet/JSP. Not a bad choice at all for production use.
- Jakarta Struts: one of the first MVC frameworks for Servlets/JSP.
- Jakarta Commons HTTP Client: the slick web browser API that we used to develop HTTP tests and to spoof web requests.
- Jakarta Commons File Upload: An API that makes it trivial to do file uploads from HTML forms.
- Netbeans: The tool I like to use when editing code. You can also download and use that awesome profiler.
- MySQL: The database we used in class. It is very easy to install and connect to your web application. Don't forget to get the JDBC driver.
- Some code snippets from class
- The HttpSessionListener for counting the number of current users.
- A servlet filter that doesn't let users click the back button of their web browser.
- A servlet filter that auto-encodes jsessionid information in relative links on the the page.
- The example .tag file for making an image rollover effect.
SessionCountListener.java
This class counts the number of current sessions. When one is created, the count goes up. When one is destroyed, the count goes down. This is not a hit tracker. It is a count of "live" users.
package example;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
/**
*A listener class that counts the number of concurent sessions.
* @author Jayson Falkner - jfalkner@umich.edu
*/
public class SessionCountListener implements HttpSessionListener {
int count = 0;
/**
*When a session is destroyed, decrement the counter.
*/
public void sessionDestroyed(HttpSessionEvent se) {
// increment the count
count--;
// set the attribute
setAttribute(se);
}
/**
*When a session is created, increment the counter.
*/
public void sessionCreated(HttpSessionEvent se) {
// decrement the count
count++;
// set the attribute
setAttribute(se);
}
// helper method to set the attribte in 'application' scope
private void setAttribute(HttpSessionEvent se) {
// get the session
HttpSession hs = se.getSession();
// get the servlet context
ServletContext sc = hs.getServletContext();
// set the attribute on the servlet context
sc.setAttribute("userCount", Integer.toString(count));
}
}
And don't forget that you must register this class via web.xml
<web-app>
<listener>
<listener-class>example.SessionCountListener</listener-class>
</listener>
<!-- rest of your web.xml stuff... -->
</web-app>
Finally, you can show the count from any JSP or serlvet that has access to the ServletContext object. Here is an example JSP.
<html>
<h1>JSP Page ${userCount}</h1>
</html>
- Login or register to post comments
- Printer-friendly version
- jfalkner's blog
- 442 reads





