问题如图
访问url能出现微信授权页面,后面跳转页面index.jsp就出现这种状况。Servlet api包也加了,怎么样解决?
访问url能出现微信授权页面,后面跳转页面index.jsp就出现这种状况。Servlet api包也加了,怎么样解决?
public class OAuthServlet extends HttpServlet {
private static final long serialVersionUID = -1847238807216447030L;[/align][align=left] public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");[/align][align=left] // 用户同意授权后,能获取到code
String code = request.getParameter("code");[/align][align=left] // 用户同意授权
if (!"authdeny".equals(code)) {
// 获取网页授权access_token
WeixinOauth2Token weixinOauth2Token = AdvancedUtil.getOauth2AccessToken("APPID", "APPSECRET", code);
// 网页授权接口访问凭证
String accessToken = weixinOauth2Token.getAccessToken();
// 用户标识
String openId = weixinOauth2Token.getOpenId();
// 获取用户信息
SNSUserInfo snsUserInfo = AdvancedUtil.getSNSUserInfo(accessToken, openId);[/align][align=left] // 设置要传递的参数
request.setAttribute("snsUserInfo", snsUserInfo);
}
// 跳转到index.jsp
request.getRequestDispatcher("index.jsp").forward(request, response);
}
}[code=html]<servlet>
<servlet-name>oauthServlet</servlet-name>
<servlet-class>
org.liufeng.course.servlet.OAuthServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>oauthServlet</servlet-name>
<url-pattern>/oauthServlet</url-pattern>
</servlet-mapping>[/align][align=left] <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
[/code]
解决方案
40
画圈的地方错了,是要填你的服务号的Appid,和Appsecret,不是填固定 的字符串