From 9afca3918772b2954248632a2a151de5d21b5f8c Mon Sep 17 00:00:00 2001 From: keyuan Date: Sun, 25 Apr 2021 21:39:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=AF=BB=E5=8F=96site?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=8E=AF=E5=A2=83=E9=80=9A=E7=94=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/sysuser/SysPropertyAction.java | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/key/dwsurvey/action/sysuser/SysPropertyAction.java b/src/main/java/com/key/dwsurvey/action/sysuser/SysPropertyAction.java index 806ddcf..e76bf0f 100755 --- a/src/main/java/com/key/dwsurvey/action/sysuser/SysPropertyAction.java +++ b/src/main/java/com/key/dwsurvey/action/sysuser/SysPropertyAction.java @@ -1,11 +1,6 @@ package com.key.dwsurvey.action.sysuser; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; +import java.io.*; import java.util.List; import java.util.Map; import java.util.Properties; @@ -42,19 +37,15 @@ import com.opensymphony.xwork2.ActionSupport; @Result(name=CrudActionSupport.SUCCESS,location="/sy/system/sys-property!input.action",type=Struts2Utils.REDIRECT) }) public class SysPropertyAction extends ActionSupport{ - + @Override public String input() throws Exception { HttpServletRequest request = Struts2Utils.getRequest(); - String fileName="site.properties"; - ServletContext sc = Struts2Utils.getSession().getServletContext(); - String filePath = "/WEB-INF/classes/conf/site/".replace("/", File.separator); - String fileRealPath = sc.getRealPath("/")+filePath+fileName; - File file=new File(fileRealPath); - InputStreamReader fr = new InputStreamReader(new FileInputStream(file),"UTF-8"); - - Properties p = new Properties(); + ClassLoader cl = this.getClass().getClassLoader(); + InputStream input = cl.getResourceAsStream("conf/site/".replace("/", File.separator)+fileName); + InputStreamReader fr=new InputStreamReader(input,"UTF-8"); + Properties p = new Properties(); try { p.load(fr); fr.close(); @@ -77,7 +68,7 @@ public class SysPropertyAction extends ActionSupport{ } return INPUT; } - + public String save() throws Exception { //管理员邮箱 String adminEmail = Struts2Utils.getParameter("adminEmail"); @@ -105,7 +96,7 @@ public class SysPropertyAction extends ActionSupport{ String headerData="\"\"OSS "; String headerDataPath="/WEB-INF/page/layouts/logo-img.jsp".replace("/", File.separator); writeData(headerDataPath, headerData); - + if(adminTelephone!=null && adminEmail!=null){ //写footer文件 String footer1="

" @@ -113,22 +104,22 @@ public class SysPropertyAction extends ActionSupport{ +""+icpCode+"

"; String footerPath="/WEB-INF/page/layouts/footer-1.jsp".replace("/", File.separator); writeData(footerPath, footer1); - + String adminInfo="

联系信息

邮箱:"+adminEmail+"

电话:"+adminTelephone+"

"+icpCode+"

"; String adminInfoPath="/WEB-INF/page/layouts/admin-info.jsp".replace("/", File.separator); writeData(adminInfoPath, adminInfo); } - + if(loginBgImg!=null){ String loginbgimg="
"; String loginbgimgPath="/WEB-INF/page/layouts/loginbgimg.jsp".replace("/", File.separator); writeData(loginbgimgPath, loginbgimg); } - + return SUCCESS; } - - + + private void writeData(String filePath,String data) { OutputStreamWriter fw = null; try {