How do I fetch a dynamic Web content into a JSP page?
I'm sure this is really simple, but I have trouble finding documentation from an avalanche of other docs and I've had very little to do with Perl.
I have a script at http://example.com/cgi-bin/perl.pl
. It outputs some text. I want to be able to pull this output into a JSP page.
Do you know any examples of or websites that explain how to do 开发者_运维技巧this?
Your question seems to be about JSP and not Perl. Pulling output from any dynamic script (like the one in Perl) means you need to include generated output from that script in your JSP page. You didn't mention if the script outputs HTML or some other format, but assuming it's HTML, you can do two things:
Include
http://example.com/cgi-bin/perl.pl
as anIFRAME
(a standard HTML element) in the JSP pagePull the content using Java code, preferably using a dedicated library (see Pulling HTML from a Webpage in Java)
The latter method will work regardless of the output format of the script. I'd recommend however against putting the Java code directly inside JSP. It's better to put it in a JavaBean helper or even a custom JSP tag.
Use JSTL <c:import>
. If not done yet or your server doesn't support it, first install JSTL. Then do:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:import url="http://example.com/cgi-bin/perl.pl" />
That's it. It will be inlined on exactly that place among all other HTML. Be aware of XSS though if that output can contain client-controlled data.
精彩评论