Image on local disk is not loading in Tomcat project configuration

0

I am working on a project using HTML5 and JavaScript. I am loading an image from the C: drive like this:

window.onload = function() {
    var canvas = document.getElementById("myCanvas");
    var context = canvas.getContext("2d");
    var imageObj = new Image();

    imageObj.onload = function() {
      context.drawImage(imageObj, 69, 50);
    };
    imageObj.src = "file:///C:/Images/Demo.jpg";
  };

The image is loading perfectly on this page. When try the same thing in my project, the image won't load in a canvas element. I am getting the following error from the browser:

Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE)[nsIDOMCanvasRenderingContext2D.drawImage]

How can this problem be solved?

javascript
html
tomcat
canvas
asked on Stack Overflow Jul 26, 2012 by Shanky • edited Jul 26, 2012 by Rusty Fausak

1 Answer

1

On Project its not advisable to use direct path you should use a related path as per your server directory as '<%=request.getContextPath()%>'/Remaing_path_from_webContent_folder_of_project

Hope it will work

answered on Stack Overflow Jul 26, 2012 by Kamal Pundir

User contributions licensed under CC BY-SA 3.0