1、服务端图片上传功能在eclipse里面没问题,部署到tomcat上面报错Cant create Cached file?
后来发现tomcat的目录里面没有temp文件夹,导致缓存文件无法创建而报错:解决方法是1、直接新建temp文件夹; 2、代码里面判断一下,没有就新建;
String webroot = RequestContextUtils.getWebApplicationContext(request).getServletContext().getRealPath("/");
//判断下tomcat下temp文件是否存在,不存在需要新建
File folder = new File(webroot);
if(folder.isDirectory()) {
folder = folder.getParentFile().getParentFile();
if(folder.isDirectory()) {
folder = new File(folder, "temp");
if(!folder.exists() || !folder.isDirectory()) {
folder.mkdir();
}
}
}其中RequestContectUtils是spring的,用来解决没有HttpRequestServer的问题;
2、$.ajax方法请求json调用时发回调到了error函数里面,但是statusCode=200;
这是因为返回值格式不对,虽然调用成功了,但是返回值不是json的格式,success函数不接收,交给了error;
3、写了一个代码行数的统计功能,代码如下:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ClassCodeTest {
public static List<File> classFiles = new ArrayList<>();
public static void main(String[] args) {
String src = "\\src\\main\\java";
int num = countCodeLineNum(src);
System.out.println("目前为止共创建java文件"+classFiles.size()+"个;编写代码:("+num+")行");
}
public static int countCodeLineNum(String src) {
int count = 0;
getCountClass(new File(src), classFiles);
for (File file : classFiles) {
count+= getClassLineNum(file);
}
return count;
}
public static int getClassLineNum(File file) {
int index = 0;
FileReader reader = null;
BufferedReader bufferedReader = null;
try {
reader = new FileReader(file);
bufferedReader = new BufferedReader(reader);
while(bufferedReader.readLine()!=null) {
index++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
if(reader!=null) {
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return index;
}
public static void getCountClass(File src,List<File> classFiles) {
File[] childrenFile = src.listFiles();
for (File file : childrenFile) {
if(file.exists() && file.isDirectory()) {
getCountClass(file,classFiles);
}else if(file.exists() && file.getName().endsWith(".java")) {
classFiles.add(file);
}
}
}
}4、mysql数据库报错如下:
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (11296 > 1024). You can change this value on the server by setting the max_allowed_packet' variable.
解决办法:
1、 mysql> show VARIABLES like 'max_allowed_packet'; 查看大小
show GLOBAL VARIABLES LIKE 'max_allowed_packet'; show VARIABLES LIKE 'max_allowed_packet';
可以编辑my.cnf,在[mysqld]段或者mysql的server配置段进行修改 max_allowed_packet = 20M 重启mysql
2、命令设置 set global max_allowed_packet = *1024*1024*20
5、max_allowed_packet修改后自动恢复到1024:
看了很多,最有可能的原因是被攻击了!!!打开日志记录查看 确实被攻击了;
打开日志开关:show variables like 'log%'; 找到log;
执行 SET GLOBAL general_log = 'ON'; 表示记录所以数据库操作,方便查看!