0

How can I use 3rd party libraries like Twitter4J on JSP?

Nathan Campos
  • 28,769
  • 59
  • 194
  • 300

1 Answers1

1

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!

Randomness
  • 610
  • 6
  • 13