JQuery plug-in simple learning instance tutorial, jquery plug-in instance tutorial
This document describes the jQuery plug-in and its usage. We will share this with you for your reference. The details are as follows:
(1) asynchronous paging plug-in flexgrid
1) Front-end js
<% @ Page language = "Java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
2) Background action
Finally, you only need to return a json file named rows.
(2) magnifiers, magnify
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
(3) autoComplete
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
(4) asynchronous upload
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
(5) Calendar
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The background action is as follows:
Package com. jquery. plugin. action; import java. io. bufferedInputStream; import java. io. bufferedOutputStream; import java. io. file; import java. io. fileInputStream; import java. io. fileNotFoundException; import java. io. fileOutputStream; import java. io. IOException; import java. util. arrayList; import java. util. list; import javax. servlet. http. httpServletRequest; import org. apache. struts2.ServletActionContext; import or G. apache. struts2.json. annotations. JSON; import com. jquery. plugin. dao. dataDao; import com. jquery. plugin. pojo. catalog; import com. opensymphony. xwork2.Action; import com. opensymphony. xwork2.ActionSupport; public class JQueryAction extends ActionSupport {/*****/private static final long serialVersionUID = 1L; private String q; private Integer rp; private Integer page; private Integer total; private List <Catalog> serarchResult = new ArrayList <Catalog> (); private List <Catalog> rows = new ArrayList <Catalog> (); private String sortname; private File upload; private String uploadFileName; public String getQ () {return q;} public void setQ (String q) {this. q = q;} public Integer getRp () {return rp;} public void setRp (Integer rp) {this. rp = rp;} public Integer getPage () {return page;} public voi D setPage (Integer page) {this. page = page ;}@ JSON (name = "total") public Integer getTotal () {return total;} public String redirect () {System. out. println ("go .. "); return Action. SUCCESS;} // {age: 1} [search: {age: 1}] @ JSON (name = "serarchResult") public List <Catalog> getSerarchResult () {return serarchResult;} public List <Catalog> getRows () {return rows;} public void setRows (List <Catalog> rows) {t His. rows = rows;} public String getSortname () {return sortname;} public void setSortname (String sortname) {this. sortname = sortname;} public File getUpload () {return upload;} public void setUpload (File upload) {this. upload = upload;} public String getUploadFileName () {return uploadFileName;} public void setUploadFileName (String uploadFileName) {this. uploadFileName = uploadFileName;} p Ublic String autoCompleteJQuery () {System. out. println ("q:" + q); List <Catalog> result = DataDao. getList (); if (! "". Equals (q) {for (Catalog catalog: result) {if (catalog. getCatalogName (). toLowerCase (). contains (q. toLowerCase () {serarchResult. add (catalog) ;}} System. out. println (serarchResult. size (); return Action. SUCCESS;} public String flexigrid () {try {List <Catalog> result = DataDao. getList (); Integer startIndex = (page-1) * rp; Integer endIndex = startIndex + rp; total = result. size (); while (endIndex> r Esult. size () {endIndex --;} System. out. println ("page:" + page + ": total:" + total); System. out. println ("sortname:" + sortname); for (int I = startIndex; I <(endIndex); I ++) {rows. add (result. get (I) ;}} catch (Exception e) {e. printStackTrace ();} return Action. SUCCESS;} public String ajaxFileUpload () {System. out. println ("begin... "); BufferedOutputStream out = null; BufferedInputStream in = null; Strin G uploadPath = null; String contextPath = null; try {// fileName = URLEncoder. encode (fileName, "GB2312"); System. out. println ("fileName:" + uploadFileName); byte [] buffer = new byte [1024]; HttpServletRequest request = ServletActionContext. getRequest (); contextPath = request. getSession (). getServletContext (). getRealPath ("/"); uploadPath = contextPath + "/upload/" + uploadFileName; System. out. println (uplo AdPath); out = new BufferedOutputStream (new FileOutputStream (uploadPath); int len = 0; in = new BufferedInputStream (new FileInputStream (upload); while (len = in. read (buffer, 0, buffer. length ))! =-1) {out. write (buffer, 0, len); out. flush () ;}} catch (FileNotFoundException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();} finally {try {if (out! = Null) {out. close () ;}if (in! = Null) {in. close () ;}} catch (IOException e) {e. printStackTrace () ;}} System. out. println ("uploaded successfully"); return null ;}}