• 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

Inserting images on JSP page

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I'm trying to insert few images on the JSP page.

but i would like to link those images from images folder in the application directory...

for e.g. images are in folder C:/JSPproject/images and i would like to insert them in page C:\JSPproject\web\myfirstpage.jsp

So my questions are...
1) Can i create images folder in JSP project? if yes, how?
2) Can i create CSS file in JSP project? if yes, how? or was the alnernative?
3) How can i give the reference to the css file from the JSP page?

Please its very urgent...any ideas welcomed


Thanks

-Joseph
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
simply put them in the root directory of your application, in other words

JSPProject
|______ images
|                   |_____ img.png
|______ css
|______ page1.jsp
|______ folder1
|                  |_____ page2.jsp
|______ WEB-INF


now in page1.jsp if you want to get a reference of img.png you do in the href of the image tag "images/img.png" while if you want to use the img.png in the page2.jsp you have to do "../images/img.png".

or you can start your paths with a "/" to start from the root.

its just a matter of directories, the same thing is done for css, javascript or any other file you want to use
 
Joseph jo
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Omar

Thanks for your reply.

I tried to follow as you said...here is my html code

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<A href="..\images1\chicklet.png" ID="image1">Inserting image on page.</A>
</body>
</html>

images are in C:\JSPProject \images1\chicklet.png and ....
JSP file is in...C:\JSPProject\web\myfirstpage.jsp

I'm using Netbeans 6.5 for developing this JSP page.

Could you please tell me what im doing wrong here?


Thanks

-Joseph
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I never used Netbeans for web page development, however try to locate a folder in your project that is named WEB-INF and create a sibling folder for it and name it img. (may be the WEB-INF folder is under a folder named web). and put your image inside the folder you created which is "img".


and reference your image in the JSP using this path "img/chicklet.png"


if you don't get it then i would suggest you to better understand how is the structure of a Java web application by visiting this page
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joseph

If you have created a web project in NetBeans, you must be having a Web Pages folder under your project directory. This will have more folders like:
META-INF
WEB-INF
and your JSP pages.

You can create an images folder right here. And access the images simply images/imagesname.jpg

Hope this helps.

 
Sheriff
Posts: 67747
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
See the JSP FAQ for information on properly formatting resource URLs. Using .. and \ are problems you need to fix.
 
Joseph jo
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Abhishek

i did that....but the problem im facing now is ...i have to give full path....
for e.g C:/JSPProject/images/img1.png

its not taking ../images/img1.png....then its not displaying the image.


Thanks

-Joseph

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using absolute physical paths (containing something like "C:") is an even bigger problem than what Bear mentioned. You need to avoid all of those.

http://faq.javaranch.com/java/ResourceUrlProblems is the page you should have read.
 
reply
    Bookmark Topic Watch Topic
  • New Topic