У меня крошечная проблема с JSP.Я новичок в целом, поэтому, пожалуйста, будьте снисходительны со мной :) Я собираюсь нарисовать таблицу из 2 столбцов: один для фотографий профилей друзей в Facebook, а другой для имен друзей в 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;
}
}
Кто-нибудь видит проблему с этим кодом?