标签:
后台 controller
package com.buss.sisenmess.controller; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jeecgframework.web.system.pojo.base.TSUser; import org.jeecgframework.web.system.service.SystemService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/sendMessageAllController") public class SendMessageAll { @Autowired private SystemService systemService; // 调用方法: href=/yh/sendMessageAllController.do?syncUser @RequestMapping(params="syncUser") public void syncUser(HttpServletRequest request, HttpServletResponse response,Long user) { //DataSourceContextHolder.setDataSourceType(DataSourceType.dataSource4); // 更改设置数据源 //List<Map<String, Object>> list =findForJdbc("select * from userlist", "userlist"); //System.out.println(1); //String seqId= request.getParameter("user"); String content = request.getParameter("contentTd"); System.out.println(content); TSUser toUser = systemService.findUniqueByProperty(TSUser.class, "seqId", user); String seqid= toUser.getUserId(); String lujing = "//2560P-PC/ServerMsgList/111.sisenmsg"; File file = new File(lujing); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } try { OutputStreamWriter bw = new OutputStreamWriter( new FileOutputStream(file),"UTF-8"); String a1="True"; //True/False(模拟用户/系统消息) String a2="haha"; //发送人编号(系统消息时可为空) String a3="hehe"; //接收人编号(向所有人发送时可为空) String a4="False"; //True/False(向所有人发送/向单一用户发送) String a5="hello 世界!"; //消息正文 bw.write(a1+"\r\n" +a2+"\r\n" +seqid+"\r\n" +a4+"\r\n" + content); bw.flush(); bw.close(); bw.close(); } catch (IOException e) { e.printStackTrace(); } try { FileReader fr = new FileReader(file); BufferedReader bReader = new BufferedReader(fr); String string = bReader.readLine(); System.out.println(string); fr.close(); bReader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
前台主要js
function sendmessage(){
var psnNo = document.getElementById("contentTd").value;
alert(psnNo);
//alert(user);
alert(jQuery("#smsBodyInfoForm").serialize());
//var url = "<%=contextPath%>/com.buss/sisenmess/service/impl/SmsSyncImpl/syncUser.act?seqId="+seqId;
var url = "<%=contextPath%>/sendMessageAllController.do?syncUser";
jQuery.post(url,jQuery("#smsBodyInfoForm").serialize(), function(res) {
});
}
向文件写入
String lujing = "//2560P-PC/ServerMsgList/111.sisenmsg";//文件地址
File file = new File(lujing);
OutputStreamWriter bw = new OutputStreamWriter(
new FileOutputStream(file),"UTF-8");
标签:
原文地址:http://www.cnblogs.com/caozengling/p/5594902.html