wood burning stoves 2.0*
The moose likes JSP and the fly likes Not able to display images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Not able to display images" Watch "Not able to display images" New topic
Author

Not able to display images

Avinash Bhashyam
Greenhorn

Joined: Nov 09, 2010
Posts: 5
<%
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

Joined: Sep 08, 2007
Posts: 3071
    
  33

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.

Mohamed Sanaulla | My Blog
Avinash Bhashyam
Greenhorn

Joined: Nov 09, 2010
Posts: 5
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

Joined: Sep 08, 2007
Posts: 3071
    
  33

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

Joined: Nov 09, 2010
Posts: 5
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

Joined: Apr 15, 2008
Posts: 198
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

Joined: Jan 10, 2002
Posts: 61426
    
  67

Note that using file-system references means that the images will work in your browser, but no one else's!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
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

Joined: Nov 09, 2010
Posts: 5
Yes its only for my machine but still i am not able to display images.
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
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

Joined: Nov 09, 2010
Posts: 5
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

Joined: Apr 15, 2008
Posts: 198
Ok. Sorry, I am all out of ideas.
This is not a jsp issue anymore but a html syntax issue.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to display images