json技术

阅读更多

首先要写一个jsp文件

<%@page pageEncoding="utf-8"
contentType="text/html;charset=utf-8"%>







点击这儿,获得一个随机数



2其中涉及引入的js文件,可以下载获得

3 写一个servlet

package web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ActionServlet extends HttpServlet {

public void service(HttpServletRequest

request, HttpServletResponse response)
throws ServletException,

IOException {
response.setContentType

("text/html;charset=utf-8");
PrintWriter out = response.getWriter

();
String uri = request.getRequestURI();
String action = uri.substring

(uri.lastIndexOf("/"),
uri.lastIndexOf("."));
if(action.equals("/citys")){
String province =

request.getParameter("province");
if(action.equals("/getNum")){
Random r = new Random();
int num = r.nextInt(999);
System.out.println("num:" +

num);
out.println(num);

}
out.close();
}

}
4 部署在eclipse即可,运行jsp文件

 

 

 

 

  • json技术_第1张图片
  • 大小: 353 KB
  • prototype-1.6.0.3.zip (29.7 KB)
  • 下载次数: 0
  • my.zip (428 Bytes)
  • 下载次数: 0
  • 查看图片附件

你可能感兴趣的:(json)