有一个很小的JSP问题。对于整个比特来说是新的,所以请对我宽大:) 我打算画一张2列的表格:一个用于Facebook好友个人资料图片,另一个用于Facebook好友名称。 我在这个论坛上查了一些参考资料,但他们似乎没有解决。在JSP中显示15个带有名称和个人资料图片的Facebook好友列表
这里有云的基本代码结构:
/*
* @(#)Friends.java 1.0
*
*/
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.restfb.Connection;
import com.restfb.DefaultFacebookClient;
import com.restfb.Parameter;
import com.restfb.exception.FacebookException;
/**
* Facebook Application Friends Servlet
*
* @version 3.0
*/
public class Friends extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final int MAX_FRIENDS = 15;
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {
// set MIME type and encoding
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
// get writer for output
final PrintWriter p = response.getWriter();
// make sure that we have obtained an access token, otherwise redirect
// to login
final String accessToken = request.getParameter("access_token");
if (accessToken == null) {
response.sendRedirect(Config.getValue("LOGIN_URL"));
return;
}
// get client
final DefaultFacebookClient client = new DefaultFacebookClient(accessToken);
// retrieve the document with all friend user ids
try {
final Connection<UserWithPicture> friends = client.fetchConnection("me/friends",
UserWithPicture.class, Parameter.with("fields", "name, picture"),
Parameter.with("limit", Friends.MAX_FRIENDS));
p.println(/** Here goes the code for table display **/);
} catch (final FacebookException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
p.flush();
p.close();
}
@Override
public void doPost(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
现在,我已经写了下面的代码,它不工作对任何怪异的原因有可能是。这里有云:
p.println("<table>" +
"<c:forEach>" +
"<tr>" +
"<td>" + friends.getPicture()
"</td>" +
"<td>" + friends.name
"</td>" +
"</tr>" +
"</c:forEach>" +
"</table>");
凡Getpicture中()方法是在UserWithPicture.java类实现:
import com.restfb.Facebook;
import com.restfb.types.User;
/**
* Model class for a User with picture
* @version 1.0
*/
public class UserWithPicture extends User {
@Facebook
private String picture;
public String getPicture() {
return this.picture;
}
}
有谁看到问题与此代码?
看起来像一个家庭作业 – hawkeye 2011-05-30 10:49:30
是啊 - 这是一个几个星期前:) – 2011-06-08 20:12:16