Displaying keyword search results 1 - 10
Created by Fang on March 30, 2012 10:07:25 Last update: March 08, 2013 13:41:57
After a user resets a password, I want to force the user to change the password before she gets access to secured content. This is usually done with a servlet filter. But with Spring MVC, you can also use a HandlerInterceptor . According to Spring JavaDoc: HandlerInterceptor is basically similar to a Servlet 2.3 Filter, but in contrast to the latter it just allows custom pre-processing with the option of prohibiting the execution of the handler itself, and custom post-processing. Filters are more powerful, for example they allow for exchanging the request and response objects that are handed down the chain. Note that a filter gets configured in web.xml, a HandlerInterceptor in the application context. As a basic guideline, fine-grained handler-related preprocessing tasks are candidates...
Created by Fang on April 16, 2012 12:58:35 Last update: April 16, 2012 12:58:35
To implement a JSP custom tag with dynamic attributes (for example, to pass-thru arbitrary attributes not handled by the JSP tag): Set the dynamic-attributes element to true in the TLD:
<tag> <name>mark</name> <tag-class>c...The tag handler must implement javax.servlet.jsp.tagext.DynamicAttributes :
package com.example.jsp; import java.io.*; ...
Created by Fang on December 06, 2011 19:03:25 Last update: December 07, 2011 08:54:11
Our custom tag, as implemented in the previous note , is broken when a template is used. Create a template file ( home-template.xhtml ):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric...and a test page that uses it ( home.xhtml ):
<?xml version="1.0" encoding="UTF-8"?> <ui:comp...Then request the page with URL: http://localhost:8080/facelet-demo/home.jsf?name=Jack . You'll find that our hello tag works inside ui:repeat but fails to get the value defined by ui:param ! What's the problem? Our hello tag implementation evaluated the EL with the wrong EL context! This is the corrected implementation:
package com.example; import java.io.IOExcep...
Created by Fang on November 08, 2011 20:55:00 Last update: November 21, 2011 18:19:44
In the simple taglib example , I used a tag handler class to implement a taglib. This is an example to implement a taglib with a UI component. The purpose is to use a custom tag to split a string and print each part in a separate paragraph, i.e., print
<p>john</p> <p>steve</p> <p>mike</p>with custom tag <my:foreach> :
<my:foreach var="who" value="john steve mike"> ...These are the files: pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"...src/main/java/com/example/UIForeash.java :
package com.example; import java.io.IOExcep...src/main/resources/META-INF/faces-config.xml :
<?xml version="1.0" encoding="UTF-8"?> <faces-c...src/main/resources/META-INF/foreach.taglib.xml :
<?xml version="1.0" encoding="UTF-8"?> <facelet...How to use: Put the JAR file generated by the above project in the WEB-INF/lib folder of the web app. If the web app is a Maven project, just add the taglib project as a dependency:...
Created by Fang on November 10, 2011 09:26:12 Last update: November 10, 2011 09:26:12
Syntax highlighted XML schema for JSF 2.0 Application Configuration Resource File ( faces-config.xml ). Almost 3000 lines!
<?xml version="1.0" encoding="UTF-8"?> <xsd:sch...
Created by Fang on November 02, 2011 16:40:10 Last update: November 02, 2011 16:40:10
Facelet taglib schema from JavaServer Faces Spec 2.0:
Created by alfa on June 03, 2011 09:41:03 Last update: June 03, 2011 09:41:03
Dynamic proxy can be used to eliminate the need to stub out unused interface methods. This is an example for a simple SAX content handler for XML parsing. The org.xml.sax.ContentHandler interface requires 11 methods be implemented but we only need three:
import java.io.IOException; import java.util.Ar...With a dynamic proxy, we don't need the empty blocks for the unused methods:
import java.io.IOException; import java.util.Ar...Equivalently (with anonymous inner class):
import java.io.IOException; import java.util.Ar...demo.xml :
<breakfast-menu> <food> <name>Belgian W...
Created by mak on March 04, 2011 14:17:32 Last update: March 04, 2011 14:18:35
To create a zipfile in python: Code:
#!/usr/local/bin/python import zipfile #...Test
unzip -l test.zip Archive: test.zip Lengt...To read a zipfile in python: Code:
#!/usr/local/bin/python import zipfile #...
Created by voodoo on November 01, 2010 22:26:00 Last update: November 01, 2010 22:26:00
Some weirdness observed while updating BLOB with PostgreSQL JDBC driver: LOB position offset starts at 1 (not 0 as in IO input stream). When you call setBinaryStream(long pos) , pos must be greater than 0. I think this is JDBC standard behavior. When you write to a BLOB output stream, new contents overwrite existing contents. Old contents are not automatically truncated. If new content length is shorter than old contents, the old contents will remain after the position where new content ended. You can call Blob.truncate(long len) to truncate existing contents. However , there seems to be an discrepancy between the JDBC doc and PostgreSQL JDBC driver. The JDBC JavaDoc states that: Truncates the BLOB value that this Blob object represents to be len bytes...
Created by Dr. Xi on September 17, 2010 21:29:47 Last update: September 17, 2010 21:31:43
With JBoss (Tomcat?), the servlet container always appends the default charset ISO-8859-1 to the Content-Type header of a JSP response. For example, if you are using JSP to render PDF and put the following declaration at the top of the JSP:
<%@ page contentType="application/pdf"%>These would be the headers in the HTTP response (notice that charset=ISO-8859-1 was appended to Content-Type ):
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 X-...And the output would be truncated a few bytes before non-ASCII characters were encountered, without any error messages ! Maybe you don't intend to output binary files with JSP, but still your response would be truncated without warning if the page happens to contain any non-ASCII characters (when the charset is the default charset=ISO-8859-1 ). However, if you...