• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java HTML URL construction

 
Ranch Hand
Posts: 164
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi every body I am generating HTML via java having just a bit of trouble with url construction so i am typically using

data.writeTofile("<h2><font color = blue>is a stock picture</font></h2>"); which works just fine together with the rest of the code to make the webpage

now i have a working url which pulls in a picture of a book, to be accurate its a picture of a blank to indicate that a picture is not available you can view this by pasting this http://www.communicatingwithpictures.talktalk.net//Cimages/no-image.gif in to the address bar or this code in an html document


data.writeTofile("          <img name='theBook'src=' http://www.communicatingwithpictures.talktalk.net//Cimages/no-image.gif' width='167' height='280'/>");

now what i am trying to do is replace the last part with a variable so that i can select different books to display at the moment the are a few books on this webspace an example of which is The Arabian Nights) Childrens Classics so changing no-image.gif for 9781858137162.jpg works fine

If however i substitute no-image.gif for a variable lets call it the lastbit and try to construct the url then it does not work can anyone tell me why or tell me how to solve the problem

so just to be clear


data.writeTofile("<h2><font color = blue>is a stock picture</font></h2>"); i use this type of arrangement to generate the html


data.writeTofile("          <img name='theBook'src=' http://www.communicatingwithpictures.talktalk.net//Cimages/no-image.gif' width='167' height='280'/>");

works fine

String lastbit ="no-image.gif"; this is so i can change to say lastbit ="9781858137162.jpg";

does not work why?

data.writeTofile("          <img name='theBook'src=' http://www.communicatingwithpictures.talktalk.net//Cimages/lastbit' width='167' height='280'/>");

if i change no-image.gif to 9781858137162.jpg manually it does work




 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

peter m hayward wrote:does not work why?

data.writeTofile("&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<img name='theBook'src=' http://www.communicatingwithpictures.talktalk.net//Cimages/lastbit' width='167' height='280'/>");



That is a string literal. It does not use or attempt to use any variable. Just because you have a string with the same couple of characters as the variable name does not mean that those characters will be replaced by the variable. You have to actually use the variable. Maybe something like this will work:


I am sure there are better libraries for writing HTML in Java than you writing your own. This all looks very fragile to me. I think you should investigate some tool to use to handle the HTML writing for you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic