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() パス "/";
%>
ここにタイトルを挿入 <入力タイプ="button" value="获取" id="getResult">
2.访问アクション代码如下
public class JsonAction extends ActionSupport{
public void getData () 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();
文字列データ = "[{"id":"01","name":"zhongqian","description":"" p1 ""},{"id":"02","name":"zhangsan", "説明":"" p2 ""}]";
pw.print(data);
pw.flush();
}
}
3.效果如下: