Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to display images

 
Avinash Bhashyam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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??

 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic