我正在使用 Grails 2.4.2。我将图像保存到 web-app 文件夹下名为 gameImage 的目录中。它在开发模式下完美运行。但是当我在 xampp 服务器的本地主机上运行 war 时, View 中的图像没有显示,而是保存在目录中。以下是我的尝试::
在我的配置文件中>>>
gameImage.location = "web-app/apps/gameImage/"
在我的 Controller 中保存图像>>>
String fileName = grailsApplication.config.gameImage.location.toString() + distGameInstance.packageName + '_' + newGameImage.getOriginalFilename()
new File( grailsApplication.config.gameImage.location.toString() ).mkdirs()
newGameImage.transferTo( new File( fileName) )
在我想显示图片的地方>>>
<g:each in="${distributedGameListInstance}" status="i" var="androidDistGameInstance">
<div class="col-lg-3 col-md-4 col-xs-6 thumb" >
<a class="thumbnail" href="#">
<g:img uri="${resource(dir: "apps/gameImage", file: "${androidDistGameInstance.imageName}")}" style="height: 120px;width: 120px;" />
</a>
</div>
</g:each>
最佳答案
不需要在config.groovy 中配置文件夹。只需按照下面的代码。至少对我有用::
def gameImage = request.getFile('appImage')
String imagePath = "${request.getRealPath('/')}/apps/gameImage/"
new File( imagePath ).mkdirs()
gameImage.transferTo( new File( imagePath + File.separatorChar + gameImageName) )
关于tomcat - Grails 网络应用程序图像目录在 war 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30409524/