JSTL URL标记在Heroku上不起作用 [英] JSTL URL tag doesn't work on Heroku

查看:240
本文介绍了JSTL URL标记在Heroku上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,我部署在本地(在Tomcat中),以及在Google App Engine和Heroku上。

该应用程序使用JSTL标签,除了URL标记(< c:url value =/ someUrl/> ),它们在所有部署中都可以正常工作,只有在Heroku中,一个额外的正斜杠将所有东西都拧紧。以下是我的意思:

 < c:url value ='/ laundryLists / search.htm'/> 

在我的本地Tomcat中,应用程序部署在testApp上下文代码中将在页面中创建以下字符串:

/ testApp / laundryLists / search.htm



其中是正确的。



在我的GAE部署的应用程序中,位于testApp.appspot.com地址处,上面的代码片段生成:



/ laundryLists / search.htm

这是正确的,因为这里的应用上下文是/(根)



在部署在testApp.herokuapp.com的我的Heroku版本中



完全相同的代码生成:



// laundryLists / search.htm(在开头注意两个正斜杠)

这是错误的,因为if放置在链接中,例如

 < a href =< c:url value ='/ laundryLists / search。 HTM'/>中>凡是< / A> 

链接网址为:

  http://laundryLists/search.htm 



值得一提的是,其他JSTL标签(例如forEach)在Heroku中运行良好。



所以我的问题是,为什么在Heroku上发生这种情况,我该如何修复它(除了硬编码URLS)呢?

解决方案

将WAR文件部署到Heroku 时,WAR文件将以 Webapp Runner ,它只是Tomcat的一个简单包装器,允许它从命令行轻松运行。在当前部署的Webapp Runner版本中,默认的上下文路径是 / ,这是额外的斜杠来自的地方。要设置其他路径(包括空字符串),可以使用 - 路径参数。要使用WAR部署为Heroku应用程序设置此功能,可以在 WEBAPP_RUNNER_OPTS config var中将其设置为像thisr:

  heroku config:add WEBAPP_RUNNER_OPTS = -  path''


I have a Simple application which I've deployed locally (in a Tomcat), as well as on Google App Engine and Heroku.

The app uses JSTL tags, and they all work fine in all deployments, except the URL tag (<c:url value="/someUrl"/>) which, only on Heroku, prepends an extra forward slash which screws everything up. Here's what I mean:

<c:url value='/laundryLists/search.htm'/>

In my local Tomcat, where the app is deployed with a context of "testApp" the above code snipped will genreate the following string in the page:

"/testApp/laundryLists/search.htm"

which is correct.

In my GAE deployed app, which sits at address testApp.appspot.com, the above code snippet generates:

"/laundryLists/search.htm"

which is correct, because here the app context is "/" (root)

In my Heroku version, which is deployed at "testApp.herokuapp.com"

The exact same code generates:

"//laundryLists/search.htm" (notice two forward slashes at the beginning)

which is wrong, because if placed in a link, such as

<a href="<c:url value='/laundryLists/search.htm'/>">whatever</a>

the link URL will be:

http://laundryLists/search.htm

which is obviously wrong.

It's worth mentioning that other JSTL tags (such as "forEach") work fine in Heroku.

So my question is, why is this happening on Heroku, and how can I fix it (other than hardcoding the URLS)?

解决方案

When deploying WAR files to Heroku, the WAR file is launched with Webapp Runner, which is just a thin wrapper around Tomcat to allow it to be run easily from the command line. In the currently deployed version of Webapp Runner, the default context path is /, which is where the extra slash is coming from. To set the path to something else (including empty string), you can use the --path parameter. To set this for a Heroku app using WAR deployment, you can set it in the WEBAPP_RUNNER_OPTS config var like thisr:

heroku config:add WEBAPP_RUNNER_OPTS="--path ''"

这篇关于JSTL URL标记在Heroku上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆