wood burning stoves*
The moose likes JSP and the fly likes jstl <c:import url= /> not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl <c:import url= /> not working" Watch "jstl <c:import url= /> not working" New topic
Author

jstl <c:import url= /> not working

David Pantale
Ranch Hand

Joined: Mar 16, 2010
Posts: 32

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

Joined: Jan 10, 2002
Posts: 60785
    
  65

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?


  • [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    David Pantale
    Ranch Hand

    Joined: Mar 16, 2010
    Posts: 32

    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
    Bartender

    Joined: Oct 14, 2005
    Posts: 18541
        
        8

    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

    Joined: Mar 16, 2010
    Posts: 32
    Sorry, I simply meant that the examples weren't (to me, anyway) entirely clear and I made some assumptions.
    Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18541
        
        8

    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

    Joined: Jan 10, 2002
    Posts: 60785
        
      65

    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.
     
     
    subject: jstl <c:import url= /> not working
     
    Similar Threads
    mockQuestion from javabeat
    jsp Iterate tag
    c:import does not work
    validating an image before display using c:import
    JSP and XML