How can I use 3rd party libraries like Twitter4J on JSP?
Asked
Active
Viewed 489 times
1 Answers
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
-
1Why don't you just answer "use a servlet" ans show a servlet example then? – BalusC Jul 08 '11 at 20:49
-
As the user asked for it as a JSP, I'm guessing they had a strong reason for not wanting to do it as a servlet! – Randomness Jul 08 '11 at 20:51