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. vue2.0项目实战(1)基础入门

    最近公司的H5项目准备重构,部门老大说前端使用vue2.0来开发,所以就准备把整个项目的开发过程记录下来,一方面是为了记录开发过程中遇到的坑,另一方面也加强自己写作的能力. 什么是 Vue? 简要介绍 ...

  2. Django 子程序

    在Web应用中,通常有一些业务功能模块是在不同的项目中都可以复用的,故在开发中通常将工程项目拆分为不同的子功能模块,各功能模块间可以保持相对的独立,在其他工程项目中需要用到某个特定功能模块时,可以将该 ...

  3. 【译】12. Java反射——类的动态加载和重新加载

    原文地址:http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html 博主最近比较忙,争取每周翻译 ...

  4. Day16--Python--初识面向对象

    今日主要内容一. 面向对象思想 1. 面向过程. 重点在'过程'. 按照事物迭代发展流程. 优点: 简单,流水线式的操作 缺点: 可扩展性差.可维护性差. 2. 面向对象. 对象是属性和动作的集合体. ...

  5. Eclipse搭建SpringBoot之HelloWorld

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

  6. Gym 101911E "Painting the Fence"(线段树区间更新+双端队列)

    传送门 题意: 庭院中有 n 个围栏,每个围栏上都被涂上了不同的颜色(数字表示): 有 m 条指令,每条指令给出一个整数 x ,你要做的就是将区间[ x第一次出现的位置 , x最后出现的位置 ]中的围 ...

  7. 构造方法中关键字-- super

    package lijun.cn.demo4; public class Person { int num =777; public Person(){ System.out.println(&quo ...

  8. java io系列13之 BufferedOutputStream(缓冲输出流)的认知、源码和示例

    本章内容包括3个部分:BufferedOutputStream介绍,BufferedOutputStream源码,以及BufferedOutputStream使用示例. 转载请注明出处:http:// ...

  9. python 生成器和各种推导式

    ##################################总结############################### 什么是迭代器? 可迭代对象通过__iter__()可以转换成迭代 ...

  10. powershell 中常用cmd,unix命令(get-alias)

    powershell 中常用cmd,unix命令(get-alias) Get-Content Alias cat -> Get-Content Alias gc -> Get-Conte ...