Ajax mode and modify form Properties action (commit path) way to submit form form

Source: Internet
Author: User
Tags foreach bind commit json
There are six main ways of data interaction between browsers and servers:
1. form submission;
2. Hyperlinks;
3.js/jquery Mode
    3.1 replace the address bar location.href= "Address bar";(This article has)
    3.2 JS Submission Form ___ Take advantage of form's Action property (this article has)
    3.3 Ajax (this article has)
The front page code is as follows:
<%@ page language= "java" contenttype= "text/html;
Charset=utf-8 "pageencoding=" UTF-8 "%> <% String Path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; %> <%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%> <%@ taglib uri= "http://java.sun.com/ Jsp/jstl/fmt "prefix=" FMT "%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  
  Back-end code    
Package cn.nrsc.ssm.action;
Import java.util.List;
Import Javax.annotation.Resource;
Import Javax.servlet.http.HttpServletRequest;
Import Org.springframework.stereotype.Controller;
Import Org.springframework.web.bind.annotation.RequestBody;
Import org.springframework.web.bind.annotation.RequestMapping;

Import Org.springframework.web.bind.annotation.ResponseBody;
Import Cn.nrsc.ssm.pojo.Items;
Import Cn.nrsc.ssm.pojo.QueryVo;

Import Cn.nrsc.ssm.service.ItemsService; @Controller @RequestMapping ("/formsubmit") public class Formsubmittest {@Resource private itemsservice Itemsservi

    Ce @RequestMapping ("list") public String list (HttpServletRequest request) {list<items> list = Itemsservice
        . Findallitems ();
        Request.setattribute ("itemList", list);
    return "Formtest"; }//ajax Test @RequestMapping ("Ajax") public String Demo1_ajax (Queryvo queryvo,integer[] IDs) {//ids to Che The value of Ckbox, which can be submitted to background System.out.println (111);Casually output something, convenient to break the point return "redirect:list"; }//By modifying the Action property (address bar address) of the form form to submit data to the background test @RequestMapping ("DeleteItems") public String deleteitems (queryvo query Vo, integer[] IDs) {//ids is the value of the checkbox, which can be submitted to the background System.out.println (111);//random output of something, convenient to break the point Retu
    RN "Redirect:list"; }//Receive page data ' {' name ': ' Test commodity ', ' price ': 99.9} ' encapsulates the object and returns the JSON data @RequestMapping ("Edititemsubmit_requestjson") public @
        Responsebody Items Edititemsubmit_requestjson (@RequestBody items items) {Items.setid (111);
    return items; }//Receive data from the Location.href method @RequestMapping ("/playplay") Public String Playplay (string IDs) {System.out
    . println (IDs);//random output points, convenient to break the point return "redirect:list";
 }
}
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.