Skip to main content

Path to custom default error page resources

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
10 replies [Last post]
tmpsa
Offline
Joined: 2010-02-01

I have successfully made a custom default error page for 404 by adding my own html file to <domain>/config/my-errorpage.html , and added a property named 'send-error_1' with the vaule 'code=404 path=my-errorpage.html' in the admin console under Configurations > Server-config > Virtual servers > server .

This works.

But my-errorpage.html contains <img src="somepath/my-image.png"/> (and also CSS background URL specs), and I can't figure out how I should specify the path, or where I should put the image files. [pulling my hair]

Preferably, I would like to keep the image files with the html file.

Is this possible? How?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
amyroh
Offline
Joined: 2004-05-06

I would put the custom default error page and image files in the docroot
directory (domains/domain1/docroot & domains/domain1/docroot/images) and
define the send-error_1 property with a value
"path=${com.sun.aas.instanceRoot}/docroot/404.html code=404".

From your error page, you can refer to your images files

hth,
Amy

On 1/18/12 7:01 AM, forums@java.net wrote:
> I have successfully made a custom default error page for 404 by adding
> my own
> html file to /config/my-errorpage.html , and added a property
> named
> 'send-error_1' with the vaule 'code=404 path=my-errorpage.html' in the
> admin console under Configurations > Server-config > Virtual servers >
> server
> .
>
> This works.
>
> But my-errorpage.html contains (and
> also
> CSS background URL specs), and I can't figure out how I should specify
> the
> path, or where I should put the image files. [pulling my hair]
>
> Preferably, I would like to keep the image files with the html file.
>
> Is this possible? How?
>
>
>
>
> --
>
> [Message sent by forum member 'tmpsa']
>
> View Post: http://forums.java.net/node/882803
>
>

tmpsa
Offline
Joined: 2010-02-01

I just tried your recipe exactly, but now I don't even get the HTML page. (My guess is that the ${...} stuff isn't honored). Have you tried to do this yourself?

amyroh wrote:
I would put the custom default error page and image files in the docroot directory (domains/domain1/docroot & domains/domain1/docroot/images) and define the send-error_1 property with a value "path=${com.sun.aas.instanceRoot}/docroot/404.html code=404". From your error page, you can refer to your images files

amyroh
Offline
Joined: 2004-05-06

On 1/19/12 2:22 AM, forums@java.net wrote:
> I just tried your recipe exactly, but now I don't even get the HTML
> page. (My
> guess is that the ${...} stuff isn't honored). Have you tried to do this
> yourself?

Which GF are you using? Can you access the HTML page via
http://localhost:8080/my-errorpage.html? I've attached my working
domain.xml for reference.

>
>

amyroh wrote:
I would put the custom default error page and image
> files in
> the docroot directory (domains/domain1/docroot &
> domains/domain1/docroot/images) and define the send-error_1 property
> with a
> value "path=${com.sun.aas.instanceRoot}/docroot/404.html code=404".
> From your
> error page, you can refer to your images files

>
>
>
>
> --
>
> [Message sent by forum member 'tmpsa']
>
> View Post: http://forums.java.net/node/882803
>
>

tmpsa
Offline
Joined: 2010-02-01

Oh, sure, I can access files in the docroot catalog via http://localhost:8080/my-errorpage.html . (And images are loaded, too). But http://localhost:8080/my-failed-webapp gives the vanilla Glassfish 404 page, not my-errorpage.html.

I run GF 3.1.1 .

amyroh
Offline
Joined: 2004-05-06

I verified that it is working fine in 3.1.1 and we have a unit test for
the feature as well. Check if you have the send-error property
correctly and send me your domain.xml if it's still not working.

Amy

On 1/20/12 12:48 AM, forums@java.net wrote:
> Oh, sure, I can access files in the docroot catalog via
> http://localhost:8080/my-errorpage.html . (And images are loaded,
> too). But
> http://localhost:8080/my-failed-webapp gives the vanilla Glassfish 404
> page,
> not my-errorpage.html.
>
> I run GF 3.1.1 .
>
>
>
>
> --
>
> [Message sent by forum member 'tmpsa']
>
> View Post: http://forums.java.net/node/882803
>
>

amyroh
Offline
Joined: 2004-05-06

Can you send me your domain.xml?

On 1/20/12 12:48 AM, forums@java.net wrote:
> Oh, sure, I can access files in the docroot catalog via
> http://localhost:8080/my-errorpage.html . (And images are loaded,
> too). But
> http://localhost:8080/my-failed-webapp gives the vanilla Glassfish 404
> page,
> not my-errorpage.html.
>
> I run GF 3.1.1 .
>
>
>
>
> --
>
> [Message sent by forum member 'tmpsa']
>
> View Post: http://forums.java.net/node/882803
>
>

tmpsa
Offline
Joined: 2010-02-01

I have checked and double-checked the send-error_1 property in the admin console. Looks good. (btw, my custom default error page is currently docroot/404.html).

I have attached my domain.xml. (I had to zip it since this forum does not allow .xml files to be attached. Weird.).

It appears that we are adressing TWO different problems now:

1. My original problem (how to load image files from a custom default error page).

2. Why is not ${com.sun.aas.instanceRoot} working with send_error_1 on my box.

Note: I *can* get my custom default error page to work (without ${com.sun.aas.instanceRoot}) by putting in in the config dir, which is the default dir according to the manual, or by specifying e.g. ../docroot/404.html .

tmpsa
Offline
Joined: 2010-02-01

After some experimentation, I have come to the conclusion that it IS possible - but not trivial - to implement user-defined error pages with images in Glassfish. It is clear that ${com.sun.aas.instanceRoot} is NOT working when used in the property 'send-error_1'. Here is a configuration that works:

  • Put the files in <domain>/docroot (your own index.html, your own 404.html, my-picture.jpg, etc)
  • Define send-error_1 to code=404 path=../docroot/404.html
  • In your own error pages, you can include the images with <img src="../docroot/my-picture.jpg" ...>

HOWEVER!

If you configure your Glassfish to sit behind Apache (with mod_jk), then any invalid url (e.g. example.com/wrong) will result in *Apache's* 'Not found' page.

And now the REALLY BAD news:

If your webapp is not working (e.g. example.com/my-webapp) then the browser will receive your nice 404.html as 'text/plain', and show ITS SOURCE CODE instead of a nice web page.

Something's badly wrong. I smell a bug. What could it be?

amyroh
Offline
Joined: 2004-05-06

On 2/17/12 12:48 AM, forums@java.net wrote:
> After some experimentation, I have come to the conclusion that it IS
> possible
> - but not trivial - to implement user-defined error pages with images in
> Glassfish. It is clear that ${com.sun.aas.instanceRoot} is NOT working
> when
> used in the property 'send-error_1'. Here is a configuration that works:
This is very strange. ${com.sun.aas.instanceRoot} is working for
send-error_1 property for me. Are you using asadmin set command or
editing domain.xml? Have you tried restarting GF?
>
> * Put the files in /docroot (your own index.html, your own
> 404.html,
> my-picture.jpg, etc)
> * Define send-error_1 to code=404 path=../docroot/404.html
> * In your own error pages, you can include the images with src="../docroot/my-picture.jpg" ...>
>
> HOWEVER!
>
> If you configure your Glassfish to sit behind Apache (with mod_jk),
> then any
> invalid url (e.g. example.com/wrong) will result in *Apache's* 'Not
> found'
> page.
This is expected since /wrong isn't assigned as JkMount directive for
Apache. You need to define a custom error page in Apache since /wrong
will not get forwarded to GF.

>
> And now the REALLY BAD news:
>
> If your webapp is not working (e.g. example.com/my-webapp) then the
> browser
> will receive your nice 404.html as 'text/plain', and show ITS SOURCE CODE
> instead of a nice web page.
>
> Something's badly wrong. I smell a bug. What could it be?

Can you file an issue [1] and assign it to me (userid : amyroh)?

Thanks for reporting.
Amy

[1 ]http://java.net/jira

>
>
>
>
> --
>
> [Message sent by forum member 'tmpsa']
>
> View Post: http://forums.java.net/node/882803
>
>

tmpsa
Offline
Joined: 2010-02-01

Ok, issue filed: http://java.net/jira/browse/GLASSFISH-18412

(It got auto-assigned to someone else than you, and I don't have powers to chage it. But I guess that you can fix that).