jquery.js doesn't get loaded in Tomcat - java

OK, so I found out so far, that despite me having the jquery.js file in the same folder as the jsp file I have, the Ecipse-Tomcat configuration is executing the files in a different location and it takes all the files except for jquery.js How is this possible and how I can make it automatically load the file in it execution folder?
In my case jquery refuses to work unless I specifically put it in the folder where tomcat is executing the files... Any ideas? Thanks.

Alright, after a few hours of struggling, I finally found a solution to this problem. Seems Eclipse Tomcat probably isn't refreshing and checking the files in the path well if you're using any other perspective than Java EE. In my case I was using and working all the time in the normal Java perspective and this way it never reloaded even when I would click refresh. Now however I switched to Java EE view and clicked refresh. The file finally appeared and jquery finally started working!

All JS/CSS/HTML files are static resources and would be served from Tomcat through DefaultServlet. You would need to configure the default servlet in your web.xml with appropriate location to the folder where these are present. This has nothing to do with the location of JSP, though the JSPs can also go under the same folder.

Related

My Dynamic Web Project welcome-file doesn't get affected by changes

This is a pretty strage and hassle problem i have here.
I created a Dynamic Web Project in Eclipse and created an HTML file named "inicio.html".
I put this into my web.xml <welcome-file> and all seemed to work okay.
I could Run on server without any problem.
Until i dragged a folder into my webapp.
folder in my project
Now when i run on server my file doesnt change at all, and even when i change the welcome-file from web.xml it doesn't change.
It looks like there's another file somewhere like a copy from the original "inicio.html" that's executing on my server.
this is an example of what's happening
I tried to change my TomCat's web.xml file and it doesn't works.
It's unlikely that the new IMG folder is relevant. Deployment Descriptors aren't really hot swappable.
Make sure automatic building is enabled on the Project menu, and then try right-clicking on the server in the Servers View and choosing "Clean Tomcat Work Directory". Otherwise, you'll need to restart the server for changes to take effect.

Why Tomcat works fine when I put a .jsp but with a .html doesn't works?

I'm working with eclipse and I created a project, I put a test.html and test.jsp file in the root folder. In the URL of the Google Chrome I put this:
http://localhost:8080/project/test.html Error 404
http://localhost:8080/project/test.jsp Works (hello world!)
What is happening?
Double check if your test.html exists under this path:
"Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\project"
If exists, then it should be accessed normally, if not then you have to clean/build your application correctly or even try to restart eclipse.
Based on your follow-up comments about the custom Tomcat install and the project error message, it sounds like you either don't have Eclipse properly configured to use your Tomcat server, or you don't have your project associated with the Tomcat server you've set up, and so perhaps your changes arent being deployed properly. See if that issue has a quick fix suggestion (right click it) or go through your project settings and verify your selected server runtime. Sorry on phone can't give specific instructions.

unable to find servlet(.java) files converted from jsp

I am using eclipse luna and tomcat version 7. I have written few jsp files and executing them on tomcat easily. I have read that jsps are converted into servlets at run time and you can locate them in tomcat/work/catalina/localhost/project name and further. My project name is quizilla and there exist a folder named quizilla-1.0-SNAPSHOT, but this folder is empty. What is the reason and where can i find those .java files. I have attached the screen shot of the folder as wellAs I am in right directory in search of my java files, but the folder is empty. So what should i do
You are using Tomcat from Eclipse, so the work directory is:
projectworkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
or something like that (if you haven't changed the Server configuration via Eclipse).
Add
<%=getClass().getResource(getClass().getSimpleName() + ".class")%>
to one of your JSP pages to detect where Tomcat has generated the servlet.

Editing Folder content in tomcat manually?

I have a WAR file called ROOT.war where I uploaded into Tomcat few days back. There I have few "public" HTML pages like index.html, about.html etc. These pages has no connection with the programatic part of the application, instead containing a link for login.jsp.
Now, I need to change the content of the index.html and about.html. What I was used to do is rebuild the entire WAR file and re-uplaod it, but now can't do it for small and iterative changes like this because the application is in use.
So, can I simply access the webapps -> ROOT folder in Tomcat and replace the index.html? Will it affect the process of the application?
It works but avoid such practices which lead to discrepancies.
Follow standard deployment process - rebuild the entire WAR file and re-upload it during deployment window.
You can, and It will work. You can even change the JSP code. The only issue you may have is that when you redeploy a new version of the war, changes made in the server will ve overriden by the new version, so you better change it in the original tool also.

Deploying a WAR file gives me a 404 Status Code on Tomcat?

I am fairly new to Tomcat. I just managed to build a project and exported it as a WAR file. I tried manually copying a WAR file to the Tomcat folder then restarting. It created the folder structure and everything but I get a 404 Status code when I try to reach the application. I tried deploying it through the Tomcat Admin panel but I'm seeing the same behavior. Am I doing anything fundamentally wrong?
Assuming that you have full privileges with the Tomcat installation, try going to http://localhost:8080/manager/html/, if you don't know the password to get into that area, look for the tomcat-users.xml file in your ${tomcat-installation}/conf directory, and that should have it. If it has no entries in it then you will want to add an entry like the following to it:
<user username="username" password="password" roles="admin,manager" />
See whether your application shows up in that screen, and if it does, click on the link and see if that gets you anywhere. If it doesn't, then I suggest following ifishers's advice, and looking at the log files to see if it lists any errors.
But long story short, most likely something is screwed up with your project's web.xml
In more recent times, this condition might occur if JAVA_HOME points to an earlier version of Java than the code in the WAR. Tomcat might use JAVA_HOME to determine JRE_HOME it shows after running startup.bat in Tomcat's BIN directory. While Tomcat may be happy itself with the Java version it gets, for the application this might not be sufficient. In my case, Tomcat 8.0.49 was running alright with JDK1.7, while the application was not initializing at all (yes, it was a Spring Boot application, WAR was being unpacked, but that's all) - without giving any errors. After setting JAVA_HOME to the location of JDK1.8, the problem was solved.
I have the same problem.
My problem is my application name and war file name are different.
I have change war file name to my application name.
Here, when your application is deployed tomcat automatically extract your war file with same name. In my case my service name is my-web-service(i.e.https://localhost:8080/my-web-service/) and my war file name is MY-java-connector-0.0.1-SNAPSHOT.war(this is my project folder name). Now tomcat is looking for my-web=service folder and it finds epicor-java-connector-0.0.1-SNAPSHOT folder. so rename the folder to my-web=service.war and it is working.
I had the same issue, my problem was that I was copying the file via sftp straight into the webapps dir of tomcat which may have caused a polling issue causing it to not deploy correctly.
Tomcat monitors the webapps dir and when it sees the .xml it will crack on and do its thing, problem is that maybe everything hasn't been copied across yet. :(
Best to create a staging folder, move or copy the war to that folder and then use linux mv command to move it into the webapps - mv is atomic so tomcat won't do anything until the operation is complete.
Magic.
Credit goes to a very very random post that I found on javarance which in turn lead to : http://pub.admc.com/howtos/tomcat/ch02.html#stagedir-section
Hope this helps someone else :)
If your'e using Spring-Boot like me to create your WAR file make sure to add the following to your main Application file.
#SpringBootApplication
public class serverTestApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(serverTestApplication.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(serverTestApplication.class);
}
}
I was stuck on this for awhile, looked through dozens of guides. This is the video that finally showed me I never configured my application properly:
https://www.youtube.com/watch?v=05EKZ9Xmfws
My best guess is that you have not configured the welcome files in your web.xml. If you go to /app/ you need to have some default file available. Typically, people either created an index.html or they have welcome file settings to point the user to the correct jsp.
I ran into this problem, too.
My simple roundabout solution is to change docBase path.
problem occurs when
docBase=".../tomcat/webapps/app_name.war";
problem solved with
docBase=".../tomcat/webapps/app_foldername/web"
I had the same problem with tomcat and just fixed it by forcing my IDE to create a web.xml file. Mine was missing. It would deploy the project but I would still get the 404 error. I read through several of these tutorials but to no avail. I read somewhere that the web.xml file needed to be configured correctly. Went to find the web.xml in the WEB-INF folder, and there was no folder and no web.xml file. I did a quick google on how to create on using my IDE and then compiled my program with the web.xml output, and it fixed the problem for me. Hope that helps. Cheers!
FWIW I had this problem and fixed it by discovering I was accessing the wrong host, like "http://wronghost:8080/why_is_this_war_not_there" so if it says "XX.war successfully deployed" in catalina.out/localhost.*.out that may be a hint for followers.
I had the same issue. In my case there were no errors in the log files, I had a welcome page defined, it was listed in the Tomcat manager webapp, and it deployed and worked fine on my dev machine. However, visiting the app at http://example.com/myApp just returned a 404 error.
It turns out the problem was in the Apache config. Apache didn't have a mount point, so it didn't know to proxy those requests to Tomcat.
Adding in the appropriate directive fixed the problem:
ProxyPass /myApp ajp://127.0.0.1:8009/myApp
If you have not created any welcome page like index.html JSP or whatever then create one. project must have an index page. I just created one say index.html and the problem is solved..🙏🙏🙏
Did you try
localhost:8080/app
assuming your war file is app.war?
edit for comment -- then your web.xml is screwed up.

Categories