Recent Notes
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 voodoo on June 27, 2012 21:07:34
Last update: June 27, 2012 21:09:44
Because of the utilization of HTTP pipelining, Ubuntu APT had problems working with web proxies like Squid . The problem was fully documented in this bug report:
disable apt http pipelining in quantal
which also provided a way to turn off pipelining manually:
apt-get -o Acquire::http::Pipeline-Depth="0" -y up...
Pipelining is turned off by default as of apt (0.9.6ubuntu1) - Ubuntu Linux 12.10 'Quantal Quetzal' - see link above.
Created by Dr. Xi on May 24, 2012 20:16:12
Last update: May 24, 2012 20:16:12
IE categorizes web sites into different security zones . You can put specific sites into a certain zone with the "Security" tab in the "Internet Options" dialog. If a site is not specifically configured, IE has default algorithm to assign it to a zone. which can have unexpected results. For example: http://myserver is in the Intranet zone because the name does not contain a dot (.). But if you are using the IP address of myserver , then it goes to the Internet zone, even though myserver may have an internal IP address, or even on the same subnet: http://192.168.2.1 . IE8 and before displays the Zone of a web site in the status bar. IE9 removed the Zone info from the status bar. You...
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 Fang on March 30, 2012 12:15:49
Last update: March 30, 2012 12:15:49
1. mvc:default-servlet-handler Configures a handler for serving static resources by forwarding to the Servlet container's default Servlet. Use of this handler allows using a "/" mapping with the DispatcherServlet while still utilizing the Servlet container to serve static resources. HandlerMapping: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping Handler: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping Attribute Description default-servlet-name The name of the default Servlet to forward to for static resource requests. The handler will try to auto-detect the container's default Servlet at startup time using a list of known names. If the default Servlet cannot be detected because of using an unknown container or because it has been manually configured, the servlet name must be set explicitly. 2. mvc:view-controller Defines a simple Controller that selects a view to render the response. HandlerMapping: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping Handler: org.springframework.web.servlet.mvc.ParameterizableViewController Attribute Description...
Created by Fang on March 30, 2012 10:23:21
Last update: March 30, 2012 10:23:21
These bean types are essential for the Spring MVC framework. I copied them here from the Spring Documentation for quick reference. Bean type Explanation HandlerMapping Maps incoming requests to handlers and a list of pre- and post-processors (handler interceptors) based on some criteria the details of which vary by HandlerMapping implementation. The most popular implementation supports annotated controllers but other implementations exists as well. HandlerAdapter Helps the DispatcherServlet to invoke a handler mapped to a request regardless of the handler is actually invoked. For example, invoking an annotated controller requires resolving various annotations. Thus the main purpose of a HandlerAdapter is to shield the DispatcherServlet from such details. HandlerExceptionResolver Maps exceptions to views also allowing for more complex exception handling code. ViewResolver Resolves logical String-based...
Created by Dr. Xi on February 13, 2012 20:48:56
Last update: February 13, 2012 20:48:56
When you insert an attribute in JSP:
<%@ taglib uri="http://tiles.apache.org/tags-tiles...
you must define the attribute in tiles definitions:
<definition name="/home" template="/WEB-INF/templa...
Otherwise you'll get runtime exception.
The ignore attribute, which defaults to false , will suppress the runtime exception when the attribute is not defined in tiles definition:
<%@ taglib uri="http://tiles.apache.org/tags-tiles...
Created by Dr. Xi on February 01, 2012 12:55:28
Last update: February 01, 2012 12:55:28
You can define environment variables in the Tomcat context.xml file like this:
<?xml version="1.0" encoding="UTF-8"?>
<Context...
which is equivalent to the following in web.xml :
<env-entry>
<env-entry-name>varName</env-entr...
In Java code, the variable can be looked up like this:
// import javax.naming.Context;
// import javax...
Created by Fang on January 31, 2012 13:57:56
Last update: January 31, 2012 15:04:29
These are the minimum steps to configure Spring MVC in web.xml :
Bootstrap Spring MVC by registering ContextLoaderListener :
<listener>
<listener-class>
org.springfra...
Register the DispatcherServlet :
<servlet>
<servlet-name>spring</servlet-name>
...
Add servlet-mapping :
<servlet-mapping>
<servlet-name>spring</servle...
Configure DispatcherServlet with WEB-INF/spring-servlet.xml , which configures WebApplicationContext specific to this servlet.
<?xml version="1.0" encoding="UTF-8"?>
<beans x...
Optionally, use context-param in web.xml to configure the global WebApplicationContext :
<!-- XmlWebApplicationContext is the default, so t...
If you omit this section, you have to create file WEB-INF/applicationContext.xml , even if it's empty.
This is the full web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app...
Created by zhidao on January 25, 2012 16:07:29
Last update: January 25, 2012 16:07:29
A JSON response is auto-magically returned when you add the @ResponseBody annotation to the return value of a @RequestMapping annotated method:
import org.springframework.stereotype.Controller;
...
For magic to happen, you must:
Add annotation-driven to the org.springframework.web.servlet.DispatcherServlet config xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans x...
Put Jackson jar files on CLASSPATH (i.e., under WEB-INF/lib ), which includes jackson-core-asl-1.6.4.jar and jackson-mapper-asl-1.6.4.jar .