tomcat - Grails 网络应用程序图像目录在 war 中无法正常工作

标签 tomcat grails debian grails-2.0

我正在使用 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/

相关文章:

xml - JSF 2.1 + Tomcat 8 - 部署错误

grails - Grails-带有关联域类的自定义排序

Symfony2 Composer 安装

c++ - undefined symbol 引用,命令行中缺少 DSO

python - 当我尝试列出 FTP 服务器时得到 "ConnectionRefusedError"

java - 部署War文件到Tomcat有什么好处?

java - jsf 的依赖项(如 servlet)阻止应用程序启动

java - 来自 Java 客户端的 SSL 连接

events - Hook Grails 事件以便在不使用插件的情况下注入(inject)属性和方法

unit-testing - Groovy,如何模拟接口(interface)保持其他方法