为什么我的 JSP 更改在不重新启动 Tomcat 的情况下不会反映出来?

发布于 2024-08-16 16:15:53 字数 1136 浏览 6 评论 0原文

我正在编辑直接位于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

清风夜微凉 2024-08-23 16:15:53

在 tomcat 文档中,请参阅开发 设置。必须将其设置为 true 才能重新加载 jsps。

开发 - Jasper 是否用于开发模式?如果为 true,则可以通过modificationTestInterval 参数指定检查 JSP 修改的频率。true 或 false,默认 true。

这是在你的CATALINA_HOME/conf/web.xml

此外,如果你需要在生产环境中刷新jsp而不重新启动,你可以转到CATALINA_HOME/work/Catalina/localhost/contentName /org/apache/jsp 并删除 your_jsp.javayour_jsp.class 文件。它们将在下次访问时重新创建。

编辑:在提供您的配置并评论不刷新内容后,我还有另一个:清除浏览器缓存,或从另一个浏览器打开页面。

In the tomcat docs, see the development setting. It must be set to true in order to have jsps reloaded.

development - Is Jasper used in development mode? If true, the frequency at which JSPs are checked for modification may be specified via the modificationTestInterval parameter.true or false, default true.

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 the your_jsp.java and your_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.

吃颗糖壮壮胆 2024-08-23 16:15:53

更晚的答案...

在上下文文件中将“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

黎夕旧梦 2024-08-23 16:15:53

尽管很容易理解,但“将开发设置为 true”的含义如下(更多内容供快速参考):

<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>
    <!-- Add the following init-param -->
    <init-param>
        <param-name>development</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
</servlet>

然后重新启动。

Simple to figure out though it may be, here's what "setting development to true" means (more for a quick reference):

<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>
    <!-- Add the following init-param -->
    <init-param>
        <param-name>development</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
</servlet>

And then restart.

も让我眼熟你 2024-08-23 16:15:53

我遇到了同样的问题并解决了问题。
确保在 conf/context.xml 中没有以下配置

<Context antiJARLocking="true" antiResourceLocking="true">

如果有该配置,请删除两个 antiJARLocking="true" antiResourceLocking="true",只需编写

<Context>

I had the same problem and fixed the issue.
Make sure that in conf/context.xml you do not have following configuration

<Context antiJARLocking="true" antiResourceLocking="true">

If you have that one, remove both antiJARLocking="true" antiResourceLocking="true", just write

<Context>
少女净妖师 2024-08-23 16:15:53

虽然答案很晚,但其他人可能会发现这很有用。

检查Tomcat文件夹的权限,我尝试了很多其他解决方案,但没有成功。

最后,我授予我的“用户帐户”对 Tomcat 文件夹的“完全控制”权限,每当我在 JSP 中进行更改时,Tomcat 都会接受更改。我假设您使用的是 Windows。
其背后的基本原理是:每当您在 JSP 中进行更改时,都必须将其编译并部署(写入)到 webapps 文件夹中。如果该文件夹没有“写入”权限,它将默默失败。我的例子就发生过这种情况。因此,如果 context.xml 中的 reloadable = truedevelopment = 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 and development = true in the context.xml do not work, try this permission fix.

I am using Tomcat 7 on Windows 7.

情绪操控生活 2024-08-23 16:15:53

同步服务器和客户端时间

您可以检查您的服务器时间和客户端系统时间。对我来说,几天前更改服务器时间后正确工作。它反映了 .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.

手长情犹 2024-08-23 16:15:53

您需要转到 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.

绻影浮沉 2024-08-23 16:15:53

打开 META-INF 文件夹中的 context.xml 文件并将 antiJARLocking 设置为 false。

您的目录树应如下所示:

Web >元信息>上下文.xml

Open your context.xml file in your META-INF folder and set antiJARLocking to false.

Your directory tree should be as follows:

Web > META-INF > context.xml

烙印 2024-08-23 16:15:53

我在 Windows 7 上使用 TomEE 1.7.2 和 Eclipse。对我有用的解决方案只是在 localhost-config(在我的 IDE 中)更改 TomEE 服务器的 web.xml 文件,以便开发 init 参数为 true:

<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>
    <init-param>
        <param-name>development</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
</servlet>

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:

<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>
    <init-param>
        <param-name>development</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
</servlet>
冧九 2024-08-23 16:15:53

(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.

荆棘i 2024-08-23 16:15:53

我在 myeclipse 中进行 jsp 更改时也遇到了这个问题,这些更改在运行时没有反映在应用程序中。
我希望这些检查能对您有所帮助。

  1. 从 MyEclipse 中双击 Tomcat Server。
  2. 单击“概述”窗口中的“发布”菜单。
  3. 选择单选按钮“资源更改时自动发布”,
  4. 输入发布间隔时间为 1 秒。

输入图片此处描述

我希望这会对您有所帮助。

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.

  1. Double click on Tomcat Server from MyEclipse.
  2. click the Publishing menu from the Overview window.
  3. Select the Radio button "Automatically publish when resources change"
  4. enter the publishing interval time as 1 second.

enter image description here
enter image description here

I hope this will help you.

新雨望断虹 2024-08-23 16:15:53

转到您的 web.xml 找到您的 jsp servlet,将此参数添加到其他参数之后:

<init-param>
  <param-name>developer</param-name>
  <param-value>true</param-value>
</init-param>

Go to your web.xml find your jsp servlet, add this parameter after the other ones:

<init-param>
  <param-name>developer</param-name>
  <param-value>true</param-value>
</init-param>
凉月流沐 2024-08-23 16:15:53

实际上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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文