Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/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
Image 显示404错误的URL图像路径_Image_Jsp_Spring Mvc_Http Status Code 404 - Fatal编程技术网

Image 显示404错误的URL图像路径

Image 显示404错误的URL图像路径,image,jsp,spring-mvc,http-status-code-404,Image,Jsp,Spring Mvc,Http Status Code 404,我试图用下面的代码在img标签中显示图像,但在浏览器控制台上显示404文件未找到错误 Jsp页面: <img id="img" src="logo.jsp?path=${schoolModel.user_name}" style="width:105px; height:120px;"/> <%@page import="com.slv.CommonUtils.WebSLCMConstants"%> <%@page import="java.io.Buffered

我试图用下面的代码在img标签中显示图像,但在浏览器控制台上显示404文件未找到错误

Jsp页面:

<img id="img" src="logo.jsp?path=${schoolModel.user_name}" style="width:105px; height:120px;"/>
<%@page import="com.slv.CommonUtils.WebSLCMConstants"%>
<%@page import="java.io.BufferedOutputStream"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@page import="java.io.InputStream"%>
<%
File f=null;
try {
    System.out.println("Inside");
    String path=request.getParameter("path");       
        if(path.equals("")){
            f=new File(WebSLCMConstants.img_retrieve_path+"WebSLCM/no_image.jpg");
        } else {
            f=new File(WebSLCMConstants.img_retrieve_path+path);
        }
        String str=f.toString();
        response.setContentType("image/jpg");
        ServletOutputStream sos;
        FileInputStream fin = new FileInputStream(str);
        BufferedInputStream bin = new BufferedInputStream(fin);
        sos = response.getOutputStream();
        BufferedOutputStream bout = new BufferedOutputStream(sos);

        int ch =0;
        while((ch=bin.read())!=-1)
        {
            bout.write(ch);
        }
        bin.close();
        fin.close();
        bout.close();
        if (true) return;
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
%>
@RequestMapping(value = "/image.do", method = RequestMethod.GET)
    public ResponseEntity getImage(String path, HttpServletResponse response) {
        try {
            if (StringUtils.isEmpty(path)) {
                return new ResponseEntity(HttpStatus.NOT_FOUND);
            } else {
                response.setHeader("Content-Type", "image/jpg");
                FileInputStream fin = new FileInputStream(path);
                ServletOutputStream out = response.getOutputStream();

                IOUtils.copy(fin, out);
                IOUtils.closeQuietly(fin);

                response.flushBuffer();
                return new ResponseEntity(HttpStatus.OK);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

logo.jsp:

<img id="img" src="logo.jsp?path=${schoolModel.user_name}" style="width:105px; height:120px;"/>
<%@page import="com.slv.CommonUtils.WebSLCMConstants"%>
<%@page import="java.io.BufferedOutputStream"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@page import="java.io.InputStream"%>
<%
File f=null;
try {
    System.out.println("Inside");
    String path=request.getParameter("path");       
        if(path.equals("")){
            f=new File(WebSLCMConstants.img_retrieve_path+"WebSLCM/no_image.jpg");
        } else {
            f=new File(WebSLCMConstants.img_retrieve_path+path);
        }
        String str=f.toString();
        response.setContentType("image/jpg");
        ServletOutputStream sos;
        FileInputStream fin = new FileInputStream(str);
        BufferedInputStream bin = new BufferedInputStream(fin);
        sos = response.getOutputStream();
        BufferedOutputStream bout = new BufferedOutputStream(sos);

        int ch =0;
        while((ch=bin.read())!=-1)
        {
            bout.write(ch);
        }
        bin.close();
        fin.close();
        bout.close();
        if (true) return;
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
%>
@RequestMapping(value = "/image.do", method = RequestMethod.GET)
    public ResponseEntity getImage(String path, HttpServletResponse response) {
        try {
            if (StringUtils.isEmpty(path)) {
                return new ResponseEntity(HttpStatus.NOT_FOUND);
            } else {
                response.setHeader("Content-Type", "image/jpg");
                FileInputStream fin = new FileInputStream(path);
                ServletOutputStream out = response.getOutputStream();

                IOUtils.copy(fin, out);
                IOUtils.closeQuietly(fin);

                response.flushBuffer();
                return new ResponseEntity(HttpStatus.OK);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

在GUI浏览器控制台显示404未找到文件错误,如下所示:


]JSP页面:

<img id="img" src="image.do?path=yourPath" style="width:105px; height:120px;"/>

WebSLCMConstants.img\u retrieve\u path
的值是多少?我在logo.jsp中打印sop,它没有打印,,,在src=“logo.jsp?path=${schoolModel.user\u name}中给出错误