JSF WebContent rendering methods not working when entering subdirectory - java

I have a web App running in liberty that utilizes jsf, made in eclipse. I am attempting to place my rendered pages (.xhtml files) in subdirectories in order to organize the URL paths.
Example:
http://1sy:9011/Batch/main.xhtml (Not actual Links. Just an Example)
To look like this: http://1sy:9011/Batch/subdirectory/main.xhtml (Example: Not a link)
where subdirectory is a folder within the webcontent directory. The problem with this is that if I use a bean method to call the page in the sub-directory, any method within that page that calls a page outside of this sub-directory will no longer worked when an input within a form is activated on that page within the sub-directory. How can I render pages outside of the sub-directory once I have called a page within it? I will place sample code with an explanation below.
public String viewGroups(){
return "subdirectory/viewgroups";
}
This method will render the .xhtml viewgroups, which is in the subdirectory(folder) "subdirectory" within the webcontent folder, but if I press a button on view groups that calls the following method:
public String editSelectedGroup(){
return "editgroup";
}
editgroup.xhtml will not be called. editgroup.xhtml is in the root of the webcontent directory, back outside of the subdirectory.

Related

Not able to access images within WEBContent/WEB-INF

My project hierarchy is like this.
ProjectName--> WebContent-->WEB-->INF-->ZUL-->XYZ-->images(Folder)+abc.zul
--> when I wants to access image within images folder in abc.zul(which is also inside XYZ fodler) images are not loaded.i am accessing images like this.
image="/images/app_icon.png"
I believe it should be WEB-INF instead of WEB->INF.
Any resource inside the WEB-INF can be accessed programmatically only.
You can put images folder out of the WEB-INF and under WebContent folder in order to access images as image="/images/app_icon.png".
Again it depends on your requirement and implementation.

How to make use of external JavaScript source file in JSP through simple java class

I am creating one project in which I am making call to a JavaScript function which resides in index.jsp from my java class ( .java file). As in this context we shouldnt write <script> tag in our index.jsp, what should I do if I want to make use of some dependent .js file like stomp.js source file in my index.jsp file??

Cannot Reach Html File on Google App Engine

I have an Eclipse Java project, and I added a "folder" off of the root called "webfiles". I then proceeded to create a file called form.html. Once I run the project locally or publish it, I cannot reach the .html file. I get a Not_Found error.
Is it possible in Google App Engine to use HTML files (other than index.html) and where do I have to place them in the project to access them by a browser? What path should I use in the browser.
You need to add include path="/**.html" " in your static files definition in appengine-web.xml else html files other than index.html would not even be uploaded.
If you have /war/webfiles/form.html in your project than path to acces it from browser:
http://your_app_name.appspot.com/webfiles/form.html
To make reference from other jsp pages use:
link to form

How to run applet in web application

I'm having the exact same problem stated in run applet in web application. It throws a ClassNotFoundException for my applet. I tried the solution from there but still no luck.
Here is my code for embedding Applet in html:
<body>
<applet codebase="/DaaS/applet" archive="/DaaS/applet/firstApplet.jar" code="FirstApplet.class" width="300" height ="300"> </applet>
I've a folder DaaS/applet which contains firstApplet.jar and my index.html is in Daas/Webcontent.
The URL in the codebase (and archive) attribute is relative to the current request URL (the one as you see in browser address bar), not to the disk file system in the server side. Imagine that you've the index.html page in some subfolder like so:
http://localhost:8080/somecontext/index.html
The URL as you have in the codebase (and archive) attribute starts with a leading slash / which makes it relative to the domain root instead of the current folder. So the webbrowser will look for the archive and the JAR in the following URL
http://localhost:8080/DaaS/applet/firstApplet.jar
This may not be correct per se. You need to make sure that the codebase (and archive) URL points to the right URL relative to the current request URL. Based on the information given so far, the /DaaS folder is basically in the same parent as index.html, so this should do:
<applet codebase="DaaS/applet" archive="firstApplet.jar" ... />
(note that I simplified the archive attribute, it will be resolved relative to codebase anyway)
This way the browser will load the JAR from:
http://localhost:8080/somecontext/DaaS/applet/firstApplet.jar

How to change location of static file in WAR archive?

By default static files are located in WEB-INF directory (accessible as /images/logo.png):
foo.war
WEB-INF
web.xml
images
logo.png
I want to change the structure and use this one instead (still accessible as /images/logo.png):
foo.war
WEB-INF
web.xml
static
images
logo.png
How can I do this with web.xml?
The container will repsond with a 404 NOT FOUND error if you directly access the files under WEB-INF using HTTP GET .
But now , you said you can access WEB-INF/images/logo.png by /images/logo.png , so I think your web application most probably achieve this result by some URLRewriteFilter mechainsim or by some Java code in the servlet level (eg a filter) , or by your web application 's framework . I suggest you to check your web application to see what mechanism causes this behvaior now and configurate to your desired result accordingly.
According to http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/WCC3.html,:
A WAR has a specific directory
structure. The top-level directory of
a WAR is the document root of the
application. The document root is
where JSP pages, client-side classes
and archives, and static Web resources
are stored.
The document root contains a
subdirectory called WEB-INF, which
contains the following files and
directories:
web.xml: The Web application
deployment descriptor Tag library
descriptor files (see Tag Library
Descriptors) classes: A directory
that contains server-side classes:
servlets, utility classes, and
JavaBeans components lib: A
directory that contains JAR archives
of libraries (tag libraries and any
utility libraries called by
server-side classes).
You can also create
application-specific subdirectories
(that is, package directories) in
either the document root or the
WEB-INF/classes directory.
So the default behavior is what you're looking for. Is your document root set incorrectly to serve content from WEB-INF?
You may use a filter or URLRewriteFilter to point /images/* to /static/images/*.
If you just want your folder structure to be /static/images for development time organization purposes, but the deployment URL to be /images -- you may need to alter your build script to copy /static/** to /.
I personally would not bother whether my static files are referred as /static/images or /images -- because they would be referred in my code (only), which I have control over.
If you are using these files in CSS and that's why you wanted the path to stay the same... better keep the images under /static/css/images and have the images that are referred in the CSS here. In this way, no matter where you move your CSS folder, you would not bother spoiling your CSS.

Categories

Resources