将数据以json字符串格式传到前台请求页面
1.前台ajax方法(这个是在FlowDocAction的add.jsp页面)
//序列号
var preFileNo = factoryCode+deptCode+"-"+modelSeriesCode+"-"+workProcessCode;
var yz=$.ajax({
type:'get',
url:'FlowDocVersion!getSort.shtml?preFileNo='+preFileNo,
cache:false,
dataType:'json',
success:function(data){
if(data){
//将json字符串转换为json对象,因为要通过点的方法来拿它的属性 eval('('+str+')');
var obj = eval('(' + data + ')');
alert(obj.preFileNo);
}
},
error:function(data){
alert("出错了");
}
});
2.后台页面:因为此处是ssh的action,方法返回String类型默认去找对应页面,而请求的页面是另一个action的result对应的页面,所以此处的
(这里是在FlowDocVersinoAction.java类里)
//文件编码
public String getSort() throws Exception {
try {
//查询所有类似的文件
String sql="select FileNo from FlowDocVersion where Status <>0 and FileNo like '"+preFileNo+"%'";
System.out.println("getSort.sql:"+sql);
List<FlowDocVersion> fileNoList = new FlowDocVersionFacade().find(sql,"FlowDocVersion.FileNo");
int max = 0 ;
if(fileNoList.size()==0){//没有与当前新增文件编码相同的文件编码
preFileNo = preFileNo+"01";
//将数据以json字符串形式响应到请求页面start
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType("text/html");
PrintWriter out;
out = response.getWriter();
//将要被返回到客户端的对象
JSONObject json=new JSONObject();
json.accumulate("preFileNo", preFileNo);
out.println(json.toString());
out.flush();
out.close();
//将数据以json字符串形式传到请求页面end
System.out.println(preFileNo);
return "";
}else {
for(FlowDocVersion e:fileNoList){
//拿到文件编码后边的序号
String sort = e.getFileNo().substring(preFileNo.length(), e.getFileNo().length());
if(sort.length()>0){
//解决 NumberFormatException
//把最大序号赋给max
try{
int i = Integer.valueOf(sort);
if(max<i){
max = i;
}
}catch (NumberFormatException ep) {
preFileNo = preFileNo+"01";
System.out.println(preFileNo);
}
}
}
max=max+1;//最大序号+1作为新增文件的序号
if(max<10){//小于10个位用0填补
preFileNo = preFileNo+"0"+max;
}else{
preFileNo = preFileNo+max;
}
}
return null;
}catch(Exception e) {
this.setMsg("生成文档编码出错");
Logger.getLogger(this.getClass()).error("FlowDocVersionAction getSort() Exception", e);
return ERROR;
}
}
将数据以json字符串格式传到前台请求页面的更多相关文章
- PHP连接mysql数据库,并将取出的数据以json的格式输出
<?php error_reporting(E_ALL || ~E_NOTICE); header("Access-Control-Allow-Origin:*");//此处 ...
- 后台拼接json字符串,传到前台时注意特殊符号处理
1.后台拼接常用的形式: sb.AppendFormat("\"字段名\":\"{0}\"", i + 1); 这个要注意字符串截断 ...
- urlencode($url):把url转义,当字符串数据以url的形式传递给web服务器时,字符串中是不允许出现空格和特殊字符串的
1.对url进行编码转义
- Java将其他数据格式转换成json字符串格式
package com.wangbo.util; import java.beans.IntrospectionException; import java.beans.Introspector; i ...
- EasyUI datagrid 分页Json字符串格式
//EasyUI datagrid 分页Json字符串格式 //{"total":xx,"rows":[{...},{...}]} total:总数 rows: ...
- Java将其他数据类型转换成JSON字符串格式
Student.java package com.demo.servlet; import java.util.List; import java.util.Map; public class Stu ...
- JS对象与json字符串格式
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- JSON字符串格式化为JSON对象
根据项目需要,需要对json格式的字符串格式化为json对象,以下是解决方法: 参考文章:https://www.cnblogs.com/cailijuan/p/10150918.html
- JAVA中JSON字符串格式转换
alibabab版本 即com.alibaba.fastjson *以下Node为实体类 //JSON字符串->Map Map map1 = (Map)JSON.parse(strJson); ...
随机推荐
- PHP中empty,is_null,isset的区别
有时候分不清这几个的区别,特此记录,以备不时之需 isset 判断变量是否已存在 empty 判断变量是否为空或为0 is_null 判断变量是否为NULL 变量 empty is_null isse ...
- Linux列字符替换
假如存在file1.txt,其内容如下: aa bb cc dd ee ff gg hh 现将第一列(aa 和 ee)统一修改为mm 则需要输入命令行: awk '{$1="mm" ...
- jmeter自动生成测绘报告并发送邮件
步骤: 1.安装ant,添加到环境变量(windows是将bin目录添加到path.cmd命令输入 ant -v 查看版本号) (mac:brew install ant ant –version) ...
- python之迭代器、生成器与面向过程编程
目录 一 迭代器 二 生成器 三 面向过程编程 一.迭代器 1.迭代器的概念理解 ''' 迭代器从字面上理解就是迭代的工具.而迭代是每次的开始都是基于上一次的结果,不是周而复始的,而是不断发展的. ' ...
- hibernate的学习周
Hibernate核心:ORM(对象关系映射) BeginSession关闭的时候要session.close(),而getCurrentsession不需要,它会自动关闭 Session.load( ...
- mac上安装虚拟机
1.Mac | 怎么安装虚拟机 2.Mac | 怎么安装VMware Fusion虚拟机 资源下载链接: 1.win7旗舰版-64位.iso 2.VMFusion811.rar
- Event Recommendation Engine Challenge分步解析第四步
一.请知晓 本文是基于: Event Recommendation Engine Challenge分步解析第一步 Event Recommendation Engine Challenge分步解析第 ...
- Android中不显示标题
在网上找的用requestWindowFeature(Window.FEATURE_NO_TITLE)这一句报错. 后来找到另一种方法 1.在res/values/styles.xml中添加如下代码 ...
- Sidetiq 定时任务
class SidekiqCreateMonthPlanWorker #定时自动生成下月计划 include Sidekiq::Worker include Sidetiq::Schedulable ...
- laravel 5.4 fopen(): Filename cannot be empty
1.出错的报错信息(我在用laravel5.4文件上传时候出错的) laravel 5.4 fopen(): Filename cannot be empty 2.解决的方法 在php.ini中修改临 ...