Web 状态码 与 Request 请求的获取

Web 状态码 的使用 org.apache.http.HttpStatus

https://www.cnblogs.com/gitnull/p/9532129.html

Request 和 Reponse 的使用

Request(参考于一下博客)

https://blog.csdn.net/kxj19980524/article/details/85274624?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control&dist_request_id=1328602.56854.16151730597302063&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control

	// http://localhost:8611/cguarantee/sys/logout
	StringBuffer requestURL = request.getRequestURL();// 获取完整路径:
	// POST
	String nethod = request.getMethod();//获取请求方式:
	// /cguarantee
	final String contextPath = request.getContextPath();//获取项目名
	// /sys/logout
	String servletPath = request.getServletPath();//获取网名 也就是/login
	//  /cguarantee/sys/logout
	String requestURI = request.getRequestURI();//获取访问路径: 项目名+servlet

Response

	HttpServletResponse httpResponse = (HttpServletResponse) response;
	 httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
	 httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
	// 浏览器响应格式  对于中文的处理 
	httpResponse.setHeader("Content-type", "text/html;charset=UTF-8");
	 httpResponse.setCharacterEncoding("UTF-8");
	// 返回浏览器内容
	 String json = new Gson().toJson(ResultInfo.error(HttpStatus.SC_FORBIDDEN, "游客禁止访问!"));
	  httpResponse.getWriter().print(json);
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值