Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jsp中单独获取图像_Jsp_Src - Fatal编程技术网

在jsp中单独获取图像

在jsp中单独获取图像,jsp,src,Jsp,Src,我试图在jsp页面中显示图像和其他内容,但是我一直在单独获取图像。我不知道为什么 以下是我的servlet中的代码: if(profile.getAvatar()!=null){ ServletContext sc = getServletContext(); String filename= sc.getRealPath("img/no_avatar.png"); String contentType = sc.getMimeType(filename

我试图在jsp页面中显示图像和其他内容,但是我一直在单独获取图像。我不知道为什么 以下是我的servlet中的代码:

if(profile.getAvatar()!=null){
       ServletContext sc = getServletContext();
       String filename= sc.getRealPath("img/no_avatar.png");
       String contentType = sc.getMimeType(filename);

        response.setContentType(contentType);

        File file = new File(filename);
        response.setContentLength((int)file.length());

        FileInputStream in = new FileInputStream(file);
        OutputStream out = response.getOutputStream();
        request.setAttribute("in", in);

        byte[] buffer =new byte[1024];

        int count;
        while((count = in.read(buffer)) >= 0)
        {
            out.write(buffer,0,count);
        }
        out.flush();
        }
以下是我的jsp:

<input type="image" name="avatar" id="avatar"src="img/no_avatar.png" />

请帮助我,希望尽快收到你们的回复


提前感谢(:

在格式化有问题的代码时,我发现JSP部分丢失了
嘿,谢谢harry,但是它仍然不工作