对于web系统,我觉得用spring可以解决,写个拦截器,记录每个方法的执行时间,写入日志就行了,但对于非web系统呢,假如有个c/s系统,如何着手?
解决方案 »
- JAVA EE关于就业问题
- x64系统weblogic11g 最大可以设置多大的内存
- 统计出一篇文章中出现次数最多的单词
- 解压版tomcat和安装版tomcat默认的根目录不一致啊,可不可以修改?
- 求个精品课程网站
- el jstl ognl 有什么区别
- 请问JB9.0下怎么实验RMI
- 请教:如何在服务器的一个确定的文件夹下新建一个文件夹和命名。同时,如果对一个文件进行重命名?thx
- 觉得特别迷茫,请大家指点,关于学习J2EE,Weblogic和structs的方法、步骤。
- weblogic连接不上的问题,(急)
- 在仅用Hibernate时如何实现更好的dao层代码和service层代码?
- 批量导入真的可以提高效率吗,JDBC批量导入和普通循环插入数据的比较
这个怎么用?有啥效果
{
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
{
//获取URL请求的相对路径信息URI的前缀部分,形如:/servlet/test.do的test
String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
// logger.debug(lookupPath);
WebSession webSession = null;
try
{
webSession = handler.getClass().getDeclaredMethod(lookupPath, HttpServletRequest.class, HttpServletResponse.class)
.getAnnotation(WebSession.class);
}
catch (Exception e)
{
//
}
if (webSession == null) webSession = handler.getClass().getAnnotation(WebSession.class);
//do something...
}
} spring配置文件 servlet-do.xml
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="interceptors">
<list>
<ref bean="webSessionInterceptor"/>
</list>
</property>
</bean> <bean id="annotationMethodHandlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> <bean id="webSessionInterceptor" class="frame.web.mvc.WebSessionInterceptor"/>
控制器类文件 MainController.java
@Controller
@WebSession
public class MainController
{
private final Logger logger = LoggerFactory.getLogger(getClass()); @WebSession
@RequestMapping
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception
{
return new ModelAndView("main/index.jsp");
} @WebSession
@RequestMapping
public ModelAndView make(HttpServletRequest request) throws Exception
{
return new ModelAndView("main/index.jsp");
}
}
请求/main.index.do时,系统能够执行MainController中的方法index,拦截器类也可以根据index方法的参数项来获取Method和Method上声明的Annotation项@WebSession。