Home > Web Front-end > JS Tutorial > Asynchronous transmission of json data format example code based on jquery_jquery

Asynchronous transmission of json data format example code based on jquery_jquery

WBOY
Release: 2016-05-16 17:12:54
Original
1017 people have browsed it

1.jsp代码如下

复制代码 代码如下:

<%@ 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 "/";
%>




Insert title here




 
 
 

 


2.访问 action代码如下

复制代码 代码如下:

public class JsonAction extends ActionSupport{
 public void getData() throws IOException
 {
  HttpServletRequest req = ServletActionContext.getRequest();
  String p1 = req.getParameter("param1");
  String p2 = req.getParameter("param2");

  HttpServletResponse rep = ServletActionContext.getResponse();
  rep.setContentType("text/json;charset=utf-8");
  PrintWriter pw = rep.getWriter();
  String data = "[{"id":"01","name":"zhongqian","description":"" p1 ""},{"id":"02","name":"zhangsan","description":"" p2 ""}]";
  pw.print(data);
  pw.flush();
 }
}

3.效果如下:

Asynchronous transmission of json data format example code based on jquery_jquery

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template