<wbr></wbr>配置如ssh
不用在web.xml中加入struts的监听了
在 随意的一个jsp或servlet中
String realPath=this.getServletPath().getRealPath("WEB-INF/applicationContext.xml");
ApplicationContext ac=new fileSystemXmlApplication<wbr></wbr>Context(realPath);
session.setAttribute("applicationContext",ac);
(注意,必须初始化此jsp或servlet才可用正常工作)
或者是在struts的action中
String realPath=request.getRealPath("WEB-INF/applicationContext.xml");
ApplicationContext ac=new fileSystemXmlApplication<wbr></wbr>Context(realPath);
session.setAttribute("applicationContext",ac);
在任何的action中都可以直接调用了
(注意,必须初始化此action,才可以正常工作)
注:这不是正常的ssh粘合,只是为了开阔一下程序设计的视野!
不用在web.xml中加入struts的监听了
在 随意的一个jsp或servlet中
String realPath=this.getServletPath().getRealPath("WEB-INF/applicationContext.xml");
ApplicationContext ac=new fileSystemXmlApplication<wbr></wbr>Context(realPath);
session.setAttribute("applicationContext",ac);
(注意,必须初始化此jsp或servlet才可用正常工作)
或者是在struts的action中
String realPath=request.getRealPath("WEB-INF/applicationContext.xml");
ApplicationContext ac=new fileSystemXmlApplication<wbr></wbr>Context(realPath);
session.setAttribute("applicationContext",ac);
在任何的action中都可以直接调用了
(注意,必须初始化此action,才可以正常工作)
注:这不是正常的ssh粘合,只是为了开阔一下程序设计的视野!
在jsp或action或servlet中
调用次方法可得到applicationContext,前提是applicationContext放于WEB-INF下
<wbr></wbr>public static ApplicationContext getContext(HttpServletRequest request){
<wbr></wbr><wbr></wbr>String path=request.getRealPath("WEB-INF/applicationContext.xml");<wbr></wbr>
<wbr></wbr><wbr></wbr>ApplicationContext context=new FileSystemXmlApplication<wbr></wbr>Context(path);
<wbr></wbr><wbr></wbr>return context;
<wbr></wbr>}
<wbr></wbr><wbr></wbr>String path=request.getRealPath("WEB-INF/applicationContext.xml");<wbr></wbr>
<wbr></wbr><wbr></wbr>ApplicationContext context=new FileSystemXmlApplication<wbr></wbr>Context(path);
<wbr></wbr><wbr></wbr>return context;
<wbr></wbr>}