Ajax cross-page submission form _ajax related

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.