aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Images are not shown in netbeans web application on jsp page 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 » Engineering » IDEs, Version Control and other tools
Bookmark "Images are not shown in netbeans web application on jsp page" Watch "Images are not shown in netbeans web application on jsp page" New topic
Author

Images are not shown in netbeans web application on jsp page

shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Hi All,
I am using netbeans and developing web application. I want to show images on jsp pages .I don't know where the problem is do I make a mistake to put images folder whether the problem in code...?Please can you help me?
folders are as below-----

mywebapplication
|______Web pages
|______Source Packages
|______Libraries
|______Configuration files

and Web pages contains as below

Web pages
|______page1.jsp
|______index.jsp
|______page2.jsp
|______WEB-INF
|______images

and images contains as below

images
|_______logo.png
|_______sunday_logo.jgp
|_______home_img_001.png



I read topics about images in java but though I follow solutions I don't get expected output. I do the code as below


Thank you in advance
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

In your code you are using sunday_logo.jpg but in the directory structure its not present.
Can you check if the given file is present in the images folder?


Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Yes there is file sunday_logo.jpg
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

in img src, use "/" as "/images/sunday_logo.jpg"
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Sumit Patil wrote:In your code you are using sunday_logo.jpg but in the directory structure its not present.
Can you check if the given file is present in the images folder?



The file is present sunday_logo.jpg

I also tried code as "../images/sunday_logo.jpg"
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Still not showing image I also tried hardcoded path such as "c:/.../images/sunday_logo.jpg" but that too doesn't works...
Help me please
Thank you
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Unless your web app is the ROOT web app, starting the path with "/" (or "\") is incorrect. Using a local path like "C:/" also won't work.
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

If you have hard coded the location and still its not showing, it means the file name you have mentioned is not present at the given location. Check the filename, extension.
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Remove the "/" in front of images and try again.
Sorry i misinterpreted your directory structure.
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Tim Moores wrote:Unless your web app is the ROOT web app, starting the path with "/" (or "\") is incorrect. Using a local path like "C:/" also won't work.

Sorry, But I don't understand what you exactly want to say..can you please explain it. and I am using netbeans .
Thank you
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Sumit Patil wrote:Remove the "/" in front of images and try again.
Sorry i misinterpreted your directory structure.

File extension is .jpg and I also tried '/' as you suggested but when I run the file in google crome and inspect the image element and open link in new tab it indicates path as http://localhost:8080/images/sunday_logo.jpg
and show error as--

HTTP:status 404
GlassFish Server Open Source Edition 3.1.2
The requested resource () is not available
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

In my last post, i said to remove the "/" in present in front of images i.e

img src="images/sunday_logo.jpg"

please try this. and also close the img tag.

Ashish Agre
Ranch Hand

Joined: Jan 22, 2011
Posts: 73

try this line of code.


if it still doesn't work then use extension as .jpeg :)
even after this it doesn't work then move sunday_logo.jpg image to the images folder inside web pages and write as




| B.E IT | SCJP 6.0 98 % |
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Yes I tried as you suggested Sir,

But Same problem is there
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Ashish Agre wrote:try this line of code.
.............


I tried both options .I have searched on google too. from 2 days I am trying to solve this problem but where is mistake I can't find it out...!!....:(

When I inspect element and open link in new tab it shows path as....

http://localhost:8080/images/sunday_logo.jpg in browser's url

Thank you
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296



As you can notice, the URL formed for the jpg file is not correct. The application name is missing from it.
Can you please stop Tomcat server, delete the folders in work folder of Tomcat and try again? Also clear the history of your browser.
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
@Sumit Patil

Before starting netbeans I always stop tomcat. Becouse Netbeans indicates to stop server anather server is running glassfish server..

Now also it is stoped.
Thank you
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Your app is deployed on Tomcat or Glassfish?
What i wanted to say was to clear the cache of the server on which your app is running. This ensures that the server is not processing the request from the cache it is maintaining.
Also it might be helpful to clear the cache of the browser as the above logic implies to browser also.
Hope this helps.
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
May I send you screan-shots ?
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Sumit Patil wrote:Your app is deployed on Tomcat or Glassfish?
..............
Hope this helps.


It's glassfish .........I cleared cache too...
nothing change
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
My project is located at.....
C:\Users\Documents\NetBeansProjects\sunday


now folders inside sunday are
build,images,nbproject,src,web,menu,build.xml

jsp psges are inside the web folder
Thank you
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

shilpa deshmukh-kadam wrote:My project is located at.....
C:\Users\Documents\NetBeansProjects\sunday


now folders inside sunday are
build,images,nbproject,src,web,menu,build.xml

jsp psges are inside the web folder
Thank you

In your first post, you mentioned the location of images folder as myapplication-->web pages-->images.
Now which is the correct path? Where is the sunday_logo.jpg is located? point the img tag to proper location of the jpg file and it will work.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
This is a typical problem that arises when running a web app in an IDE instead of a proper servlet container. My guess would be that you would have long since solved the problem if the IDE was not part of the equation.
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Sumit Patil wrote:......In your first post, you mentioned the location of images folder as myapplication-->web pages-->images.
Now which is the correct path? Where is the sunday_logo.jpg is located? point the img tag to proper location of the jpg file and it will work.



Sorry sir,
First is correct
But the path of whole folder mywebapplication is such as below

C:\Users\Documents\NetBeansProjects\mywebapplication

This one is correct path and first one is too correct becouse in first post I don't tell you where exactly mywebapplication folder is ....!!

e.g path of sunday_logo.jpg is
C:\Users\Documents\NetBeansProjects\mywebapplication\web pages\images\sunday_logo.jpg
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Tim Moores wrote:This is a typical problem that arises when running a web app in an IDE instead of a proper servlet container. My guess would be that you would have long since solved the problem if the IDE was not part of the equation.

So what will be the solution when I want to use IDE...:?
Thank you
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Why do you want to use the IDE? IDEs are for development, not for deployment. If the very act of using an unrealistic deployment scenario is causing problems, then the natural step would be to move towards a more realistic scenario, wouldn't you agree?
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

As suggested by Tim, why don't you create a war file of your app and deploy directly to Tomcat or Glassfish? I think that will help.
And please, i am not a "Sir" you can call me Sumit :)
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Thank you both of you Tim Moores, Sumit Patil
I will try your suggestion ...

Thank You very much for giving me your valuable time....
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Hello once again,
I got solution for IDE .........
There is palette tab where we got image control we have to just double click on it. then browse image file with browse botton. set height and width.......then click ok
That's the solution
kiran badi
Greenhorn

Joined: Oct 26, 2009
Posts: 26
>>>There is palette tab where we got image control we have to just double click on it. then browse image file with browse botton. set height and width.......then click ok
That's the solution

This is funny solution.maybe you should have checked browser http code, if it says 404 , then its path problem.Again there many reasons for this path problem.Glad it got resolved.
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

shilpa deshmukh-kadam wrote:
There is palette tab where we got image control we have to just double click on it. then browse image file with browse botton. set height and width.......then click ok


Why don't you use your browser to see the path of the image file. This will help you learn how to add paths in a jsp/html file for later projects.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

There ain't no such thing as a "netbeans web application". There are only web applications that are created/maintained by NetBeans.

If NetBeans is such a critical part of your project that you cannot conceive of how to make things work without NetBeans, you are a cripple, using NetBeans as a crutch instead of its proper use as a toolbox. NetBeans isn't going to be available on the production server. More importantly, you're outsourcing essential JEE knowledge that should be in your head, not in the IDE, and from my experience that means that you're not going to know how to use the IDE effectively, much less handle problems that arise when the IDE is not working the way you want it to.

I know it's popular for management to expect to hire unskilled, untrained monkeys that they can pay minimal wages and expect the IDE to compensate for the shortcomings of the employees, but the results of that kind of approach are abominable. If it was really possible for software to do all the work, there wouldn't be any need for the coders at all, and so far that has never been the case - or even close to it.

The best way to avoid being one of those disposable untrained (and ultimately frustrated) "monkeys" is to learn the technology without being dependent on the IDE, no matter how good that IDE might be.


Customer surveys are for companies who didn't pay proper attention to begin with.
shilpa deshmukh-kadam
Ranch Hand

Joined: Jun 01, 2012
Posts: 38
Sumit Patil wrote:

Why don't you use your browser to see the path of the image file. This will help you learn how to add paths in a jsp/html file for later projects.

Definatelty ,
I will keep in mind your suggestions...I am a learner and I want to learn deeply ..


Thank you for giving me valuable suggestions ....with our above whole discussion I learn much new things about java and IDE.
In future I will need your help...Thank you
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

You are most welcome
 
Consider Paul's rocket mass heater.
 
subject: Images are not shown in netbeans web application on jsp page