基本构建如上,注册页面提交的数据直接提交到了处理命令用的Action方法,未经过预设的过滤器filter;filter设置的过滤原则是:/*经测试,filter对应类运行正常,无问题。求高手解答。
PS:1:表单提交的数据会经过filter过滤吗?
2:如果用struts的拦截器,可否替代filter?菜鸟求解
PS:1:表单提交的数据会经过filter过滤吗?
2:如果用struts的拦截器,可否替代filter?菜鸟求解
2、自己百度看看structs的拦截器跟filter的区别
会的,因为你配置了/*
2:如果用struts的拦截器,可否替代filter?菜鸟求解
可以的,在你的struts.xml文件中配置interceptor
我在过滤器自定义类中提交了断点
测试:在访问注册页面时,过滤器起了作用,断点调试,但是当提交数据时(提交到注册用action),断点未生效,直接进入了注册用的action;
请问我是哪里出了问题?希望明示,还是说配置出了问题。
当提交请求时,封装好类只需要调用.save等hibernate自定义的方法即可,可以这么写么?
实质上是一个封装,把代码放到类A中。
private SessionFactory sf; public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException { try {
log.debug("Starting a database transaction");
//开始事务
sf.getCurrentSession().beginTransaction(); // Call the next filter (continue request processing)
chain.doFilter(request, response);
log.debug("Committing the database transaction");
//提交事务
sf.getCurrentSession().getTransaction().commit(); } catch (StaleObjectStateException staleEx) {
log
.error("This interceptor does not implement optimistic concurrency control!");
log
.error("Your application will not work until you add compensation actions!");
throw staleEx;
} catch (Throwable ex) {
// Rollback only
ex.printStackTrace();
try {
if (sf.getCurrentSession().getTransaction().isActive()) {
log
.debug("Trying to rollback database transaction after exception");
//提交错误日志后,回滚事务
sf.getCurrentSession().getTransaction().rollback();
}
} catch (Throwable rbEx) {
log.error("Could not rollback transaction after exception!",
rbEx);
}
throw new ServletException(ex);
}
} public void init(FilterConfig filterConfig) throws ServletException {
log.debug("Initializing filter...");
log.debug("Obtaining SessionFactory from HibernateUtil");
//初始化
sf = HibernateUtil.getSessionFactory();
}