Blog Archives

Spring MVC: Specify MIME headers

There’s seems to be 2 options. 1) Use ResponseEntity<String> as return type: String xml = … HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.APPLICATION_XML); return new ResponseEntity<String>(xml, responseHeaders, HttpStatus.OK) 2) Use ‘produces’ attribute of @RequestMapping @RequestMapping(value=”/some/page”, produces=”application/xml”) Test both methods, and they

Posted in Spring, Spring MVC

@InitBinder

Today we look at @InitBinder annotation. This can be used to set and invoke a custom Validator (Note: Don’t try and mix this with @Valid / JSR303 – the Bean Validation annotations). In essence it allows us to replace this

Posted in Spring, Spring MVC

Spring MVC – Pass through controller

Define controller which immediately forwards to a view when invoked: <mvc:view-controller path=”/” view-name=”home”/> Or, serve static resources: <mvc:resources mapping=”/resources/**” location=”/public-resources/”/> http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-view-controller

Posted in Spring, Spring MVC

Spring MVC

MVC defines the following special beans: DispatcherServlet – A servlet (web.xml) that takes an incoming request and hands it off to a Handler Mapping defined in its configuration (xxx-servlet, or other if using contextConfigLocation param). (link) Controllers – handles an

Posted in Spring, Spring MVC

Spring’s @ModelAttribute

What is it? @ModelAttribute annotated methods are executed before the chosen @RequestMapping annotated handler method. They effectively pre-populate the implicit model with specific attributes, often loaded from a database. Such an attribute can then already be accessed through @ModelAttribute annotated

Posted in Spring, Spring MVC

Spring tag libs

spring.tld http://static.springsource.org/spring/docs/3.0.2.RELEASE/reference/html/spring.tld.html <%@ taglib prefix=”spring” uri=”http://www.springframework.org/tags&#8221; %> spring-form.tld http://static.springsource.org/spring/docs/3.0.2.RELEASE/reference/html/spring-form.tld.html <%@ taglib prefix=”form” uri=”http://www.springframework.org/tags/form”%&gt; JSTL Javadoc: http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/ Tutorial: http://docs.oracle.com/javaee/5/tutorial/doc/bnakh.html <%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%&gt;

Posted in Spring, Spring MVC

Spring – multiple contexts

Spring MVC normally contains several xml files for configuration: web.xml – required for java web aplications (used to configure following two) applicatonContext.xml  – defines the root context (shared by all) location & name is specified by the contextConfigLocation property in

Tagged with: , , ,
Posted in Spring, Spring MVC