springmvc获取response时,报错ServletRequestAttributes cannot be resolved to a type,不缺包
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springmvc获取response时,报错ServletRequestAttributes cannot be resolved to a type,不缺包相关的知识,希望对你有一定的参考价值。
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
@RequestMapping(value="/test")
@ResponseBody
public Object test(@RequestParam Map<String, String> param,Model model,HttpServletResponse response)
springmvc中使用response的out.print问题
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { Member member = (Member) RequestUtil.parseRequestToObject(request,Member.class); if (member == null) { jzLogic.insertMember(member); return new ModelAndView("index"); } else { return new ModelAndView("Error", "message", "账号已被注册!"); } }
在上述代码中如果需要使用out.print打印如alert("");信息可按以下方式进行:
...... response.setContentType("text/html; charset=gbk"); PrintWriter out = response.getWriter(); out.println("<script language=‘javascript‘>"); out.println("alert(‘账号已被注册!‘);"); out.println("history.back();"); out.print("</script>"); return null; ......
return null,如果return new ModelAndView则直接转发
以上是关于springmvc获取response时,报错ServletRequestAttributes cannot be resolved to a type,不缺包的主要内容,如果未能解决你的问题,请参考以下文章
springMVC中获取request和response对象的几种方式(RequestContextHolder)
Docker获取镜像报错docker: Error response from daemon
aspx页面使用ajax遇到try catch中使用Response.End()报错
springMVC 解决中文乱码时使用produces报错?
Spring MVC 中获取 HttpServletRequest request, HttpServletResponse response 对象的方法