项目中的积累,及常见小问题

一、浏览器清空缓存的时候若是选择清空cookie,其实就是清空session(google浏览器,ie11没有这个问题)
二、本地环境最好用ip地址127.0.0.1而非localhost,重定向要加request.getcontentpath()上下文javascript

三、当控制session超时的时候,点击tab按钮,会有iframe嵌套问题,能够在session超时设置的返回jsp代码中,顶部加上以下判断例:如login.jsphtml

<script type=text/javascript>
if (window != top) 
    top.location.href = location.href; 
</script>

<html>java

四、在web.xml。这里注意点是浏览器不请求保持在20分钟后,session过时web

<!-- 配置sessio过时时间单位:分钟 -->spring

<session-config>
       <session-timeout>20</session-timeout>
 </session-config>

五、项目中使用aop控制日志和事务shell

注意点:spring配置文件是必须加的json

<!-- 配置使Spring采用CGLIB代理 -->
    <aop:aspectj-autoproxy proxy-target-class="true"/>

当你的aop想切springmvc的controller类,必定也在springmvc配置文件上加入上面的配置centos

用aop从session中取出user信息的方法,部分代码以下:浏览器

public void doBefore(JoinPoint jp) {
 
   	 Object[] args = jp.getArgs();  
     HttpServletRequest request = null;  
     StringBuilder str = new StringBuilder();
     //经过分析aop监听参数分析出request等信息  
     for (Object obj : args) {  
         if (obj instanceof HttpServletRequest) {  
             request = (HttpServletRequest) obj;  
         } else if (obj instanceof HttpServletResponse) {
        	 
         } else {
        	 str.append(obj);
         }
         
     } 
     UserVO user = null;
     if (request != null) {  
    	 user = (UserVO) request.getSession().getAttribute("currentUser");
    	 if (user != null) {
    		 logger.info("用户名:{}", user.getUserName());  
    	 }
     }

其中发现个问题,spring和springmvc扫描注解包,最好要彻底分离,springmvc监控controller,spring加载其他控制权,让springMVC的配置xml和spring容器的配置xml分开,在各自的xml中配置本身该作的事情,不要让springMVC去扫描不应本身管理的注解。不然到后面总是出一些奇怪的问题。例如:spring中的事务回滚和aop配置缓存

六、在作aop日志管理的时候遇到获取session问题。解决方案以下:

HttpSession session = (HttpSession) RequestContextHolder.getRequestAttributes().getSessionMutex();

spring 版本不一样方式,最好的方法.getSessionMutex();可能不一样

简单的是使用注解

    @Autowired
    HttpServletRequest request;  respose 同理。。。

七、获取最新记录问题,例如获取gps数据表中,每辆车的最新gps数据

/* 
数据以下: 
name val memo 
a    2   a2(a的第二个值) 
a    1   a1--a的第一个值 
a    3   a3:a的第三个值 
b    1   b1--b的第一个值 
b    3   b3:b的第三个值 
b    2   b2b2b2b2 
b    4   b4b4 
b    5   b5b5b5b5b5 
*/ 

--1、按name分组取val最大的值所在行的数据。 
--方法1: 
select a.* from tb a where val = (select max(val) from tb where name = a.name) order by a.name 

八、centos 6.5 本地copy文件到服务器

shell命令  rz

九、jackson pojo转换json时间问题,它默认的是时间很长的数字

ObjectMapper objmapper = new ObjectMapper();

objmapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

十、eclipse设置项目管理

第一次方式

第2种方式

十一、获取tomcat webapp真实目录,例如app文件放在 webapp的 app文件夹下

request.getSession().getServletContext().getRealPath("/app");

十二、maven + jetty启动项目问题,在用eclipse的jetty启动项目的时候,下载文件总是出内存溢出,后来改为在pom.xml,加jetty配置控制,在 maven的 web包的pom.xml中

  </dependencies> 以后加,

<build>         <plugins>             <plugin>                 <groupId>org.mortbay.jetty</groupId>                 <artifactId>jetty-maven-plugin</artifactId>                 <version>8.1.16.v20140903</version>                 <configuration>                     <webApp>                         <contextPath>/</contextPath>                     </webApp>                     <connectors>                         <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">                             <port>8080</port>                             <maxIdleTime>60000</maxIdleTime>                         </connector>                     </connectors>                     <scanIntervalSeconds>0</scanIntervalSeconds>                     <scanTargetPatterns>                         <scanTargetPattern>                             <directory>src/main/webapp</directory>                             <includes>                                 <include>**/*.xml</include>                                 <include>**/*.properties</include>                             </includes>                         </scanTargetPattern>                     </scanTargetPatterns>                     <stopKey/>                     <stopPort/>                 </configuration>             </plugin>         </pl

相关文章
相关标签/搜索