Displaying keyword search results 1 - 10
Created by Dr. Xi on December 03, 2013 09:14:45 Last update: December 03, 2013 09:14:45
To test the effects of proxy settings http.proxyHost and http.proxyPort , I set these values to a non-existing proxy server:
java -Dhttp.proxyHost=example.com -Dhttp.proxyPort...To my surprise, the Google is retrieved successfully! Is Java ignoring these settings? It turns out that Java tries to fetch the URL directly after the proxy connection fails. If a working proxy is found at proxyHost:proxyPort , then the request is routed through the proxy, otherwise a direct connection is tried. The settings are documented here: http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html . For HTTPS use these properties: htttps.proxyHost htttps.proxyPort
Created by Dr. Xi on November 01, 2013 10:23:45 Last update: November 01, 2013 10:23:45
This example class generates and verifies RSA signature on a test file.
import java.io.*; import java.security.*; im...
Created by Dr. Xi on June 17, 2012 13:14:25 Last update: June 17, 2012 13:14:25
Link to official Java networking properties page: http://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html http.keepAlive (default: true) Indicates if keep alive (persistent) connections should be supported. Persistent connections improve performance by allowing the underlying socket connection be reused for multiple http requests. The default is true and thus persistent connections will be used with http 1.1 servers. Set to 'false' to disable the use of persistent connections. http.maxConnections (default: 5) If HTTP keep-alive is enabled, this value is the number of idle connections that will be simultaneously kept alive, per-destination.
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 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 March 30, 2012 15:04:04 Last update: March 30, 2012 15:04:04
Spring MVC 3.1 can send either JSON or HTML response on the same URL, depending on the type of response requested. With this mechanism, a page can be sent when directly requested from a link, but a JSON response can be sent in response to an AJAX request. This is the controller code:
package com.example; import java.util.Map; ...In the above example, JSON response will be sent when the HTTP request contains header "Accept: application/json". HTML response will be sent then the header is "Accept: */*", or "Accept: text/html", or anything else. You can add a limitation that the HTML response does not produce "application/json". But then the question is which response will be sent when the HTTP header is "Accept: */*"? Both methods will...
Created by Dr. Xi on March 13, 2012 08:46:57 Last update: March 13, 2012 08:46:57
This trick sets HTML base to the root context path of the current webapp: The short version:
<!DOCTYPE html> <%@ taglib uri="http://java.sun...The long version:
<!DOCTYPE html> <%@ taglib uri="http://java.sun...
Created by Fang on February 21, 2012 20:33:58 Last update: February 21, 2012 20:33:58
You can customize Tomcat error page with error code:
<error-page> <error-code>404</error-code> ...or Java exception type:
<error-page> <exception-type>java.lang.Throwab...Either error-code or exception-type is required, but not both. There's no way to aggregate error codes, such as:
<!-- This does not work! --> <error-page> ...Customizing error pages is about the only way to suppress the default stack trace in Tomcat in case of an unhandled exception.
Created by Fang on January 31, 2012 15:40:34 Last update: January 31, 2012 15:41:28
This is a simple Hello World application with Spring 3 MVC. Like the default Apache HTTPd welcome page, it displays " It works! " when successfully deployed. The sole purpose is to show the minimum elements needed to setup Spring 3 MVC. I use Maven since it's so much easier than downloading the dependencies manually. Directory layout:
./src ./src/main ./src/main/webapp ./src/...pom.xml :
<?xml version="1.0" encoding="UTF-8"?> <project...WEB-INF/web.xml :
<?xml version="1.0" encoding="UTF-8"?> <web-app...WEB-INF/applicationContext.xml (empty, but needed):
<?xml version="1.0" encoding="UTF-8"?> <beans x...WEB-INF/spring-servlet.xml :
<?xml version="1.0" encoding="UTF-8"?> <beans x...WEB-INF/jsp/home.jsp :
<!DOCTYPE html> <html> <head> <title>H...Build with:
mvn clean packageThe resulting webapp is target/springmvc.war .
Created by Fang on January 28, 2012 13:24:09 Last update: January 28, 2012 13:31:22
This is a simple JSP custom tags library with tag body. Just like the JSF counterpart , it splits a string and repeats the body for each word, i.e., with this markup:
<%@ taglib uri="http://custom.tag.com/demo" prefix...output:
<html> <body> <p>Hello Tigger!</p> <p>H...With Maven, this is the directory structure:
./src ./src/main ./src/main/resources ./s...There are three files to write: pom.xml :
<project xmlns="http://maven.apache.org/POM/4.0.0"...src/main/java/tagdemo/IterateTag.java :
package tagdemo; import java.io.IOException...src/main/resources/META-INF/demotag.tld :
<?xml version="1.0" encoding="UTF-8"?> <!DO...Build with:
mvn clean installTo use it as a dependency in other Maven projects:
<dependency> <groupId>tag-demo</groupId> ...