You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

10 months ago
package com.dsideal.gw.Handler;
import cn.hutool.json.JSONObject;
import com.jfinal.handler.Handler;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class RouterHandler extends Handler {
@Override
public void handle(String target, HttpServletRequest req,
HttpServletResponse res, boolean[] isHandled) {
//可以正确获取到URL的完整路径
String servletPath = req.getServletPath();
JSONObject jo = new JSONObject();
jo.put("servletPath", servletPath);
jo.put("success", true);
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Cache-Control", "no-cache");
res.setCharacterEncoding("UTF-8");
res.setContentType("application/json");
try {
res.getWriter().println(jo);
res.getWriter().flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
isHandled[0] = true;
}
}