1 package ese.modify; 2 import java.io.BufferedReader; 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileNotFoundException; 6 import java.io.FileOutputStream; 7 import java.io.IOException; 8 import java.io.InputStreamReader; 9 import java.io.OutputStreamWriter; 10 11 import javax.annotation.Resource; 12 import javax.servlet.http.HttpServletRequest; 13 import javax.servlet.http.HttpServletResponse; 14 15 import org.apache.log4j.Logger; 16 import org.springframework.stereotype.Controller; 17 import org.springframework.web.bind.annotation.RequestMapping; 18 import org.springframework.web.bind.annotation.RequestMethod; 19 import org.springframework.web.bind.annotation.RequestParam; 20 import org.springframework.web.bind.annotation.ResponseBody; 21 22 import ese.configure.Configuration; 23 import ese.configure.ConfigurationManager; 24 import ese.controller.BaseController; 25 26 @Controller 27 public class Modifyconf2 extends BaseController{ 28 //private org.codehaus.jackson.map.ObjectMapper jsonMapper = new org.codehaus.jackson.map.ObjectMapper(); 29 30 //@Resource 31 private ConfigurationManager configuremanager; 32 33 @RequestMapping(value="read.do",method=RequestMethod.GET) 34 public @ResponseBody 35 String read(@RequestParam("readpath") String readpath,HttpServletRequest request,HttpServletResponse response) throws IOException{ 36 37 //String url2 = ResourceUtils.findResource(readpath); 38 Configuration conf = configuremanager.getConfiguration(); 39 String path = conf.getProperty("configFilePath"); 40 //String url2 = path + readpath; 41 String url2 = readpath; 42 43 String content=readtxt2(url2); 44 //content=readtxt2(url2); 45 /* try { 46 jsonMapper.writeValue(response.getOutputStream(), "success"); 47 } catch (Exception e) { 48 logger.debug("in modifyconf.do jsonMapper.writeValue wrong."); 49 } */ 50 51 return content; 52 } 53 54 @RequestMapping(value="modify.do",method=RequestMethod.GET) 55 public @ResponseBody 56 String modify(@RequestParam("modifypath") String modifypath,@RequestParam("content") String content,HttpServletRequest request,HttpServletResponse response) throws IOException{ 57 58 Configuration conf = configuremanager.getConfiguration(); 59 String path = conf.getProperty("configFilePath"); 60 String url2 = path + modifypath; 61 62 //String url = ResourceUtils.findResource(modifypath); 63 savetxt(url2,content); 64 return "Success"; 65 } 66 67 private void savetxt(String url,String content) { 68 File file=new File(url); 69 OutputStreamWriter outputStreamWriter = null; 70 try { 71 outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file),"UTF-8"); 72 } catch (Exception e) { 73 // TODO Auto-generated catch block 74 e.printStackTrace(); 75 } 76 try { 77 outputStreamWriter.write(content); 78 outputStreamWriter.close(); 79 80 } catch (IOException e) { 81 // TODO Auto-generated catch block 82 e.printStackTrace(); 83 } 84 85 } 86 87 private String readtxt2(String url){ 88 BufferedReader rd = null; 89 try { 90 rd = new BufferedReader(new InputStreamReader(new FileInputStream(url))); 91 } catch (FileNotFoundException e1) { 92 // TODO Auto-generated catch block 93 e1.printStackTrace(); 94 } 95 StringBuffer sb = new StringBuffer(); 96 String line; 97 try { 98 while ((line = rd.readLine()) != null) 99 {100 sb.append(line);101 102 sb.append("\r\n");103 //sb.append(rd.)104 }105 }catch (Exception e) {106 // TODO Auto-generated catch block107 e.printStackTrace();108 }109 try {110 rd.close();111 } catch (IOException e) {112 // TODO Auto-generated catch block113 e.printStackTrace();114 }115 line= sb.toString();116 return line;117 }118 119 120 121 }
1 2 3 4 5修改配置 6 7 8 9 10 11 51 52 53 54 55
58 81 82 83 | 84 80