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";
}
}