Eclipse Servlets take a long time to update - java

I'm testing running a simple Servlet from within Eclipse. When I click 'Run', the console says it is starting TomCat, and then an internal browser launches within Eclipse which shows my code.
However, if I make any changes in the servlet and click 'Refresh' in the browser, the changes don't show. Then, a few seconds later if i hit refresh, the changes begin to show randomly. So I'm guessing there's a cache setting somewhere that controls this.
How can I turn that cache setting off or otherwise make the Eclipse internal browser update instantly as soon as I hit refresh?

This is caused by the way servlet developing works. When modifying your servlert, it needs to be submitted to the servlet container after compiling it. The servlet container itself needs to reload the servlet, the servlet must be instantiated (servlet lifecycle). Thats a lot of things to do, which may cause you waiing for an update visible in the browser some seconds.

Related

ServletException in:/layouts/menu.jsp null' in one portion of jsp page where redirect link is there

There is a java struts 1.1 web application developed using java 4 and which is now being upgraded to openjdk 8. While running the application I am getting this servlet exception in the UI screen in one portion which consists of a link to different jsp page. How to fix this issue?
[ServletException in:/layouts/menu.jsp] null'
I had the same issue. I think it's getting hung up somewhere in your Action class, as soon as you enter the entry point of your Action class. Place some system outs to the console and check how far you can get with it. Then if you don't see your next system out, then that's where the issue may be hanging around.

How to find the entry point in a java web application to debug?

I am trying to debug a java web application. I have configured tomcat in eclipse, added my application to tomcat and started the tomcat in debugging mode.
Now, when the user performs any action on the web page, the request hits the server, goes through some java/tomcat classes and finally reaches our application code.
If I know which of the application classes/methods will be executed, I can set a breakpoint and start debugging from there. But if I don't know which code will be executed, how can I set breakpoint?
Basically I am trying to figure out which application class/method is executed when user performs an action on the page.
I know I can set a breakpoint in the Servlet doGet/doPost method. But we are using struts and we have many more general servlets also. So it is difficult to set breakpoint in all of them.
Please help.
Check your Tomcat logs (or console). You should see which part of code is executed when you are doing something on your web page then set breakpoints. When you finally catch the program somewhere try to find a better place according to stacktrace in your debugger.
Look in your struts-config.xml file and find the action that matches your URL. Most Struts implementations use the *.do pattern to match Struts actions. The path part of the URL without the .do will match an action configuration in your struts-config.xml file. Find the action class that is called and put your breakpoint in the execute() method.

Showing the right "Running" status in tomcat manager

I'm running a servlet in a tomcat container.
All is working correct, tomcat calls the init method of my Servlet and it starts correctly.
When I look at the Tomcat Web Application Manager - List Applications I see the running status is "true".
In the init function I want to check some important settings.
If a check fails, I throw a new ServletException. Now I thought that the running status would change to "false" but it didn't.
So my question is how to stop the servlet from a check in the init function.
Or maybe I just do it the wrong way.
Would like to get some help, thanks in advance
The Manager does not show the status of individual servlets but of the web application. Individual servlets can fail to start but that doesn't stop the web application from starting.
If you have some checks you want to perform that need to stop the web application starting then put those checks in the contextInitialized method of a ServletContextListener and throw a RuntimeException (or a subclass of it) if the checks fail.

Custom Service Builder Methods in Hooked JSP

I want to extend the users admin portlet that is located in the control panel. I hooked the jsp and wanted to use methods from the service builder that are in the same hook as the jsp.
The problem is that the jsp can not find the classes. So I copied the *-service.jar to the tomcat lib/ext folder and removed it from the hook when deploying it.
But that doesn't work. After a while I get an exception that says Cache is not alive or this web application instance has been stopped already.
Is there a way to use methods from my custom service builder in the hooked jsp ?
The approach you have taken is correct, i.e. to put the *-service.jar inside [TOMCAT_HOME]/lib/ext and removing the jar from the hook.
The error might be because the hook may not have been properly undeployed, you may get some idea from this forum post. So my suggestion would be to:
Undeploy the hook
Stop the server
Copy the jar to [TOMCAT_HOME]/lib/ext
Clear temp and work directory
Restart the server
Deploy the hook
Whenever you remove a jar from a plugin-project and then just deploy without undeploying the portlet, sometimes you may notice that the jar file may be still present in the deployed webapps/plugin-project's directory, and this might be the case here as well. Also, whenever you put something in the global classpath (i.e. [TOMCAT_HOME]/lib/ext) you need to restart the server.
Also, don't forget to import the class in the JSP :-), just in case ...

What causes duplicate requests to occur using spring,tomcat and hibernate

I'm working on a project in Java using the spring framework, hibernate and tomcat.
Background:
I have a form page which takes data, validates, processes it and ultimately persists the data using hibernate. In processing the data I do some special command (model)
manipulation prior to persisting using hibernate.
Problem:
For some reason my onSubmit method is being called twice, the first time through things
are processed properly. However the second time through they are not; and the incorrect
information is being persisted.
I've also noticed that on other pages which are simply pulling information from the data
base and displaying on screen; Double requests are happening there too.
Is there something misconfigured, am I not using spring properly..any help on this would
be great!
Additional Information:
The app is still being developed. In testing the app I'm running into this problem. I'm using the app as I would expect it to be used (single clicks,valid data,etc...)
If you are testing in IE, make note that in some versions of IE it sometimes submits two requests. What browsers are you testing the app in?
There is the javascript issue, if an on click handler is associated with submit button and calls submit() and does not return false to cancel the event bubble.
Could be as simple as users clicking on a link twice, re-submitting a form while the server is still processing the first request, or hitting refresh on a POST-ed page.
Are you doing anything on the server side to account for duplicate requests such as these from your users?
This is a very common problem faced by someone who is starting off. And not very sure about the application eco-system.
To deploy a spring app, we build the war file.
Then we put it inside 'webapps' folder of tomcat.
Then we run the tomcat instance using terminal (I am presuming a linux system).
Now, we set up env in that terminal.
The problem arises when we set up our environment for the spring application where there can be more than one war files to be deployed.
Then we must cater to the fact that the env must be exclusive to a specific war file.
To achieve this, what we can do is create exclusive env files for every war. (e.g. war_1.sh,war_2.sh,.....,war_n.sh) and so on.
Now we can source that particular env file for which we have to deploy its corresponding war. This way we can segregate the multiple wars (applications) and their environment.

Categories