日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

easyui ajax post,实例详解EasyUI框架使用Ajax提交注册信息

發布時間:2023/12/2 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 easyui ajax post,实例详解EasyUI框架使用Ajax提交注册信息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文主要介紹了EasyUI框架 使用Ajax提交注冊信息的實現代碼的相關資料,希望通過本文能幫助到大家,需要的朋友可以參考下,希望能幫助到大家。

EasyUI框架 使用Ajax提交注冊信息的實現代碼

一、服務器代碼:

@Controller

@Scope("prototype")

public class StudentAction extends BaseAction {

private static final long serialVersionUID = -2612140283476148779L;

private Logger logger = Logger.getLogger(StudentAction.class);

private String rows;// 每頁顯示的記錄數

private String page;// 當前第幾頁

private Map josnMap = new HashMap<>();

// 查詢出所有學生信息

public String list() throws Exception {

return "list";

}

public String regUI() throws Exception {

return "regUI";

}

// 查詢出所有學生信息

public String listContent() throws Exception {

List list = studentService.getStudentList(page, rows);

System.out.println("list==" + list);

toBeJson(list, studentService.getStudentTotal());

return "toJson";

}

// 轉化為Json格式

public void toBeJson(List list, int total) throws Exception {

josnMap.put("total", total);

josnMap.put("rows", list);

JSONParser.writeJson(josnMap);// 自定義的工具類

}

public String reg(){

logger.error("kkk");

try {

studentService.save(model);

josnMap.put("success", true);

josnMap.put("msg", "注冊成功!");

} catch (Exception e) {

e.printStackTrace();

josnMap.put("success", false);

josnMap.put("msg", "注冊失敗!");

}

try {

ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");

ServletActionContext.getResponse().setCharacterEncoding("utf-8");

ServletActionContext.getResponse().getWriter().print(JSON.toJSONString(josnMap));

} catch (IOException e) {

e.printStackTrace();

}

return "toJson";

}

public void setRows(String rows) {

this.rows = rows;

}

public void setPage(String page) {

this.page = page;

}

public Map getJosnMap() {

return josnMap;

}

public void setJosnMap(Map josnMap) {

this.josnMap = josnMap;

}

}

二、BaseAction代碼:

import java.lang.reflect.ParameterizedType;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import cn.oppo.oa.service.DepartmentService;

import cn.oppo.oa.service.ForumService;

import cn.oppo.oa.service.PrivilegeService;

import cn.oppo.oa.service.RoleService;

import cn.oppo.oa.service.StudentService;

import cn.oppo.oa.service.UserService;

import com.alibaba.fastjson.JSON;

import com.opensymphony.xwork2.ActionSupport;

import com.opensymphony.xwork2.ModelDriven;

public abstract class BaseAction extends ActionSupport implements ModelDriven {

/**

*

*/

private static final long serialVersionUID = 1L;

@Resource

protected RoleService roleService;

@Resource

protected DepartmentService departmentService;

@Resource

protected UserService userService;

@Resource

protected PrivilegeService privilegeService;

@Resource

protected ForumService forumService;

@Resource

protected StudentService studentService;

protected T model;

@SuppressWarnings("unchecked")

public BaseAction() {

try {

// 得到model的類型信息

ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();

Class clazz = (Class) pt.getActualTypeArguments()[0];

// 通過反射生成model的實例

model = (T) clazz.newInstance();

} catch (Exception e) {

throw new RuntimeException(e);

}

}

public void writeJson(Object object){

try {

String json = JSON.toJSONStringWithDateFormat(object, "yyyy-MM-dd HH:mm:ss");

ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");

ServletActionContext.getResponse().setCharacterEncoding("utf-8");

ServletActionContext.getResponse().getWriter().write(json);

ServletActionContext.getResponse().getWriter().flush();

ServletActionContext.getResponse().getWriter().close();

} catch (Exception e) {

e.printStackTrace();

}

}

public T getModel() {

return model;

}

}

三、頁面代碼:

EasyUI框架

$(function(){

if(${"#easyui_regForm"}.form('validate')){

$.ajax({

url:'${pageContext.request.contextPath}/student_reg.action',

data:${"#easyui_regForm"}.serialize(),

dataType:'json',

success:function(obj,status,jqXHR){

if(obj.success){

$("#easyui_regDialog").dialog('close');

}

$.message.show({

title:'提示',

msg:obj.msg

});

}

});

}else{

alert('驗證失敗');

}

});

aa

cc

dd

kk

登陸名稱:
登陸密碼:
登陸名稱:
登陸密碼:
確定密碼:

四、struts2.xml配置

/p>

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

"http://struts.apache.org/dtds/struts-2.0.dtd">

/WEB-INF/jsp/user/loginUI.jsp

/noPrivilegeError.jsp

/test.jsp

/WEB-INF/jsp/{1}/{2}.jsp

/WEB-INF/jsp/{1}/saveUI.jsp

{1}_list?parentId=${parentId}

/index.jsp

topic_show?id=${id}

topic_show?id=${topicId}

josnMap

/easyui.jsp

相關推薦:

總結

以上是生活随笔為你收集整理的easyui ajax post,实例详解EasyUI框架使用Ajax提交注册信息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。