The previous mention of duplicate submit form issues, processing token password checksum, redirection, there is a frequently used method is the new page processing form submission, close the current page when finished, and refresh the page before sending the request.
Artdialog.js is used here.
1. File structure
2, user.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <%@ taglib uri= "/struts-tags" prefix= "s" %> <%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
3, useradd.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <%@ taglib uri= "/struts-tags" prefix= "s" %> <%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
4, Usermanageaction.java
Package com.myssh2.action;
Import java.io.IOException;
Import Java.io.PrintWriter;
Import Javax.annotation.Resource;
Import javax.servlet.ServletException;
Import Org.apache.struts2.ServletActionContext;
Import Org.springframework.context.annotation.Scope;
Import Org.springframework.stereotype.Controller;
Import Com.myssh2.bean.User;
Import Com.myssh2.service.UserService;
Import Com.opensymphony.xwork2.ActionContext;
Import Com.opensymphony.xwork2.ActionSupport;
@Controller @Scope ("prototype") public class Usermanageaction extends actionsupport{@Resource userservice userservice;
private user user;
Public user GetUser () {return user;
public void SetUser (user user) {this.user = user;
Public String Addui () {return "add"; public void Add () throws Servletexception, ioexception{servletactioncontext.getresponse (). setContentType ("Te
Xt/html;charset=utf-8 "); PrintWriter out = Servletactioncontext.getresponse ().Writer ();
try {userservice.adduser (user);
Actioncontext.getcontext () ("Message", "save Success");
Out.write ("{\" success\ ": true}");
catch (Exception e) {e.printstacktrace ();
Out.write ("{\" success\ ": False,\" msg\ ": \" Error\ "}");
}
}
}
Page effects
Use $ (' #userForm ') when submitting a form. Serialize (); Serialization of form data
Window.opener.art.dialog ({time:2,content: ' Save Success '}), return the page using window.open (or the parent page) and invoke the Artdialog plug-in's timed shutdown dialog
settimeout (function () {window.opener.location.reload ();},3); Use a timer to refresh a page that uses window.open (or as a parent page), The dialog and reload time Setup issues need to be readjusted.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.