AddPropertiesOperation.jsp
1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<%@ page import="weaver.general.Util" %>
<%@ include file="/templetecheck/filecheck/CheckUserIsSysadmin.jsp" %>
<%@ page import="java.util.*,org.dom4j.*,java.io.*,org.json.JSONObject" %>
<%@ page import="weaver.templetecheck.PropertiesUtil" %>
<%@ page import="weaver.templetecheck.FileUtil" %>
<%@ page import="weaver.security.file.FileType" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
String fpath = request.getParameter("path");
JSONObject object = new JSONObject();
ArrayList<String> types = new ArrayList<String>();
types.add(".properties");
if(!FileType.validateFileExt(fpath,types)) {
object.put("message","2");//文件创建失败
out.print(object.toString());
return;
}
FileUtil fileUtil = new FileUtil();
String content = request.getParameter("contentarea");
//判断path是存已存在,路径是否正确
File file = new File(fileUtil.getPath(fpath));
if(file.exists()) {
//response.sendRedirect("AddXml.jsp?message=1");//文件已存在
object.put("message","1");//文件已存在
out.print(object.toString());
return;
}
try {
PropertiesUtil prop = new PropertiesUtil();
//System.out.println("content:"+content);
String res = prop.saveFile(fpath,content);
object.put("message",res);//文件已存在
out.print(object.toString());
} catch(Exception e) {
e.printStackTrace();
//response.sendRedirect("AddXml.jsp?message=2");//文件创建失败
object.put("message","2");//文件创建失败
out.print(object.toString());
return;
}
%>