2013年工作中遇到的20个问题:101-120

101. 浮点数 处理。
  计算百分比,四舍五入计算总和,可能大于100%了。囧!
  (如果保留1位小数的话)
  1 8 8
  1/17=0.058~=0.1
  8/17=0.470~=0.5
  8/17=0.470~=0.5
 
  综合就是1.1,也就是110%了。
 
  要想提高准确率,应该提高保留的小数位数,这样误差会更小,小到可以接受。
   (如果保留2位小数的话)
 

102. 局域网也坑人。
    网络连接报错,提示数据库连接已关闭,sql state 08s01。
 SQLServer的网段是 1段的,而本机ip是5段的。
 这2天经常出现这种情况,后来把ip换成同一个段的就好了。
 
103.清除浏览器图标缓存
C:UsersFansAppDataRoamingSogouExplorerFavIcon

104. Sesseion过期
在公共页面设置session判断。
或者过滤器中设置。

异步执行请求需要特殊判断。

105.存储过程
create procedure addCompany(IN name varchar(255),IN address varchar(255),
IN register_no varchar(255),IN run_status varchar(255),IN registered_capital varchar(255),
IN legal_representative varchar(255),IN foundation_date date)

begin
  insert into b2c_company(name,address,register_no,run_status,registered_capital,legal_representative,foundation_date)
  values(name,address,register_no,run_status,registered_capital,legal_representative,foundation_date);
end

使用原因:

  for(int index=0;index<100;index++){
    //向数据库中增加1000个左右的实体
    addManyCompanies();
  }
 
  增加操作非常耗费时间。
 
 106.MySQL修改语句结束分隔符。
 delimiter $
 在MySQL终端中可以成功修改。
 在MySQL-Front中不可以。
 
 
 通过mysql-front导入,总是出现“编码-乱码”问题。
 在MySQL终端中可以成功导入。
 
 Windows下的MySQL-Front,界面美观,但经常出错。
 
 警示:工具也可能出现问题,而不仅仅是程序活脚本。
 
 107.xml配置,强调元素的顺序。
 <filter>
  <filter-name>encoding</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <async-supported>true</async-supported>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>UTF-8</param-value>
  </init-param>
  
 </filter>
 
 async-supported这个元素需要放在init-param的前面。(这种类似问题,我遇到了好几次,不错有时候
 元素的顺序不一定要严格按照schema中的要求)
 Element : filter
 Content Model : (((description*, display-name*, icon*)), filter-name, filter-class?, async-supported?, init-param*)
 
108.Tomcat提高启动速度。

1.每个项目单独使用1个Tomcat,Tomcat每次启动只需要启动1个项目。
2.Tomcat完全版,包含了Docs,Examples等项目,可以去掉,加快启动。

假设每次启动,减少时间0.1s。
1年,启动2000次,也就是200s,3分钟啊。

109.Spring注入Bean,最开始,只有实现类,注入没问题。
后来,加上了 事务注解等很多内容后,启动报错了,提示缺少CGLIB2 jar包。
我提取了 接口,然后就没有错误了。

另外一种方法:增加CGLIB2,不提取接口。

CGLIB生成接口(百科:使用CGLIB来为那些没有接口的类创建模仿(moke)对象)。
http://baike.baidu.com/view/1254036.htm


(为什么不想使用接口呢?1个实现类就得1个接口,太麻烦了。开发过程中,接口的参数,经常发生变动,1处变动,2处修改。)

110.eclipse中tomcat自动部署时自动停止问题processWorkerExit(w, completedAbruptly)。
解决方案:去掉java->debug->suspend execution on uncaught exceptions 选项钱的对勾就行了。

具体请参考:http://hi.baidu.com/hellodragon109/item/bdd485e981f2c1058d3ea8b7

111.启动时就初始化。

使用 static 加载,还是不行。
需要配置启动时就加载的Servlet,在Servlet中 加载资源。

当应用程序启动后,事实上并没有创建所有的Servlet实例。容器会在首次请求需要某个Servlet服务时,才将对应的Servlet类实例化、进行初始化操作,然后再处理请求。这意味着第一次请求该Servlet的客户端,必须等待Servlet类实例化、进行初始动作所必须花费的时间,才真正得到请求的处理。

112.Eclipse记忆最近打开的项目,默认为5个。
修改记忆个数:Preferences->Startup and shutdown ->Workspaces ->Number of recent workspaces to remember。
输入希望保存的个数。

113. log4j配置
log4j.appender.I.File=log/zsy_info

本机Ubuntu系统,日志文件位于 当前用户 /home/fans/log/zsy_info
服务器CentOS系统,日志文件位于 当前用户/home/username/tomcat7/bin/log/zsy_info

114.JDK版本
JDK7编译,服务器JDK6

115.isNumeric(CharSequence cs)
           Checks if the CharSequence contains only Unicode digits.
  只是简单地判断,字符序列中是否只含有Unicode数字,“1.5”返回false。
    
116. 文件分隔符 使用 File.seperator。
如果一直在同一个操作系统,一般不会遇到问题。
某个项目,我经常在Linux和Windows下的Eclipse工作,写成“//”,在Linux下可能不能运行。


117. 版本不同,maven仓库中的jar的groupId和artifactId不同。

        <dependency>
   <groupId>commons-httpclient</groupId>
   <artifactId>commons-httpclient</artifactId>
   <version>3.1</version>
  </dependency>

  <dependency>
   <groupId>org.apache.httpcomponents</groupId>
   <artifactId>httpclient</artifactId>
   <version>4.2.1</version>
  </dependency>
  
  
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.0.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.3</version>
      <scope>compile</scope>
    </dependency>

118.Tomcat启动报内存溢出。

 如果是cd TOMCAT目录的bin,来启动,在catalina.bat的第一行加上
 set JAVA_OPTS= -Xmx512M -Xms256M -XX:MaxPermSize=256m
 具体大小,自己定义。
 
 如果是在Eclipse中启动,双击控制面板“Tomcat v7.0 Server at localhost”,
 打开配置界面,点击“Open Launch Configuration”,Arguments->VM Arguments
 添加 -Xmx512M -Xms256M -XX:MaxPermSize=256m。

 参考资料:http://blog.sina.com.cn/s/blog_7c76d639010118co.html
 
119.Maven下配置Servlet包,“<scope>provided</scope>”不起作用,仍然会把servlet/jsp包拷贝到
WEB-INF目录导致,Tomcat启动出错。
<!--  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <version>3.0.1</version>
   <scope>provided</scope>
  </dependency>
  <dependency>
   <groupId>javax.servlet.jsp</groupId>
   <artifactId>javax.servlet.jsp-api</artifactId>
   <version>2.2.1</version>
   <scope>provided</scope>
  </dependency>  -->
  
(环境:Window7+Eclipse+Tomcat7)
这个问题是以前一个同学告诉我的,今天我体验了下,确实有问题。

可能是Eclipse的问题?

120.HTTP请求头

ajax获取数据
application/json js转换为js对象

test/plain js转换为string

有的时候,发送http请求,获取json数据,请求头应该为“application/json”
却写成了“test/plain”,也会出现问题。

相关阅读

工作问题 http://blog.csdn.net/FansUnion/article/category/1334371


原文地址:https://www.cnblogs.com/qitian1/p/6463678.html