67,550
社区成员




RequestMapping(value="/api",method = RequestMethod.POST)
@ResponseBody
public String getWeiXinMessage(HttpServletRequest request, HttpServletResponse response,HttpSession session) throws Exception
{
// 将请求、响应的编码均设置为UTF-8(防止中文乱码)
request.setCharacterEncoding("UTF-8"); //微信服务器POST消息时用的是UTF-8编码,在接收时也要用同样的编码,否则中文会乱码;
response.setCharacterEncoding("UTF-8"); //在响应消息(回复消息给用户)时,也将编码方式设置为UTF-8,原理同上;
//初始化配置文件
String respMessage = CoreService.processRequest(request);//调用CoreService类的processRequest方法接收、处理消息,并得到处理结果;
// 响应消息
//调用response.getWriter().write()方法将消息的处理结果返回给用户
//return "redirect:${pageContext.request.contextPath}/xxt/debug?arg="+respMessage;
//ServletContext application = request.getServletContext();
session.setAttribute("param001", respMessage);
//application.setAttribute("param001", "respMessage");
return respMessage;
}
RequestMapping(value="/api",method = RequestMethod.POST)
@ResponseBody
public String getWeiXinMessage(HttpServletRequest request, HttpServletResponse response,HttpSession session) throws Exception
{
// 将请求、响应的编码均设置为UTF-8(防止中文乱码)
request.setCharacterEncoding("UTF-8"); //微信服务器POST消息时用的是UTF-8编码,在接收时也要用同样的编码,否则中文会乱码;
response.setCharacterEncoding("UTF-8"); //在响应消息(回复消息给用户)时,也将编码方式设置为UTF-8,原理同上;
//初始化配置文件
String respMessage = CoreService.processRequest(request);//调用CoreService类的processRequest方法接收、处理消息,并得到处理结果;
// 响应消息
//调用response.getWriter().write()方法将消息的处理结果返回给用户
//return "redirect:${pageContext.request.contextPath}/xxt/debug?arg="+respMessage;
//ServletContext application = request.getServletContext();
session.setAttribute("param001", respMessage);
//application.setAttribute("param001", "respMessage");
return respMessage;
}
//用来调试
@RequestMapping(value="/debug")
public ModelAndView debug(HttpServletRequest req, HttpSession session){
ServletContext application = req.getServletContext();
ModelAndView mav= new ModelAndView("hello1");
mav.addObject("debug1", session.getAttribute("param001"));
return mav;
}
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<c:set var="stx" value="${pageContext.request.contextPath }"></c:set>
<head>
<title>hello1</title>
</head>
<body>
Hello 1
USER:${debug1}
url:${stx}
</body>
</html>