spring与servlet环境配置 (一)

2014-11-24 10:16:44 · 作者: · 浏览: 0
1、HttpServletProxy.java
[java]
package com.zfy.commons.util;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class HttpServletProxy extends HttpServlet {
private static final long serialVersionUID = 4382945551447764730L;
private String targetServlet;
private HttpServlet proxy;
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void init() throws ServletException {
this.targetServlet = getInitParameter("targetServlet");
getServletBean();
proxy.init(getServletConfig());
}
private void getServletBean() {
WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
this.proxy = (HttpServlet) wac.getBean(targetServlet);
}
@Override
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, RuntimeException {
proxy.service(request, response);
}
}
package com.zfy.commons.util;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class HttpServletProxy extends HttpServlet {
private static final long serialVersionUID = 4382945551447764730L;
private String targetServlet;
private HttpServlet proxy;
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void init() throws ServletException {
this.targetServlet = getInitParameter("targetServlet");
getServletBean();
proxy.init(getServletConfig());
}
private void getServletBean() {
WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
this.proxy = (HttpServlet) wac.getBean(targetServlet);
}
@Override
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, RuntimeException {
proxy.service(request, response);
}
}2、web.xml
[java]
< xml version="1.0" encoding="UTF-8" >
contextConfigLocation
classpath:spring.xml,classpath:spring-hibernate.xml
字符集过滤器
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
字符集编码
encoding
UTF-8
spring监听器
org.springframework.web.context.C