Web applications 使用图像元素中的绝对路径作为源

Web applications 使用图像元素中的绝对路径作为源,web-applications,tomcat6,image,absolute-path,Web Applications,Tomcat6,Image,Absolute Path,我的jsp页面中有一个简单的img元素,它必须将一个放置在webapp上下文外部的图像用作源 我是这样做的:从servlet生成并使用JSTL设置的路径 <img src="C:/somewhere/32x32/userXX.png" class="member-box-avatar"> ${foto}包含绝对路径C:\mypath\32x32\n我尝试过任何类型的斜杠组合使用 <img src="<%=request.getContextPath()%>/you

我的jsp页面中有一个简单的img元素,它必须将一个放置在webapp上下文外部的图像用作源

我是这样做的:从servlet生成并使用JSTL设置的路径

<img src="C:/somewhere/32x32/userXX.png" class="member-box-avatar">
${foto}包含绝对路径C:\mypath\32x32\n我尝试过任何类型的斜杠组合

使用

<img src="<%=request.getContextPath()%>/your/image/dir/image.png">
如果它托管在您的应用程序上下文中

否则使用

1.IFrame用于呈现其他图像的图像url


2.使用Ajax/jQuery异步渲染图像

我为此苦苦挣扎了几个小时。 我用这个把戏成功了

<a href="edit?action=showImageFull&url=C:/Users/Noir/Desktop/WorkSpaceEclipseNeu/w_mvc_3/WebContent/imgfolder/${imgageimage.time}.jpg" target="_parent">
<img  src="http://localhost:8080/w_mvc_3/edit?action=showImageFull&url=C:/Users/Noir/Desktop/WorkSpaceEclipseNeu/w_mvc_3/WebContent/imgfolder/${imgageimage.time}-thumb.jpg"width="150" height="100">
这用于显示缩略图和完整图像。
我希望有帮助。

我得到的是http://myhost/MyWebApp/C:/mypath/32x32/userXX.png...so 似乎仍在webapp上下文中。您是否可以共享正在使用的代码,至少是与问题相关的重要部分,这有助于您无法通过web共享文件的物理路径。我建议您将图像移动到一个路径,该路径将驻留在您的web应用程序中,然后是user request.getContextPath,建议您指出该路径。问题是,我无法移动这些文件,因为它们是从其他服务昂贵地更新的……我正在阅读有关使用server.xml中的上下文标记定义外部文件的内容可从webapp访问上下文…对此有何建议?当我在apache上的时候,我用别名做了一个小把戏……有类似的东西吗?通过在server.xml文件中放置上下文来解决
<a href="edit?action=showImageFull&url=C:/Users/Noir/Desktop/WorkSpaceEclipseNeu/w_mvc_3/WebContent/imgfolder/${imgageimage.time}.jpg" target="_parent">
<img  src="http://localhost:8080/w_mvc_3/edit?action=showImageFull&url=C:/Users/Noir/Desktop/WorkSpaceEclipseNeu/w_mvc_3/WebContent/imgfolder/${imgageimage.time}-thumb.jpg"width="150" height="100">
    if(action.equals("showImageFull")) {            
        try {
             String url = request.getParameter("url");

                response.setContentType("image/jpeg");  
                ServletOutputStream out;  
                out = response.getOutputStream();  
                FileInputStream fin = new FileInputStream(url);  

                BufferedInputStream bin = new BufferedInputStream(fin);  
                BufferedOutputStream bout = new BufferedOutputStream(out);  
                int ch =0; ;  
                while((ch=bin.read())!=-1)  
                {  
                bout.write(ch);  
                }  

                bin.close();  
                fin.close();  
                bout.close();  
                out.close();  

        } catch (BookNotFoundException e) {
            RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/jsp/error.jsp");
            dispatcher.forward(request, response);
        }               
    }