为什么我的 JSP 更改在不重新启动 Tomcat 的情况下不会反映出来?
我正在编辑直接位于 tomcat/webapps/myapp/WEB-INF 内的 JSP 文件,但要查看更改,我必须重新启动服务器。据我所知,JSP 更改不需要您重新启动服务器。我发现的与自动重新加载相关的唯一配置是 reloadable = "true"
如果您希望 Catalina 这样做,则设置为 true 监控 /WEB-INF/classes/ 中的类 和 /WEB-INF/lib 进行更改,以及 自动重新加载网页 如果检测到更改,则应用程序。
我在 context.xml
中使用了此属性,但问题仍然存在。在不重新启动的情况下无法检测到 JSP 文件中的更改的其他可能原因是什么?
@Bozho: 这是 web.xml
的摘录。我需要改变什么吗?
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
I am editing JSP files which are residing directly inside tomcat/webapps/myapp/WEB-INF
, but to see the changes, I have to restart the server. As far as I know, JSP changes don't require you to restart the server. The only configuration I found which is related to automatic reloading is reloadable = "true"
Set to true if you want Catalina to
monitor classes in /WEB-INF/classes/
and /WEB-INF/lib for changes, and
automatically reload the web
application if a change is detected.
I used this attribute in the context.xml
, but still the problem persists. What could be the other possible reason of not detecting changes in JSP files without restarting?
@Bozho:
This is the excerpt from web.xml
. Do I need to change something?
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
在 tomcat 文档中,请参阅
开发 设置。必须将其设置为 true 才能重新加载 jsps。
这是在你的
CATALINA_HOME/conf/web.xml
中此外,如果你需要在生产环境中刷新jsp而不重新启动,你可以转到
CATALINA_HOME/work/Catalina/localhost/contentName /org/apache/jsp
并删除your_jsp.java
和your_jsp.class
文件。它们将在下次访问时重新创建。编辑:在提供您的配置并评论不刷新内容后,我还有另一个:清除浏览器缓存,或从另一个浏览器打开页面。
In the tomcat docs, see the
development
setting. It must be set to true in order to have jsps reloaded.This is in your
CATALINA_HOME/conf/web.xml
Additionally, if you need to refresh a jsp in a production environment without restart, you can go to
CATALINA_HOME/work/Catalina/localhost/contentName/org/apache/jsp
and delete theyour_jsp.java
andyour_jsp.class
files. They will be recreated the next time they are accessed.Edit: after providing your configuration, and comment about not refreshing the content, I have another though: clear your browser cache, or open the page from another browser.
更晚的答案...
在上下文文件中将“antiResourceLocking”设置为“true”可能会阻止 Tomcat 重新加载 JSP (Bugzilla 37668)。
这记录在 Tomcat 文档 中,位于“ antiResourceLocking”参数解释
An even more late answer ...
Setting "antiResourceLocking" to "true" in the context file may prevent JSP to be reloaded by the Tomcat (Bugzilla 37668).
This is documented on the Tomcat doc, at the "antiResourceLocking" parameter explanation
尽管很容易理解,但“将开发设置为 true”的含义如下(更多内容供快速参考):
然后重新启动。
Simple to figure out though it may be, here's what "setting development to true" means (more for a quick reference):
And then restart.
我遇到了同样的问题并解决了问题。
确保在
conf/context.xml
中没有以下配置如果有该配置,请删除两个
antiJARLocking="true" antiResourceLocking="true"
,只需编写I had the same problem and fixed the issue.
Make sure that in
conf/context.xml
you do not have following configurationIf you have that one, remove both
antiJARLocking="true" antiResourceLocking="true"
, just write虽然答案很晚,但其他人可能会发现这很有用。
检查Tomcat文件夹的权限,我尝试了很多其他解决方案,但没有成功。
最后,我授予我的“用户帐户”对 Tomcat 文件夹的“完全控制”权限,每当我在 JSP 中进行更改时,Tomcat 都会接受更改。我假设您使用的是 Windows。
其背后的基本原理是:每当您在 JSP 中进行更改时,都必须将其编译并部署(写入)到 webapps 文件夹中。如果该文件夹没有“写入”权限,它将默默失败。我的例子就发生过这种情况。因此,如果 context.xml 中的
reloadable = true
和development = true
不起作用,请尝试此权限修复。我在 Windows 7 上使用 Tomcat 7。
A late answer, anyone else might find this useful though.
Check the permissions on the Tomcat folder, I have tried a lot of other solutions and it did not work out.
Finally I gave my 'user account' 'Full control' permission to the Tomcat folder and Tomcat picked up the changes whenever I made a change in JSP. I am assuming you are using Windows.
The rationale behind this was: whenever you make a change in JSP, it has to be compiled and deployed (written) to the webapps folder. If there is no 'write' permission on that folder, it will silently fail. This was happening in my case. So if
reloadable = true
anddevelopment = true
in the context.xml do not work, try this permission fix.I am using Tomcat 7 on Windows 7.
同步服务器和客户端时间
您可以检查您的服务器时间和客户端系统时间。对我来说,几天前更改服务器时间后正确工作。它反映了 .jsp 文件的更改。
Synchronize server & client time
you can check your server time and client system time. For me a few days ago after changing the server time correctly worked. It reflected the changes of the .jsp files.
您需要转到 Eclipse 中的服务器项目并编辑 web.xml 文件并将“development”设置为 true。
You will need to go to the server project in Eclipse and edit the web.xml file and set 'development' to true.
打开 META-INF 文件夹中的
context.xml
文件并将antiJARLocking
设置为 false。您的目录树应如下所示:
Web >元信息>上下文.xml
Open your
context.xml
file in your META-INF folder and setantiJARLocking
to false.Your directory tree should be as follows:
Web > META-INF > context.xml
我在 Windows 7 上使用 TomEE 1.7.2 和 Eclipse。对我有用的解决方案只是在 localhost-config(在我的 IDE 中)更改 TomEE 服务器的 web.xml 文件,以便开发 init 参数为 true:
I am using TomEE 1.7.2 on Windows 7 with Eclipse. The solution that worked for me was simply changing the web.xml file for the TomEE server at localhost-config (in my IDE) so that the development init param is true:
(Tomcat 7.0.62) 我必须转到 CATALINA_HOME/temp/xx-mysite/,在 that 目录树中找到我的 jsp 文件并编辑它。
xx 是一个随机(?)前缀数字,在我的例子中是 11,但每个站点都有一个。
(Tomcat 7.0.62) I had to go to CATALINA_HOME/temp/xx-mysite/, find my jsp file in that directory tree and edit it.
xx is a random(?) prefix number, in my case 11, but every site had one.
我在 myeclipse 中进行 jsp 更改时也遇到了这个问题,这些更改在运行时没有反映在应用程序中。
我希望这些检查能对您有所帮助。
我希望这会对您有所帮助。
I too faced this problem while doing jsp changes in myeclipse, those are not reflecting in the application while running.
I hope these checks will help you.
I hope this will help you.
转到您的 web.xml 找到您的 jsp servlet,将此参数添加到其他参数之后:
Go to your web.xml find your jsp servlet, add this parameter after the other ones:
实际上jsp引擎检查jsp页面是否比其servlet页面旧,并在此基础上决定是否需要更改。
Actually jsp engine check whether jsp page is older than its servlet page or not and on the basis of this it it's decide whether changes are needed or not.