This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Not able to display images

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%
BufferedReader in = new java.io.BufferedReader(new FileReader("C:\\Users\\Avinash\\Desktop\\testfile.txt"));
String pagesize = in.readLine();
String queryimage = in.readLine();
in.close();
%>
The page size is <%= pagesize%><br>
This is the query image:<br>
<a href=<%=queryimage%>> <img src=<%=queryimage%> border="2" width="150" height="150" alt="Alternative Image"/></a>

The contents of the testfile are
300
C:\Users\Avinash\Desktop\sampleimages\42.jpg
C:\Users\Avinash\Desktop\sampleimages\45.jpg
C:\Users\Avinash\Desktop\sampleimages\46.jpg
C:\Users\Avinash\Desktop\sampleimages\47.jpg
C:\Users\Avinash\Desktop\sampleimages\48.jpg
C:\Users\Avinash\Desktop\sampleimages\8.jpg

I am able to display the pagesize but not the images.The alternate text appears.
Why is it happening??

 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Avinash,

Welcome to JavaRanch!!

Please use Code tags to post the source code.

Also in.readLine() doesnt move to the next line. So you need to move to the next line and then read the next line. You can also try using Scanner to read it.
 
Avinash Bhashyam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sure that it reads the next line.I tried printing it and it always automatically goes to the next line.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Avinash Bhashyam wrote:I am sure that it reads the next line.I tried printing it and it always automatically goes to the next line.



Are you missing the Double qoutes for the src and href attributes of img and a tags respectively? You can have a look at the HTML generated by this JSP and see if its what you were expecting.
 
Avinash Bhashyam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.I am using then.I am able to do it the same way in java script.But even specifying the source directly dosent work
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the generated result looks something like this?
That will not work. If you want to point to files in your local file system then use the "file://" notation and do not try do it the windows way.

EDIT: OK, it might work on Internet Explorer but not on all browsers
 
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that using file-system references means that the images will work in your browser, but no one else's!
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was kinda waiting that to be his next question

BUT, it might be that he really IS designing a web application that will work only in his own machine!
 
Avinash Bhashyam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes its only for my machine but still i am not able to display images.
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Avinash Bhashyam wrote:Yes its only for my machine but still i am not able to display images.

And you tried adding the quotes AND tried to use the file://C:/dir/image.jpg syntax I mentioned?
 
Avinash Bhashyam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes
<img src="file://C:/sampleimages/1.jpg" border="2" width="150" height="150" alt="Alternative Image"/>
this is what i used
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Sorry, I am all out of ideas.
This is not a jsp issue anymore but a html syntax issue.
 
Marshal
Posts: 27211
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ilari Moilanen wrote:This is not a jsp issue anymore but a html syntax issue.


Or possibly a browser security issue. But it's still a weird idea and (in my opinion) a problem not worth solving. You don't use JSP for that sort of thing anyway.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic