Using 3rd Party Java Libraries on JSP
How can I use 3rd party libraries like Twitter开发者_如何学编程4J on JSP?
It's a bit sick, but can you not just inline the appropriate Java in your JSP?
<%
// This should really be in a servlet
// Twitter4J code from their example
Twitter twitter = new TwitterFactory().getInstance();
List<Status> statuses = twitter.getFriendsTimeline();
System.out.println("Showing friends timeline.");
for (Status status : statuses) {
System.out.println(status.getUser().getName() + ":" +
status.getText());
}
%>
Make sure that the Twitter4J jar and all its dependencies are in your WEB-INF/lib/ folder. Then, give some serious thought to not doing this in a JSP if at all possible!
精彩评论