Recent Notes

Displaying keyword search results 51 - 60
Created by alfa on April 08, 2011 14:14:46    Last update: April 08, 2011 14:26:13
It's a lot easier to use swing JOptionPane to present a dialog. But if plain awt is what you want, this is the code. A Dialog is a Window object, so you paint it just like you would for a window. import java.awt.*; import java.awt.event.*; ...
Created by nogeek on April 07, 2011 20:54:17    Last update: April 07, 2011 20:54:17
Use javax.xml.parsers.DocumentBuilder to parse xml. DocumentBuilder.parse() takes: java.io.File org.xml.sax.InputSource java.io.InputStream java.lang.String as a URI to an XML document Example code: import java.io.*; import javax.xml.parsers.Docu...
Created by Dr. Xi on March 24, 2011 12:11:14    Last update: March 24, 2011 12:22:03
This is the task: your client wants to know how the web application is used. That is pretty easy. A plethora of commercial tools or any of the free log analysis tools such as analog and AWStats would fit the bill. But here's the catch: they want to know not only what pages are visited by how many people and when, but also who logged in and did what. Your application is using form based authentication and therefore, everyone is anonymous in the web access log. What to do? This is a servlet filter that generates a web access log with authenticated user info that can be fed to log analysis tools such as analog and AWStats . Filter code (the output format is Apache...
Created by Dr. Xi on November 29, 2010 13:08:05    Last update: November 30, 2010 08:51:34
This sample code sets up a server socket on a specified address and port. I use it to test port binding conflicts. import java.net.*; public class SocketBind ... Note: " netstat -ano " also gives you information on active TCP connections, including listening ports. But there are cases where netstat reports nothing and bind still fails.
Created by Fang on August 10, 2010 21:37:36    Last update: October 25, 2010 20:18:47
The tags <fmt:formatNumber> Format a numeric value as number , currency or percentage - controlled by the type attribute (defaults to number if type is missing). Syntax: <fmt:formatNumber value="numericValue" [type="... Attributes: Name Dynamic? Type Description value true String or Number Numeric value to be formatted. type true String Specifies whether the value is to be formatted as number, currency, or percentage. pattern true String Custom formatting pattern, must follow the pattern syntax specified by the class java.text.DecimalFormat . currencyCode true String ISO 4217 currency code. Applied only when formatting currencies (i.e. if type is equal to "currency"); ignored otherwise. currencySymbol true String Currency symbol. Applied only when formatting currencies (i.e. if type is equal to "currency"); ignored otherwise. It is used only when currencyCode is...
Created by James on June 30, 2010 20:14:28    Last update: July 03, 2010 18:41:12
The HTML page <!DOCTYPE html> <html> <head> <title>jQu... Client Side Code // called before upload submit function sta... Server Side Code Using Apache Commons FileUpload as example. Upload code (responds to fileUpload.do ): final HttpSession session = httpServletRequest... Progress code (responds to uploadProgress.do ): HttpSession session = httpServletRequest.getSe...
Created by Dr. Xi on June 03, 2010 22:43:43    Last update: June 20, 2010 14:13:05
Using the Sun BASE64Encoder : import java.io.*; import sun.misc.BASE64Encoder... However, the Sun encoder is awfully slow. The Apache encoder is a lot faster. Here's the code with Apache encoder: import java.io.*; import org.apache.commons.cod... Performance comparisons between Apache and Sun: C:\>bash bash-3.2$ time java EncodeFileWithBase...
Created by Fang on April 03, 2010 20:21:15    Last update: April 04, 2010 03:30:22
The tags <c:out> The <c:out> tag evaluates an expression and outputs the result on the page. The syntax is: <c:out value="value" [escapeXml="{true|false}"] ... where escapeXml defaults to true and default defaults to empty string "". <c:out value="${expr}" escapeXml="false"/> is equivalent to ${expr} . If a variable is set in multiple scopes, the lower scope wins. In the following example code, attribute1 is set in request, session, and application scopes; attribute2 is set in session and application scopes; attribute3 is set in the application scope. The results are: <c:out value="${attribute1}"/> : Attribute1 request scope <c:out value="${attribute2}"/> : Attribute2 session scope <c:out value="${attribute3}"/> : Attribute3 application scope To access values in higher scopes, you have to specify the scope explicitly, like this: <c:out value="${sessionScope.attribute1}"/> : Attribute1 session...
Created by Fang on April 01, 2010 22:24:58    Last update: April 02, 2010 02:49:38
In this note I'll show you how to create and package a JSP custom tag. The purpose of this tag is to display a random splash image for a home page, among a set of images. We should be able to add or delete candidate splash images from the WAR archive without the need to change the JSP. This is the intended use of the tag: <%@ taglib uri="http://custom.tag.com/demo" prefix... In the above example you provide a set of images named splash*.png (e.g., splash1.png, spalsh2.png, ...), and the tag will pick a random one to display when the JSP is rendered. Let's get started. I'll use Maven for this purpose. Create the standard Maven directory structure ./pom.xml ./src ./src/main ./src/main/jav... pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0"... SplashTag.java package tagdemo; import java.util.ArrayList......
Created by Dr. Xi on September 17, 2008 04:18:49    Last update: August 07, 2009 03:19:42
Simple enum: enum Suite { SPADE, HEART, DI... Enum with code and description: import java.util.*; enum Suite { SP...
Previous  1 2 3 4 5 6 7 Next