English 中文(简体)
Why are my JSP changes are not reflected without restarting Tomcat?
原标题:

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>
问题回答

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.

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

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.

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>

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.

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.

You will need to go to the server project in Eclipse and edit the web.xml file and set development to true.

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

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>

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

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>

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.





相关问题
Tomcat´s server.xml dynamic configuration

My web application uses the same database configuration as the application XYZ. I have a resource declaration for a context in server.xml, so I have a duplicated configuration (once for web ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...

热门标签