Tomcat7 serving blank pages - eclipse-luna

I am using Java with Tomcat7 to develop a web application.
I'm a trying to test my services in local using Eclipse built-in environment.
My servlets are working fine but I get blank pages when loading HTML file.
My home page is configured like so in my web.xml:
<welcome-file-list>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
My ports 8005, 8080 and 8009 are not in used by another application.
I tried switching Tomcat's location in Eclipse properties but nothing changed.
Why is Tomcat serving blank HTML pages?

Problem solved: I simply moved all my HTML files under the WebContent directory.
WebContent appears to be the root directory of Java EE web applications under Eclipse.

Related

Getting Problem in apache server while deploying spring boot application on tomcat 9: Status 404 - Not Found

enter image description hereI have developed application that is build in spring boot which is working fine in my local but while deploying on production i'm getting error.
HTTP Status 404 - Not Found
Description: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Check your tomcat health
Remove your war and start it
Go to localhost:port and a tomcat home page must be renderized:
If your tomcat does not show the expected home page, try to fix it before to deploy your app.
Possible cause
According to your comments, you issue could be this:
You java web app shows the home page in your localhost (eclipse) at:
http://localhost:8080
But when you deploy in a tomcat, you are using a war file which is deployed in webapps folder. For example:
acme-web.war
So if you deploy this war in your tomcat hosted in
http://localhost:1234 (which must render the tomcat home page)
Your app will be available at:
http://localhost:1234/acme-web
There is a technique to show your web instead the tomcat home page. Just ask me!
I hope this helps you.

I can't see my WAR file in webapps folder of Tomcat

I can't see my WAR file in webapps folder of my Tomcat server directory.
My project is portal project and I am using Liferay portal technology hosted on Tomcat server.
For deploying, I am using Maven configured goal name 'deploy'.
When I deploy the portlet module it generated the war file and I can see the file in deploy folder of my Liferay server but when I start the tomcat server it should ideally generate/move WAR file in 'webapps' folder of tomcat server directory but it is not doing that.
I have tried multiple options like deleting and re-configuring the server, setting Dynamic web-module version to 3.0 from 2.5 (as suggested in one of the post at StackOverflow) but nothing works for me.
I am stuck in this issue for long time and any help will be a great help..
Thanks
I'm assuming that you're using Liferay 7 or Liferay DXP. As these versions are built on OSGi, they're transforming the WAR files into an OSGi bundle (so called WAB, Web Application Bundle) and do not deploy them to tomcat, as you observe.
Prior versions did this, but not the current one.
As you don't state what else you'd expect: This is your answer - you're right, it's not there.
If you don't use Liferay 7 or DXP: Elaborate.

Moving Spring boot web application in tomcat 8

I made a little web app with Spring Boot with web MVC, it is working fine if I run it by deploying the war or if I run it directly from STS. The problem is that my application is always run with his appname as context app (something like "localhost:8080/appname/") and I can't change it. I tried to write a web.xml with dispater-config.xml but, even if the server recognize it, the path is not changed. I tried to write the method in the SpringBootServletInitializer and setting the path, but it is not working too. I also tried to add a META-INF/context.xml in the webapp folder trought STS (project->src->webapp->META-INF->context.xml) but it's not working too. I am just going crazy with, what should i do to change the app's context path? Thanks
EDIT: I would mount my app in the root context of tomcat
It's built in, in eclipse (STS). I suggest using a stand alone tomcat and not the integrated eclipse tomcat and deploy the war on your stand alone tomcat
Add the context path as a parameter to your #RequestMapping annotation, like this: #RequestMapping("/helloworld")

When using Spring + Spring Boot + STS, where in the Spring Project directory is the localhost "home" folder?

I am using Spring/Spring Boot/and Ember. I want to put my index.html file in the "localhost" main folder, but I have no idea how the Spring Tool Suite deploys Spring Boot. What is the normal process for HTML development and accessing a Spring REST server without getting Cross Site Scripting errors?
My folder structure is as follows:
/.settings
/BookingClient
/gradle
/html (this is where my index.html, css, and all Ember related JS stuff is)
/node_modules
/src
/target
I am guessing its somewhere in the /target directory but nothing I have tried has worked.
Spring Boot will serve static resources for you. Simply put them in src/main/resources/static. See the documentation on static content for more information.

Where should I keep the Spring applicationContext.xml in an EAR

I have service classes which are deployed in an EAR with no WAR or Web apps. In what folder structure should I ideally store the applicationContext.xml?
Currently we load it as
Resource res = new ClassPathResource("META-INF/applicationContext.xml");
That's as good a place as any. It doesn't really matter, and I'm not aware of any convention for this.
If you are using Spring in a web application, you shouldn't ever load a ClasspathXmlApplicationContext manually. Your context will be a web application context, not a classpath application context, and will be loaded automatically if you put the following in your web.xml:
Code:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config.xml</param-value>
</context-param>
assuming your main Spring config file is called spring-config.xml and is located in the WEB-INF folder.
Loading classpath context programmatically is always wrong for web app, you should have one context loaded by listener and (optionally) one more context loaded by DispatcherServlet (if you use Spring web mvc as your mvc framework). I suggest you start by reading some documentation and try the Petclinic example to gain some insight in how to correctly use Spring in a web application.
Also, your ear packaging strategy is wrong; your Spring configuration is webapp specific so you should put your Spring config files inside the WAR, under the root of the web app (probably the best place is somewhere under WEB-INF, alongside web.xml and other descriptors). If you have resources like classes used by both ejb and webapp, you should package those classes inside a jar, put this jar under the lib directory in your ear and add a Class-Path entry for the jar in the MANIFEST.MF of webapp & each of the ejb jars. If you have config files with environment-dependant properties (like jdbc config and disk paths) you shouldn't package them inside your ear but instead let the application read it externally from the file system (PropertyPlaceholderConfigurer is your best shot).
For starters, I suggest you use Eclipse ear creation function to see how your web app should be packaged before you start using ant to build your project.
I also suggest you consider Maven as your compile - build - package strategy since this will automate and standardize the project and the web app maven archetype will let you create a correct pattern for j2ee web app in a blink.

Resources