我感觉就是把renren 的instruction 给重新叙述一遍啊~~~ 那还是要叙述一遍~~~我先是尝试了一下没用renren api javascript sdk 的方法~~
还是从头说吧~~(其实就是按照renren的instruction做了一遍)
先建一个servlet 名字叫 com.shangliang.webcanvas.WelcomeServlet 实现一个跳转,到 /view/welcome.jsp上
package com.shangliang.webcanvas;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.shangliang.webcanvas.config.AppConfig;
/**
* Servlet implementation class WelcomeServlet
*/
@WebServlet("/WelcomeServlet")
public class WelcomeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public WelcomeServlet() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setAttribute("appId", AppConfig.APP_ID);
RequestDispatcher welcomeDispatcher = request.getRequestDispatcher("/views/welcome.jsp");
welcomeDispatcher.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
这个地方 renren instruction 上写的是 /renrenapp/home 然后再在 web.xml 里面配置 servlet mapping 什么的。我就从简了~~
<%@ page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Renren Webcanvas Demo -- Welcome</title>
</head>
<body>
<script type="text/javascript">
top.location="http://graph.renren.com/oauth/authorize?client_id=${requestScope.appId}&response_type=token&display=page&redirect_uri=" + encodeURIComponent("http://apps.renren.com/holdparty/HomeServlet");
</script>
Hi, Welcome!
</body>
</html>
当然可以登陆http://apps.renren.com/holdparty/HomeServlet 看看是否建立成功~~但事实上这么做是不安全的~~~不知道要怎么改过来~~
package com.shangliang.webcanvas;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.shangliang.webcanvas.config.AppConfig;
/**
* Servlet implementation class HomeServlet
*/
@WebServlet("/HomeServlet")
public class HomeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HomeServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setAttribute("appId", AppConfig.APP_ID);
RequestDispatcher welcomeDispatcher = request.getRequestDispatcher("/views/home.jsp");
welcomeDispatcher.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
This is my app home!
</body>
</html>
package com.shangliang.webcanvas.config;
public class AppConfig {
public static final String APP_ID = "";
public static final String API_KEY = "";
public static final String APP_SECRET = "";
}
之后就可以了~~登陆 http://apps.renren.com/holdparty/WelcomeServlet
就不截图了
因为第一次授权通过了就没有授权的界面了 。。。>_<