Grails: displaying created image in gsp

前端 未结 8 2004
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 10:07

I\'m very new to Grails so there\'s probably a very simple answer to this question. I\'m trying to display a dynamically created image in a gsp. The image is NOT stored in

8条回答
  •  执念已碎
    2020-11-29 10:46

    The following code works in Grails 2.x.

    HomeController.groovy

    class HomeController {
    
        def index() {
        }
    
    
        def viewImage(){
            def file = new File(params.title)
            def img = file.bytes
            response.contentType = 'image/png' // or the appropriate image content type
            response.outputStream << img
            response.outputStream.flush()
        }
    }
    

    views/home/index.jsp

    <%@ page contentType="text/html;charset=ISO-8859-1" %>
    
    
        
        
        View Image
    
    
      
    "/>

提交回复
热议问题