将数据以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); ...
随机推荐
- A1123. Is It a Complete AVL Tree
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...
- A1087. All Roads Lead to Rome
Indeed there are many different tourist routes from our city to Rome. You are supposed to find your ...
- react-native中的请求数据
很多移动应用都需要从远程地址中获取数据或资源.你可能需要给某个 REST API 发起 POST 请求以提交用户数据,又或者可能仅仅需要从某个服务器上获取一些静态内容. 使用 Fetch React ...
- 激活函数(ReLU, Swish, Maxout)
神经网络中使用激活函数来加入非线性因素,提高模型的表达能力. ReLU(Rectified Linear Unit,修正线性单元) 形式如下: \[ \begin{equation} f(x)= \b ...
- Luogu P2613 【模板】有理数取余
题目链接 \(Click\) \(Here\) 真心没啥东西,只要能\(Get\)到在数字输入的时候按位取模,以及除数也可以直接取模就可以了.(把每个数看做乘法原理和加法原理构造起来的即可.) #in ...
- (Dijkstra) POJ1797 Heavy Transportation
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 53170 Accepted: ...
- 选择排序Java版
package dataStructureAlgorithmReview.day01; import java.util.Arrays; /** * * @author shundong * */ p ...
- SQL语法基础之DELETE语句
SQL语法基础之DELETE语句 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看帮助信息 1>.查看DELETE的帮助信息 mysql> ? DELETE Na ...
- idea代码回退到前面的版本
好多时候一个项目添加了新功能,导致整个项目不能运行,而之前的版本又没有保存.怎么办了?回退到以前的版本就OK啦, 没错IDEA就是这个智能化. 第一步:点击项目名称->右键->选择Loca ...
- 解决 git push Failed to connect to 127.0.0.1 port 8-87: 拒绝连接
今天在本地使用nsq 测试的时候总是提示端口被占用 通过查看环境变量确实存在该代理 如何解决 使用netstat 命令查看端口被占用情况 根据经常ID号查看是哪一个进程正在被占用 如何还是不行,则在[ ...