[java]
1.Spring配置的XML
[html]
< xml version="1.0" encoding="UTF-8" >
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd ">
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
2 解析多视图请求的类
[java]
package com.spring.action;
import java.util.Locale;
import java.util.Map;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
/**
* @author Jeson
* @blog:http://www.gbsou.com
* @date:Oct 20, 2009 8:39:27 AM
* @version :1.0
*
*/
public class MultiViewResover implements ViewResolver {
private Map
@Override
public View resolveViewName(String viewName, Locale locale)
throws Exception {
int n = viewName.lastIndexOf("_"); // 获取
// viewName(modelAndView中的名字)看其有没有下划线
if (n == (-1))
return null; // 没有则直接返回空
// 有的话截取下划线后面的字符串 这里一般是jsp,ftl,vm与配置文件中的
String suffix = viewName.substring(n + 1);
// 根据下划线后面的字符串去获取托管的视图解析类对象
ViewResolver resolver = resolvers.get(suffix);
// 取下划线前面的部分 那时真正的资源名.比如我们要使用hello.jsp 那viewName就应该是hello_jsp