I have an error.html page which I want to redirect to when a user comes accross Error404 for example. The below is working:
<error-page>
<error-code>404</error-code>
<location>/error404.jsp</location>
</error-page>
However, my error404.jsp file contains an image which doesn't get displayed when user is redirected. If I just type in the URL, the full page with image is displayed. But if a user tries to do something which reports error 404, the error404.jsp file gets displayed without the image.
I also tried with having an error404.html but I get the same problem...
Do you have any ideas why this is happening?
Many thanks
Ena
When the error page is rendered, its content is returned in the HTTP response without a redirect. This means that the browser still 'sees' it in context of the URL of the request that had an error. So any relative resource links (images, css, etc.) will be relative to the current page's URL.
So if you have the following setup:
image1.gif in images folder
error404.jsp that references the image as "../images/image1.gif"
You will find that typing http://yourserver.com/YourContextRoot/error404.jsp works fine, but when you use http://yourserver.com/YourContextRoot/path1/path2/missingPage it tries to look for the image in the wrong path (i.e. under /YourContextRoot/path1/images/image1.gif).
The solution is to use JSP EL or scriptlet to create a server-relative link (i.e. starts with a '/'), by including context-root:
<img src="${pageContext.request.contextPath}/images/image1.gif" />
I hope that works!
Related
I've been having this problem for some days now and spend 2 hours debugging a simple meta tag without result.
The problem I'm facing is that the facebook debugger provides me with a whole different url from cloudfront and sets wrong meta image.
The url
The Image it should show
I also made a thread on facebook.com: https://developers.facebook.com/bugs/807177749469671/
The object debugger from Facebook for your given URL mentions that some redirects are occurring on the page, it's also mentioning when these redirections occur. It can either be an HTTP direction, meta-tag with og:url property or a link tag. Your page does contain one of these tags, on line 91 to be specific;
<link rel="dns-prefetch" href="//yummygum.com">
This redirection is why Facebook is trying to load an image with the name "meta-img.png" since this is the og:image the homepage is referring to. Try to remove that link redirection and see if it's loading the right image.
I am using SpringMVC to make a simple web app.
My controller request mapping is like this:
#RequestMapping(value = "index.html")
public String index(Model model) {
model.addAttribute("type", "index");
return "index";
}
When I use visit the following URL:
http://localhost:8012/MyCloud/index.html
Things work fine and I can see the properly rendered /views/index.jsp.
But if I directly visit the views/index.jsp file with the following URL, the URL is indeed visitable. And an ugly 500 server error because apparently, there's no attribute named "type" been set so NullReferenceException is thrown.
http://localhost:8012/MyCloud/views/index.jsp
By mapping request to *.html URL, I want to trick my customer into believing they are visiting plain HTML page. But if they somehow managed to know my JSP view locations and visit them directly, they will see ugly errors.
Can I prevent this?
Shall I use an error page?
Servlet containers won't serve any content in WEB-INF. By putting your JSPs there, you prevent anyone from directly accessing a JSP by navigating to it in the browser by name.
so move all your JSPs to the WEB-INF folder, and user will not be able to directly access the urls, while the controller code will be able to render the UI properly with them.
You can cofigure a error page in web.xml
<error-page>
<location>/general-error.html</location>
</error-page>
Should the welcome file mentioned in welcome file list tag always be physically present?
i.e. jsp, html etc. Or can it be a URL pattern?
I defined a welcome file list in the web.xml as:
<welcome-file-list>
<welcome-file>/home</welcome-file>
</welcome-file-list>
/home downloads a JSON file from the server to display on the browser. But whenever I start the application, it does not take me to the following page: http://localhost:8080/myapp/home. Instead it always goes to http://localhost:8080/myapp/ only. Please advise what am I doing wrong.
it does need to have a physical file on your webapp folder for a welcome file to be found even if some kind of controller will treat the request, for example, if you have a JSF app and the FacesServlet only handles requests of type *.faces on your app you should place an empty file called home.faces under your webapp folder, so it can be correctly mapped, on your case I guess the issue is slightly different, you want to fetch data from the server side and display it on the browser when user first lands on your app, so what you can do is actually:
Create an HTML called home.html as your welcome file with an empty div as a placeholder for your data.
Use a Javascript library or do an AJAX call to fetch the JSON from the server side
If the result call is OK, render the placeholder DIV with data fetched from server.
I'm running Meteor 0.6.6.1, using the package Router and all my images are in the public folder.
My issue is: when I'm in the URL root (http://localhost:3000), after the template is rendered, I am able to load an image, as illustrated using the console in the image below:
But when I'm in another URL (http://localhost:3000/orderProduct/frame1) using the Router to drive the right template, I can't load the same image after the template is rendered, as shown in the image below:
As we can see from the console's output, the only difference is the well known Chrome's warning about the content type.
I would like to load the images in a routed URL after the template is rendered. Someone can help me, please?
Thanks in advance.
You use relative URLs for images, the ones that does not start with /. In this case, browser search for the image RELATIVE to the current document path. So in the second case, it search in the orderProduct folder, which does not exist - and hence the error. See what's the image URL the browser tries to fetch, it's different in the two examples.
To solve your problem use absolute path, the one starting with /:
$('body').append('<img src="/imageName.png">');
In this case, the browser will look for the photo in the given path on the current server, and it will find it regardless on what's the current page address.
When i use the object debugger, the scraper is not able to see my OG content on my page. The debugger says "Can't download: Could not retrieve data from URL.", even though it's a 200 OK and shows the correct fetched and canonical URL. I have a subdomain on it, and it work fine.So not sure what happen to my main domain.
When click on Scraped URL See exactly what our scraper sees for your URL , it just show blank page.
Your site seems to have some HTML errors: http://validator.w3.org/check?uri=http%3A%2F%2Fspandooly.de
You should fix them before attempting to validate your site.
Funny thing, I create a copy of your page, and it seems to validate with no changes in the HTML. Your webserver might be doing something weird (according to the headers, the charset is missing or none):
http://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.webniraj.com%2Fspandooly.html