前言

如果使用了MVC框架(比方,struts2)。



server的响应数据。分3种情况

1、响应数据是结果页面
2、响应数据是json格式的数据
3、响应数据是json格式的数据,然后再又一次发出一次请求

注:响应数据要么是结果页面,要么是json格式的数据,否则。结果页面会覆盖掉json格式的数据——从而导致jquery的post的回调函数没有运行,导致struts2没有跳转到结果页面。



响应数据是结果页面

1.响应数据是结果页面,表示跳转到结果页面。

2.业务的应用场景通常是,查(询)数据就是跳转到结果页面。

代码演示样例
//业务控制器类
//查看任务单反馈信息(注:通常是查数据的时候。就是跳转到结果页面)
public String view() {
try {
feedbacklist = feedbackService
.getTaskFeedbackInfoListByTaskId(taskinfo.getTaskid());
} catch (Exception e) {
e.printStackTrace();
}
return "view"; }

响应数据是json格式的数据

1.响应数据是json格式的数据的话,那么肯定不是依据struts2配置文件的结果页面进行跳转——实际上,这个时候也没有配置结果页面。否则会覆盖掉json格式的数据。

2.业务的应用场景是。
1)对数据库进行增、删、改的操作。
2)刷新当前页面的部分数据。


代码演示样例
//.jsp代码:发出请求
<s:form action="taskInfoAction!save.action" id="myform" method="post"
cssClass='subForm'>
<s:hidden name='taskinfo.taskid' />
<div id="bodycontent">
<p align="left">
   
<font class="title_little">任务情况表</font>                                                                                
                                                   
         
</p>
<table width="1000" height="" border="1">
<tr>
<td class="clum_title" width="125">
项目编号:
</td>
<td width="125">
<s:hidden name="taskinfo.projectid" id="projectid"></s:hidden>
<s:textfield name="taskinfo.projectcode" maxlength="32" id="projectcode" cssStyle="width:123"/>
</td>
<td width="125">
项目简称:
</td>
<td width="125" colspan="3">
<s:textfield name="taskinfo.projectname" cssClass="required"
maxlength="64" id="projectname" cssStyle="width:325" onclick="selectProjectInfo()"/>
</td>
<!--
<td class="clum_title" width="125">
项目类型
</td>
<td width="125">
<s:select name="taskinfo.tasktype" headerKey="" id="projecttype"
cssClass="required" headerValue="--请选择--"
list="@com.telewave.projectmanagerweb.util.TwUtil@getDict('ProjectType')" onchange="showUnitModel(this)"/>
</td>
<td width="125">所属里程碑</td>
<td width="125" id="milestone_td"></td>
-->
</tr>
<tr>
<td class="clum_title">
工作计划
</td>
<td colspan="7">
<font class="introduction">(有计划必须填写)</font>
<s:hidden name="taskinfo.workplanid" id="workplanid" />
计划名称:
<s:textfield name="planname" cssClass="required"
maxlength="64" id="planname" cssStyle="width:160" /> 计划拟制人:
<s:textfield name="workplanname" cssClass=""
maxlength="64" id="workplanname" cssStyle="width:205" /> <input type="button" value="选择计划信息"
onclick="selectWorkPlanInfo('add')" style="width: 125" /> </td>
</tr>
<tr>
<td class="clum_title">
任务名称
</td>
<td colspan="2">
<s:textfield name="taskinfo.taskname" cssClass="required" cssStyle="width: 100%" maxlength="64" />
</td>
<td>
所属部门
</td>
<td colspan="2">
<s:select list="organs" name="taskinfo.departmentid" listKey="organcode" listValue="organname" headerKey="" headerValue="--请选择--" cssClass="required"/>
</td>
<td>
计划外任务单
</td>
<td>
<s:select list="#{'1':'是','0':'否'}" name="taskinfo.outofplan" headerValue="--请选择--" cssClass="required"/>
</td>
</tr>


//业务控制器类
// 保存或者改动领导批示信息
public void save() {
try {
/* 新增任务单基本信息 */
// 获取自己主动生成的id
String guidid = GuidManager.GetGuid();
taskinfo.setTaskid(guidid);
taskinfo.setLockstate("0");
taskinfo.setTaskcode(this.getTaskcode());// add by hql 20101108
// 新增一条任务单基本信息 if("1".equals(taskinfo.getOutofplan())){
Workplandetail workplandetail=new Workplandetail();
workplandetail.setWorkplandetailid(GuidManager.GetGuid());
workplandetail.setWorkplanid(taskinfo.getWorkplanid());
workplandetail.setPrincipal(taskinfo.getWorkplanname());
workplandetail.setWorkdescription(taskinfo.getTaskname());
workplandetail.setStartdate(taskinfo.getBegindated());
workplandetail.setEnddate(taskinfo.getEnddate());
workplandetail.setPrincipal(taskinfo.getAcceptperson());
workplandetail.setProjectid(taskinfo.getProjectid());
workplandetail.setProjectname(taskinfo.getProjectname());
workplandetail.setPlanresult(taskinfo.getOutputResult());
workplandetail.setWorkcontent(taskinfo.getWorkrequired());
workplandetail.setPlanworkload(taskinfo.getWorkload());
workplandetail.setTaskrelated("是");
plandetailService.save(workplandetail);
taskinfo.setWorkplanid(workplandetail.getWorkplandetailid());
}
taskinfoService.addTaskinfo(taskinfo);
/* 新增任务单方法 */ /* 假设页面中的变更信息不为空,则新增一条变更信息的记录
if (!StringUtils.isNull(changeinfo.getChangecontent())) {
// 设置变更信息的外键
changeinfo.setTaskid(guidid);
// 新增一条变更信息
changeinfoService.save(changeinfo);
} 新增变更信息方法 */ /* 假设页面中的绩效考核信息不为空,则新增一条绩效考核信息的记录 */
if (!isEmpty(evaluateinfo)) {
if (!StringUtils.isNull(evaluateinfo.getEvakuateremark()) || !StringUtils.isNull(evaluateinfo.getEvaluatetotalscore())
|| !StringUtils.isNull(evaluateinfo.getExecutionevaluatscore()) || !StringUtils.isNull(evaluateinfo.getQualityevaluatscore())
|| !StringUtils.isNull(evaluateinfo.getScheduleevaluatscore())) {
// 新增绩效考核信息
evaluateinfo.setTaskid(guidid);
evaluateinfoService.addTaskresultevaluationinfo(evaluateinfo);
}
}/* 新增绩效考核信息方法 */ // 新增工作产物信息
if (list!=null&&!list.isEmpty()) {
for (int i = 0; i < list.size(); i++) {
Taskworkproductinfo workproductentity = new Taskworkproductinfo();
workproductentity = list.get(i);
if (!isEmpty(workproductentity)) {
if (!isNullWorkProductEntity(workproductentity)) {
workproductentity.setTaskid(guidid);
String productid = GuidManager.GetGuid();
workproductentity.setId(productid);
workproductService.addTaskworkproductinfo(workproductentity);
} else {
if (!isEmpty(workproductentity.getId())) {
workproductService.deleteTaskworkproductinfo(workproductentity.getId());
}
}
}
}
}
super.printSuccssMsg("新增信息成功", guidid);
} catch (Exception e) {
super.printFaitureMsg("新增信息失败");
log.error(e.getMessage(), e);
}
}
//业务控制器类的父类
/**
* 响应数据-成功
* @param successMessage
* @param id
*/
protected void printSuccssMsg(String successMessage, String id) {
try {
if (isEmpty(id))
getResponse().getWriter().print(
"{success:true,tip:'成功提示',msg:'" + successMessage
+ "',Data:''}");
else
getResponse().getWriter().print(
"{success:true,id:'" + id + "',tip:'成功提示',msg:'"
+ successMessage + "',Data:''}");
} catch (Exception localException) {
}
}

响应数据是json格式的数据,然后在jquery post的回调函数里再又一次发出一次请求


代码演示样例
//.js代码:发出请求
// 遮罩层-注冊
function register1(){
// 提交表单
var form = document.getElementById("register");
var param = $("#register").serialize();
$.post(form.action,
param,
function(json){
if(json.success){
$.unblockUI(); // 退出遮罩层
window.location = "registerSuccess.jsp"; //发起一次新的请求
}else{
alert("注冊失败! ");
}
},
"json");
}

//配置文件
<struts>
<package name="loginPackage" extends="struts-default"
namespace="/login">
<action name="register" class="loginControllerBean" method="register"></action>
</package>
</struts>

//业务控制器类
public void register(){
//
loginBusiness.register(user); //
try {
response.getWriter().print("{\"success\":\"true\",\"data\":\"\"}");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

server的响应数据的更多相关文章

  1. Django 源码小剖: 响应数据 response 的返回

    响应数据的返回 在 WSGIHandler.__call__(self, environ, start_response) 方法调用了 WSGIHandler.get_response() 方法, 由 ...

  2. 对 响应数据写在config文件的再次优化

    之前写过 [基于moco的mock server 简单应用]这篇文章,然后自己这段时间也在做基金的接口测试,逛了一些论坛,然后对 响应数据写在config文件的再次优化,之前是把所有的响应数据都写到c ...

  3. Ocelot简易教程(六)之重写配置文件存储方式并优化响应数据

    本来这篇文章在昨天晚上就能发布的,悲剧的是写了两三千字的文章居然没保存,结果我懵逼了.今天重新来写这篇文章.今天我们就一起来探讨下如何重写Ocelot配置文件的存储方式以及获取方式. 作者:依乐祝 原 ...

  4. 使用Typescript重构axios(六)——实现基础功能:获取响应数据

    0. 系列文章 1.使用Typescript重构axios(一)--写在最前面 2.使用Typescript重构axios(二)--项目起手,跑通流程 3.使用Typescript重构axios(三) ...

  5. 使用Typescript重构axios(十三)——让响应数据支持泛型

    0. 系列文章 1.使用Typescript重构axios(一)--写在最前面 2.使用Typescript重构axios(二)--项目起手,跑通流程 3.使用Typescript重构axios(三) ...

  6. 使用Typescript重构axios(十六)——请求和响应数据配置化

    0. 系列文章 1.使用Typescript重构axios(一)--写在最前面 2.使用Typescript重构axios(二)--项目起手,跑通流程 3.使用Typescript重构axios(三) ...

  7. Java框架之SpringMVC 03-RequestMapping-请求数据-响应数据

    SpringMVC SpringMVC是一种轻量级的.基于MVC的Web层应用框架. 通过一套 MVC 注解,让 POJO 成为处理请求的控制器,而无须实现任何接口. 采用了松散耦合可插拔组件结构,比 ...

  8. 用 jQuery.ajaxSetup 实现对请求和响应数据的过滤

    不知道同学们在做项目的过程中有没有相同的经历呢?在使用 ajax 的时候,需要对请求参数和响应数据进行过滤处理,比如你们觉得就让请求参数和响应信息就这么赤裸裸的在互联网里来回的穿梭,比如这样: 要知道 ...

  9. ASP.NET Core 中文文档 第四章 MVC(2.3)格式化响应数据

    原文:Formatting Response Data 作者:Steve Smith 翻译:刘怡(AlexLEWIS) 校对:许登洋(Seay) ASP.NET Core MVC 内建支持对相应数据( ...

随机推荐

  1. 【转】Unity3D的LightProbe动态光探头用法介绍

    原创至上,移步请戳:Unity3D的LightProbe动态光探头用法介绍 之前曾经介绍过Unity3D的LightMapping烘焙的用法.单独使用的LightMapping效果很好,但由于只是把光 ...

  2. HA&Federation【转】

    转自:http://blog.csdn.net/tutucute0000/article/details/39756123 从nameNode1.namenode2克隆出namenode3.namen ...

  3. 【Android】Android消息处理机制

    三大核心类 android的消息处理有三个核心类:Looper,Handler和Message. 其实还有一个Message Queue(消息队列),但是MQ被封装到Looper里面了 Looper ...

  4. nginx源码分析:module机制

    根据nginx官方文档,添加一个module的介绍,当我们需要添加一个module时,需要以下操作: 1.为该module新建一个目录. 2.添加一个config文件,一个module核心代码源文件. ...

  5. SparkStreaming python 读取kafka数据将结果输出到单个指定本地文件

    # -*- coding: UTF-8 -*- #!/bin/env python3 # filename readFromKafkaStreamingGetLocation.py import IP ...

  6. lsblk命令

    lsblk命令用于列出所有可用块设备的信息,而且还能显示他们之间的依赖关系,但是它不会列出RAM盘的信息.块设备有硬盘,闪存盘,cd-ROM等等.lsblk命令包含在util-linux-ng包中,现 ...

  7. Android SDK下载和更新失败解决方法

    原因是dl-ssl.google.com访问不到,解决方法就是修改C:\Windows\System32\drivers\etc\hosts文件.添加一行: 74.125.237.1       dl ...

  8. [转]MySQL函数大全 及用法示例

    原文地址:http://blog.sina.com.cn/s/blog_4586764e0100h5ct.html 1.字符串函数ascii(str)   返回字符串str的第一个字符的ascii值( ...

  9. Spring的Assert工具类的用法

    简介 今天在看spring mvc源码时看到下面代码,感觉蛮有意思的,在这里记录下 Assert断言工具类,通常用于数据合法性检查,在JAVA编程中,通常会编写如下代码: if (name == nu ...

  10. WPF通过EventTrigger改变其他控件的值

    场景:点击TextBox后弹出Poppup 原理:使用EventTrigger后触发StoryBoard,通过StoryBoard改变其他控件的值. 参考代码: <Grid> <Gr ...