菜鸟java编程 Servletproxy

来源:互联网 发布:php cookie 保存数组 编辑:程序博客网 时间:2024/06/16 13:05
package com.lyl.servlet;


import java.io.IOException;


import javax.servlet.GenericServlet;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;


import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;


public class ServletProxy extends GenericServlet {


private String targetBean;
private Servlet proxy;

@Override
public void service(ServletRequest req, ServletResponse resp)
throws ServletException, IOException {
proxy.service(req, resp);
}
@Override
public void destroy() {
super.destroy();
}
@Override
public void init() throws ServletException {
this.targetBean = getServletName();
getServletBean();
proxy.init(getServletConfig());
}


private void getServletBean(){

WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
this.proxy = (Servlet) webApplicationContext.getBean(targetBean);

}



}
0 0
原创粉丝点击