Not able to access image on jsp file - eclipse

Attaches is the image of my project hierarchy. I am trying to call image from images directory to the jsp file in jsp directory but I am getting blank screen.
So far I have tried :
/WEB-INF/images/'<'imageFileName'>'
/images/'<'imageFileName'>'
/'<'imageFileName'>'
src/main/webapp/WEB-INF/images/'<'imageFileName'>'
Please help me on this.

You can't access any resources that are under WEB-INF folder, it serves just that purpose, to hold the resources that are not directly visible for the public but available to the classloader (servlets) of your web app.
You should make a mapping by the means of mvc:resources element, you should checkout the docs
for your particular case a mapping like
<mvc:resources mapping="/images/**" location="/WEB-INF/images"/>
should work out, and you'll be able to browse your images via request such as
/images/'<'imageFileName'>'

You can place your images and jsp folder under the web-app folder rather than WEB-INF folder. Then you can access the images using:
/images/'<'imageFileName'>'

The JSPs cannot access files inside WEB-INF folder directly, since it's not publicly available. But you can access it indirectly through a Servlet which will return the Image's stream object.
The sample code to access files in WEB-INF folder is in the below link. Have a look.
http://simple.souther.us/ar01s10.html

Related

Assets in public folder not loading when browsing CRUD pages of a class in Sinatra

I am using Bootstrap for some basic styling to a CRUD app in Sinatra. While the assets in the public folder load as usual on all pages, they don't load when I am browsing a particular record in my database.
For example, http://localhost:4567/songs loads all stylesheets and assets, but not http://localhost:4567/songs/1.
In my console, the page seems to be trying to find the css file in /songs folder, which I am not sure why its doing that.
http://localhost:4567/songs/bootstrap.css
Any help or pointers would be appreciated.
My main.rb file: http://pastie.org/8543319
My song.rb class file: http://pastie.org/8543312
Provide absolute path for assets in your views.

Access zk internationalization labels in another eclipse project

I have multiple projects in my eclipse workspace and would like to share the i3-labels files for internationalization between them. How do I move the internationalization labels into a folder (commonProject) in another project, and get to see them?
Right now in zk.xml I have:
<system-config>
<label-location>/commonProject/labels/i3-label_es_MX.properties</label-location>
<label-location>/commonProject/labels/i3-label_fr_FR.properties</label-location>
<label-location>/commonProject/labels/i3-label.properties</label-location>
</system-config>
But I can't access the labels. (I get a null pointer)
Thanks!
Your current path is a relative servlet path, but the servlet
does not load your labels, cos they arn't deployed.
You could add a system path, load the labels from a DB or URL,
as discribed in the ZK-Doc.
So it could look like
<system-config>
<label-location>file:///path/to/my/projects/commonProject/labels/i3-label_es_MX.properties</label-location>
<label-location>file:///path/to/my/projects/commonProject/labels/i3-label_fr_FR.properties</label-location>
<label-location>file:///path/to/my/projects/commonProject/labels/i3-label.properties</label-location>
</system-config>

Where do I put picture in my ASP.Net MVC2 application?

Where do I place images within my solution?
I usually create Images folder inside Content folder. Most 3rd party components that use .css files search images subdirectory for their images by default.
You could put them in the Content folder, along with your .css files. Or you could create a brand new folder and organize it any way you like.
In the content folder.
We have a separate resources domain that serves up all static content (recommended). In the solution, I just have a 'resources' folder that mimics the structure of the production folder. Easier to deploy using a script. You can create a separate site or vdir on your local web server and map it to this static folder. The location could then be refernced in your project via an app setting (configuration.resourcedomain + "/resources/images/xyz.jpg")

Netbeans creating a dist jar with all images etc included

I am trying to distribute a netbeans project however the jar it creates and the contents of the dist folder are dependant on some image files which i included into the project - however these images are not in the dist folder and I cannot workout how to make things work so I can export the project in a distributable format including all the things it needs.
Can somebody please tell me how I can export a project which runs within Netbeans without using the project's /dist folder which includes everything it needs?
Cheers
Andy
One way to achieve this is to add a folder (f.i."resources") in your project's src dir. Then copy the images to that dir. Now the images should get included when you build the project (if I remember correctly). Accessing the files can be accomplished with "getResourceAsStream"...
If whatever resources you are interested in are in the classpath, packaged in the jar, war, or the distribution, you can retrieve them by getting resources.
The convention is indeed to have a directory named 'src/resources' that serves as the root for this. Depending on the amount and scope of the resources you are using you may also want to add a sub-directory hierarchy to keep the organization and state of the resources manageable.
Also, not that a resource can be any file, an image, sound, text, xml, binary, etc. no limitation.
Finally, the call will look like this if you are using an object method:
getClass().getResourceAsStream("resources/myResource") - or - getClass().getResource("resources/myResource")
depends on if you want a stream or just the URI at that point in the code. Typically one would use the URI for delegating the processing of the resource elsewhere and the stream form when you are processing it in-line.
For a class method, you will need to do something more like:
new Object().getClass()...
The think to keep in mind here, is eventually this is resolving to the class loader and it is from that class path that the resource will be fetched.
You can add images the same way:
final Image image0 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("images/1.png"));

Where do I put static files for GWT app? war folder or public folder?

I have some JavaScript files, a main HTML file, a main CSS file, and some CSS files that get imported into the main one.
I understand that I can put static files in two places: a) the 'war' folder; or b) the 'public' folder.
Where is the best place to put my static files? Are the two locations treated differently? Is there a 'best practice' on this issue?
The difference between the 2 locations is that files in the public folders are copied by the gwt compiler to the 'your module' folder in the 'war' folder. This is means if you deploy the 'war' (for example via the google plugin to the google appengine) the files from the 'public' folder are not at the toplevel.
For example, if you have an index.html in the 'public' folder with gwt module named 'mymodule' and you deploy it to www.example.com it looks as follows, you need to access it via:
www.example.com/mymodule/index.html
If you have the index.html in the 'war' folder, you get:
www.example.com/index.html
Summarizing. Your landing page should be in the 'war' folder. Resource files used by the landing page can also be stored here (css, images). Any other resource file that is referred to in any gwt module file (or code, like images) should be stored in the 'public' folder related to the gwt module.
The new way of working in GWT is to use the war folder.
But, if you project is a reusable widget library which is used in a GWT application then you should put the resources in the public folder. The compiler will make sure that the files are automatically included in the generated package.
As I see it, it depends on your requirements, but let's start at a speaking example first ...
I find the documentation (should be GWT 2.6.0) about this to be incorrect or at least incomplete/confusing. As I see it (I am not a guru so please correct me if my investigations are wrong!) I am looking at the following example proj structure
myproj/
src/my/gwtproj/
client/
img/
foo1.png
AppClientBundle.java
foo2.png
public/
img/
foo3.png
foo4.png
war/
img/foo5.png
foo6.png
.classpath
.project
Imagine we may (or may not) need to reference such resources in some AppClientBundle interface (or other application reference context):
interfaces AppClientBundle extends ClientBundle {
#Source("img/foo1.png")
ImageResource fooImg();
}
Then it seems to depend on your Requirements, e.g.:
R.a) these resources (like images) are refered to in the application code, e.g. in our AppClientBundle interface via #Source annotations
R.b) these resources are to be grouped by folders, e.g. foo2.png vs. img/foo1.png
R.c) these resources should be available outside some specific application URL context path, e.g. if used as widget library, e.g. http://host1/gwtapp1/foo4.png vs. http://host1/gwtapp2/foo4.png
R.d) these resources need to be application-independently (e.g. externally) URL-referenced, e.g. http://host1/gwtapp1/foo4.png vs. http://host1/foo6.png
Here's what one can do (Possibilities) and it's implications regarding R.* above:
P.1) (generally recommended as I see it) put nicely folder-structured resources under my.gwtproj.client (here e.g. foo1.png)
this way #Source("img/foo1.png")... works fine
in the docs above they speek about some public folder (in my case my.gwtproj.public), but creating it as a package in Eclipse does not me allow this (since public is a reserved Java key word, but creating it via the Navigator view works)
however, this way the #Source above does not work (likely because it's an issue with the relative AppClientBundle file system location)
nevertheless if the resource should be publicly available under the application context one may have to do it via this public folder
P.2) put "ungrouped" resources directly under myproj/war, e.g. projdir/war/foo6.png
this way it can be used/found within annotations, e.g. #Source
and it can be referenced outside the application itself via e.g. http://host1/foo6.png
P.3) put folder-structured resources under myproj/war, e.g. projdir/war/img/foo5.png
in contrast to P.2) #Source("img/foo5.png") would not work anymore