Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jstl <c:import url= /> not working

 
David Pantale
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm trying to use jstl c:import and I'm just getting junk. I just tried:

<c:import var="data" url="http://ichart.finance.yahoo.com/t?s=IBM" />
<c:out value="${data}"/>

the taglib is:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

I've also tried without the var="data" and the c:out and all I get is junk displaying, not an image. And, no, there are no compile or runtime errors. Below is what I'm getting:

‰PNG  IHDR¾_Ùêí”IDATxœí{PSWþÀ¿÷&!! y€€(ëQéÏW·Nm;ÝŸ­µÕ­­níXmíŽÝ®vwqµŒ­ÔêhÛµÓí¿µS]GeZ§Zº[§ÀŠbiP ¼ ä!Â#!{z¹^D„,÷3LæžsÏ9÷{“/ßó½ç|ϹI’ÀÂrÿp©£‚‚‚eË–uwwëõúeË–ŽãÁÁÁï¾ûîk¯½†ÎFFFšL¦ŽŽ¥R ÝÝÝR©tªDÍÍÍF£ÇqˆŽŽV©TŒF£1**Šž388xõêÕGy%[[[ëëë1 KHH u{F„Ýn×ëõ.— Çñ9sæðùü±45:/^‹ÅèX Ì™3‡žér¹d2™V«-))€îîn™Liii㸮§F£Q,òÉ';wî|å•WPfWWWCCCYY™@ °Ùl~y/c2™ÌfsZZŽãA”——ã8A/sóæMºê˜Í檪*‡ÃAåÔÕÕ-^¼˜ ˆââb·¿÷È*ˆššµZÖÖÖV[[›’’rϦî

Why isn't the image displaying?

Thanks
Dave
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's an image? You can't just blurt out the image data in the middle of HTML and expect something good to happen.

Answer the following question:

  • What's the proper way to display an image in HTML?
  •  
    David Pantale
    Ranch Hand
    Posts: 32
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Thanks for replying. Okay, I got the image to display by this:

    <img border="0" src="http://ichart.finance.yahoo.com/t?s=IBM" />

    Obviously I misunderstood the c:import tag! However, the code samples I saw all seemed to use just the <c:import> in that fashion.

    I was using this code from tutorialspoint.com

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <html>
    <head>
    <title><c:import> Tag Example</title>
    </head>
    <body>
    <c:import var="data" url="http://www.tutorialspoint.com"/>
    <cut value="${data}"/>
    </body>
    </html>

    So, if I want to include the whole web page in my jsp, what's the best way?

    Thanks
     
    Paul Clapham
    Sheriff
    Pie
    Posts: 20758
    30
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Are you seriously saying you found multiple examples which told you to use <c:import> to import an image? Can you provide links to those examples? Because I suspect they are really examples like the one you posted which import HTML. Which is what <c:import> is for.
     
    David Pantale
    Ranch Hand
    Posts: 32
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sorry, I simply meant that the examples weren't (to me, anyway) entirely clear and I made some assumptions.
     
    Paul Clapham
    Sheriff
    Pie
    Posts: 20758
    30
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    David Pantale wrote:Sorry, I simply meant that the examples weren't (to me, anyway) entirely clear...


    One of the hazards of learning new subjects!
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64629
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The <c:import> action will suck in the response of the URI passed to it, and emit it directly to the JSP response. So if it's an image, it'll just dump the image data into the generated HTML. As you saw, that's not going to work.

    Whatever the URI of &c:import> action returns must be appropriate to embed in the generated HTML at the point of the action.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic