前台拿值到后台:
后台 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+" " +a2+" " +seqid+" " +a4+" " + 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");
从后台拿值到前台
前台主要jsp:
function doInit(){ var url = "<%=contextPath%>/yh/subsys/oa/officeProduct/officeType/act/YHOfficeDepositoryAct/findOfficeDepositoryInfo.act"; jQuery('#exampleTableToolbar').bootstrapTable({ url:url, columns: [ {checkbox: true,'5%'}, {field:'seqId', visible:false}, {field: 'depositoryName',title: '办公用品库',sortable:true,align:'left','10%',formatter:equipmentCenterFunc}, {field: 'officeTypeId',title: '办公用品类别',sortable:true,align:'left','15%',formatter:equipmentCenterFunc}, {field: 'deptId',title: '所属部门',sortable:true,align:'left','15%'}, {field: 'manager',title: '仓库管理员',sortable:true,align:'left','17%'}, {field: 'proKeeper',title: '物品调度员',align:'left','5%'}, {field: '',title: '操作',align:'left','10%',formatter:opts}, {field:'groupNo', visible:false} ], height:'100%', striped: true, sortable:true, clickToSelect:true, sidePagination: 'server', dataType:'text', queryParamsType:'limit', pageSize:10, pageList:[10,20,30,50], pagination:true, escape:true, queryParams:function(params) { params.direct=params.order; params.sortColumn=params.sort; params.dtoClass='yh.core.data.YHPageQueryParam'; params.nameStr='seqId,depositoryName,officeTypeId,deptId,manager,proKeeper'; params.pageSize=params.limit; params.pageIndex=params.offset/params.limit; return params; }, responseHandler:function(res) { var rtJson = eval("("+res+")"); return {"total":rtJson.totalRecord, "rows":rtJson.pageData}; } }); } </script> </head> <body topmargin="5" onload="doInit()"> <div class="col-sm-12 animated fadeInRight"> <div class="example-wrap"> <form id="opForm" > <h2>办公用品库设置管理</h2> <div> <div class="row row-lg"> <div class="col-sm-12 example"> <table id="exampleTableToolbar" data-card-view="true" data-mobile-responsive="true"></table> </div> </div> </div> <tr> <td align="center" colspan="6" class="TableControl"> <input type="button" value="增加办公用品库" onclick="addNew();" class="BigButtonC"> </td> </tr> </form> </div> </div> </body>
后台主要代码:
/** * 查询办公用品库 * @param request * @param response * @return * @throws Exception */ public String findOfficeDepositoryInfo(HttpServletRequest request, HttpServletResponse response) throws Exception { YHRequestDbConn requestDbConn = (YHRequestDbConn) request .getAttribute(YHBeanKeys.REQUEST_DB_CONN_MGR); Connection dbConn = null; try { dbConn = requestDbConn.getSysDbConn(); YHPerson user = (YHPerson) request.getSession().getAttribute( "LOGIN_USER");// 获得登陆用户 List<YHOfficeDepository> findOfficeDep = officeDepository.findOfficeDepositorySet(dbConn, user); //list转换成json net.sf.json.JSONArray jsonArray = net.sf.json.JSONArray.fromObject(findOfficeDep); StringBuffer rtBuf = new StringBuffer("{totalRecord:"); rtBuf.append(findOfficeDep.size()); rtBuf.append(",pageData:"); rtBuf.append(jsonArray); rtBuf.append("}"); PrintWriter pw = response.getWriter(); pw.println(rtBuf); pw.flush(); System.out.println(rtBuf); request.setAttribute("findOfficeDepS", rtBuf); } catch (Exception e) { request.setAttribute(YHActionKeys.RET_STATE, YHConst.RETURN_ERROR); request.setAttribute(YHActionKeys.RET_MSRG, e.getMessage()); request.setAttribute(YHActionKeys.FORWARD_PATH, "/core/inc/error.jsp"); throw e; } return null; //return "subsys/oa/officeProduct/officeType/index.jsp"; }