Notes by Fang

Displaying notes 11 - 20
Created by Fang on July 25, 2012 12:59:47    Last update: July 25, 2012 12:59:47
Example code: import javax.xml.ws.BindingProvider; import jav... Wierdly, even though the response context ( ctx ) itself is a Map, you cannot iterate through the keys. This: for (String key: ctx.keySet()) { logger.inf... fails: WARN : InternalError - Handler execution resulted ...
Created by Fang on June 29, 2012 14:56:21    Last update: June 29, 2012 14:56:21
To delete a cookie in Java servlet API, call Cookie.setMaxAge(0) . According to Servlet API JavaDoc : A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age. A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted.
Created by Fang on June 05, 2012 09:12:36    Last update: June 05, 2012 09:13:03
The apache.commons.lang package has a nice utility to escape strings for various language environments. Simply include the dependency in pom.xml : <dependency> <groupId>org.apache.commons</... and use it: // import org.apache.commons.lang3.StringEscapeUti...
Created by Fang on May 17, 2012 19:31:39    Last update: May 17, 2012 19:31:39
To inject ServletContext into a Spring bean: implement ServletContextAware : import javax.servlet.ServletContext; import... Define bean in Spring application context: <beans:bean id="myBean" class="com.example.M...
Created by Fang on May 15, 2012 13:04:24    Last update: May 15, 2012 13:04:44
Set the warnLogCategory attribute to log uncaught exception stacktrace: <bean class="org.springframework.web.servl...
Created by Fang on May 03, 2012 15:07:17    Last update: May 03, 2012 15:07:52
Scaling an image with default Java API loses quality (horribly!): public static BufferedImage resizeImage(Buffer... The imgscalr library does the job beautifully. And its' very easy to do: // import org.imgscalr.Scalr; public static... To import the library in Maven: <dependency> <groupId>org.imgscalr</groupId> ...
Created by Fang on April 16, 2012 13:32:10    Last update: April 16, 2012 13:32:10
There are two steps to create a custom function for JSP: Declare the function in the TLD: <?xml version="1.0" encoding="UTF-8" ?> <taglib... Implement the function (must be static): package com.example; public class UrlTransl... To use the function: <%@ taglib uri="http://www.example.com/jsp/tags" p...
Created by Fang on April 16, 2012 13:18:40    Last update: April 16, 2012 13:18:40
Simply call pageContext.setAttribute() to export a variable from within a JSP custom tag: public class MyCustomVarTag extends TagSupport { ... The availability of the exported variable can be limited in the TLD: <tag> <name>setVar</name> <tag-class... The availability scopes are: Value Availability NESTED Between the start tag and the end tag. AT_BEGIN From the start tag until the scope of any enclosing tag. If there’s no enclosing tag, then to the end of the page. AT_END After the end tag until the scope of any enclosing tag. If there’s no enclosing tag, then to the end of the page.
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 February 24, 2012 14:38:06    Last update: April 06, 2012 13:19:29
Step 1: create a Json factory: package com.my.service.dev; import java.io.... Step 2: use it: ObjectMapper mapper = new ObjectMapper(new AllowCo...
Previous  1 2 3 4 5 6 7 8 9 10 Next