关于SSH架构问题,很急~~ 现在公司要用SSH架构开发,我想弄个BASEACTION,但不知道怎么写比较好,最好是继承DispatchAction 的,希望大家给个例子 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在里面放一些你经常用到的东西...比如private final static ClassPathXmlApplicationContext ctx; // private final static ApplicationContext ctx; static { try { ctx = new ClassPathXmlApplicationContext( "classpath:TEST-INF/applicationContext*"); // ctx = new FileSystemXmlApplicationContext( // "classpath:MANPOWER-IBOOKING-INF/applicationContext.xml"); } catch (ExceptionInInitializerError iniex) { iniex.printStackTrace(); throw new RuntimeException( "Error initializing applicationContext.xml. Cause: " + iniex); } } /** * 公共的getBean方法 用于得到Spring中定义的bean的实例 * * @param <T> * @param clz * @return */ @SuppressWarnings("unchecked") public static <T> T lookupService(Class<T> clz) { return (T) ctx.getBean(clz.getSimpleName()); } /** * 公共的getBean方法 用于得到Spring中定义的bean的实例 * * @param beanId * @return */ @SuppressWarnings("unchecked") public static Object lookupService(String beanId) { return ctx.getBean(beanId); } public abstract class BaseAction extends DispatchAction implements ApplicationContextAware { private ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } public Object getBean(String id) { return this.applicationContext.getBean(id); } public abstract ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception;}这样就行了,也可以轻松获得spring上下文.. 还可以放上一些常用的service接口 一般都有可以取当前用户的方法...获取ApplicationContext什么的.. 找本《spring In Action》之类的基础书籍做做功课吧。速食面吃多了,营养不全面,影响发育。 在maven2中怎么配置sqlserver的依赖啊? 一个标签取值问题 web怎么下载一个软件 out.println("<UL>"); 创建JDBC数据源的问题????? JB的jsp转为tomcat服务器问题 关于TOMCAT中的Realm实现机制 文本框的onChange()事件的疑惑,请多多指教。 jsp如何处理数据并发的请写出代码 高手救命啊!!!!关于递归取值的问题!!! session,cookie的使用 关于滚动条的问题
比如private final static ClassPathXmlApplicationContext ctx; // private final static ApplicationContext ctx; static {
try {
ctx = new ClassPathXmlApplicationContext(
"classpath:TEST-INF/applicationContext*"); // ctx = new FileSystemXmlApplicationContext(
// "classpath:MANPOWER-IBOOKING-INF/applicationContext.xml");
} catch (ExceptionInInitializerError iniex) {
iniex.printStackTrace();
throw new RuntimeException(
"Error initializing applicationContext.xml. Cause: "
+ iniex);
}
} /**
* 公共的getBean方法 用于得到Spring中定义的bean的实例
*
* @param <T>
* @param clz
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T lookupService(Class<T> clz) {
return (T) ctx.getBean(clz.getSimpleName());
}
/**
* 公共的getBean方法 用于得到Spring中定义的bean的实例
*
* @param beanId
* @return
*/
@SuppressWarnings("unchecked")
public static Object lookupService(String beanId) {
return ctx.getBean(beanId);
}
ApplicationContextAware { private ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
} public Object getBean(String id) {
return this.applicationContext.getBean(id); } public abstract ActionForward execute(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception;
}
这样就行了,也可以轻松获得spring上下文..