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字符串格式传到前台请求页面的更多相关文章

  1. PHP连接mysql数据库,并将取出的数据以json的格式输出

    <?php error_reporting(E_ALL || ~E_NOTICE); header("Access-Control-Allow-Origin:*");//此处 ...

  2. 后台拼接json字符串,传到前台时注意特殊符号处理

    1.后台拼接常用的形式:     sb.AppendFormat("\"字段名\":\"{0}\"", i + 1); 这个要注意字符串截断 ...

  3. urlencode($url):把url转义,当字符串数据以url的形式传递给web服务器时,字符串中是不允许出现空格和特殊字符串的

    1.对url进行编码转义

  4. Java将其他数据格式转换成json字符串格式

    package com.wangbo.util; import java.beans.IntrospectionException; import java.beans.Introspector; i ...

  5. EasyUI datagrid 分页Json字符串格式

    //EasyUI datagrid 分页Json字符串格式 //{"total":xx,"rows":[{...},{...}]} total:总数 rows: ...

  6. Java将其他数据类型转换成JSON字符串格式

    Student.java package com.demo.servlet; import java.util.List; import java.util.Map; public class Stu ...

  7. JS对象与json字符串格式

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  8. JSON字符串格式化为JSON对象

    根据项目需要,需要对json格式的字符串格式化为json对象,以下是解决方法: 参考文章:https://www.cnblogs.com/cailijuan/p/10150918.html

  9. JAVA中JSON字符串格式转换

    alibabab版本  即com.alibaba.fastjson *以下Node为实体类 //JSON字符串->Map Map map1 = (Map)JSON.parse(strJson); ...

随机推荐

  1. A1112. Stucked Keyboard

    On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the char ...

  2. 牛客网暑期ACM多校训练营 第九场

    HPrefix Sum study from : https://blog.csdn.net/mitsuha_/article/details/81774727 k较小.分离x和k. 另外的可能:求a ...

  3. Day032--Python--操作系统, process进程

    多道技术背景: 提高工作效率(充分利用I/O阻塞的时间)    (I: input, O: output) 同时执行多个任务 多道技术: 空间复用: 充分利用内存空间 时间复用: 充分利用I/O阻塞时 ...

  4. Eclipse搭建SpringBoot之HelloWorld

    你的eclipse需要先安装 Spring Tool Suite™ 第一种方法(不建议,之所以贴上是因为探索的过程) 首先新建Maven工程 勾选第一个按钮,第三个是选择working set ,你可 ...

  5. hdu 2476"String painter"(区间DP)

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 给定字符串A,B,每次操作可以将字符串A中区间[ i , j ]的字符变为ch, ...

  6. 第一个java程序的编译

    import java.io.*; public class EmployeeTest{ public static void main(String args[]){ /* 使用构造器创建两个对象 ...

  7. bigdata learning unit two--Spark environment setting

    1.下载 Spark安装之前的准备 文件的解压与改名 tar -zxvf spark-2.2.0-bin-hadoop2.7.tgz rm -rf spark-2.2.0-bin-hadoop2.7. ...

  8. bzoj1233 单调队列优化dp

    https://www.lydsy.com/JudgeOnline/problem.php?id=1233 数据结构优化dp的代码总是那么抽象 题意:奶牛们讨厌黑暗. 为了调整牛棚顶的电灯的亮度,Be ...

  9. Storm常用的类

    BaseRichSpout (消息生产者)BaseBasicBolt (消息处理者)TopologyBuilder (拓扑的构建器)Values (将数据存放到values ,发送到下个组件)Tupl ...

  10. 基于C语言libvirt API简单小程序

    libvirt API简单小程序 1.程序代码如下 #include<stdio.h> #include<libvirt/libvirt.h> int getDomainInf ...