Просмотр исходного кода

解决读取site配置环境通用问题

keyuan 4 лет назад
Родитель
Сommit
9afca39187
1 измененных файлов с 13 добавлено и 22 удалено
  1. 13 22
      src/main/java/com/key/dwsurvey/action/sysuser/SysPropertyAction.java

+ 13 - 22
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="<a href=\"${ctx }\"><img alt=\"\" src=\"${ctx }/images/logo/LOGO.png\" align=\"middle\" height=\"46\" ><span class=\"titleTempSpan\">OSS</span></a> ";
 		String headerDataPath="/WEB-INF/page/layouts/logo-img.jsp".replace("/", File.separator);
 		writeData(headerDataPath, headerData);
-		
+
 		if(adminTelephone!=null && adminEmail!=null){
 			//写footer文件
 			String footer1="<div class=\"dw_footcopy\" style=\"font-size: 16px;color: gray;\"><p style=\"margin-bottom: 6px;\">"
@@ -113,22 +104,22 @@ public class SysPropertyAction extends ActionSupport{
 	    	+"<a href=\"/\" style=\"color: gray;font-size: 16px;\">"+icpCode+"</a></p></div>";
 			String footerPath="/WEB-INF/page/layouts/footer-1.jsp".replace("/", File.separator);
 			writeData(footerPath, footer1);
-			
+
 			String adminInfo="<div style=\"color: gray;\"><h3 style=\"line-height: 40px;\">联系信息</h3><p style=\"line-height: 40px;\">邮箱:"+adminEmail+"</p><p style=\"line-height: 40px;\">电话:"+adminTelephone+"</p><p style=\"line-height: 40px;\">"+icpCode+"</p></div>";
 			String adminInfoPath="/WEB-INF/page/layouts/admin-info.jsp".replace("/", File.separator);
 			writeData(adminInfoPath, adminInfo);
 		}
-		
+
 		if(loginBgImg!=null){
 			String loginbgimg="<div class=\"m-logbg\"><img src=\"${ctx }"+loginBgImg+"\" style=\"margin-top:0px; margin-left: 0px; opacity: 1;\" width=\"100%\" ></div>";
 			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 {