42 lines
1.8 KiB
Java
42 lines
1.8 KiB
Java
package com.hellogithub.servlet.githubinfo;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.hellogithub.service.githubService;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpServlet;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.annotation.WebServlet;
|
|
import java.io.IOException;
|
|
import java.io.PrintWriter;
|
|
import java.util.HashMap;
|
|
|
|
@WebServlet("/returnGithubInfo")
|
|
public class ret_Github_infoServlet extends HttpServlet {
|
|
private githubService githubservice = new githubService();
|
|
@Override
|
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
doPost(req,resp);
|
|
}
|
|
|
|
@Override
|
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
resp.setCharacterEncoding("UTF-8");
|
|
resp.setContentType("text/html; charset=utf-8");
|
|
// 设置响应头允许ajax跨域访问
|
|
String curOrigin = req.getHeader("Origin");
|
|
resp.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin);
|
|
resp.setHeader("Access-Control-Allow-Credentials", "true");
|
|
resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD");
|
|
resp.setHeader("Access-Control-Max-Age", "3600");
|
|
resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
|
resp.setContentType("application/json;charset=UTF-8");
|
|
|
|
PrintWriter writer = resp.getWriter();
|
|
String projectid = req.getParameter("projectId");
|
|
writer.println(githubservice.ret_Github_info(Integer.parseInt(projectid)));
|
|
writer.close();
|
|
}
|
|
}
|