No project can be run from eclipse on Tomcat - eclipse

When trying to create Dynamic Web project or even using old one( which used to work before) and running it on the tomcat(v8.0.35) server from my eclipse (mars.2 v4.5.2) I started getting Http status code 404 when accessing the recourse:
Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>hello</display-name>
<servlet>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.javawebtutor.controller.LoginServlet</servlet-class>
</servlet>
<servlet>
<display-name>RegisterServlet</display-name>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>com.javawebtutor.controller.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/RegisterServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
For reference, I have done everything step by step in this tutorial:
http://www.javawebtutor.com/articles/hibernate/mvc-appliction-using-servlet-jsp-and-hibernate.html
Java I'm using for the project is jdk1.8. For server - jre1.8
I'm 99% sure I've not deviated from the tutorial and something wrong must be with my Tomcat installation. As I mentioned it worked before on other projects I have not modified and it stopped working as well.
I have tried cleaning projects, cleaning Tomcat server, work directory, remove tomcat server, restart eclipse, add tomcat server again. I've even converted project into Maven project and tried to build with clean and install goals. Nothing helped.
Here is server location snippet:
Related answer here: Tomcat is not deploying my web project from Eclipse
And yes, I did try everything in there.
If it helps I'm developing on Win10
EDIT:
Project topology:

With the limited amount of info, I suggest you do the following:
Check if you have a login.jsp directly under your webapp or webContent(your tutorial uses this), because your welcome file in web.xml specifies this as your home page.
Try access http://localhost:8080/ instead of http://localhost:8080/hello/
Please provide your complete expanded project tree if the above does not solve your problem.
Also, here is one of my youtube video introducing how to set up a running java-web app with eclipse and tomcat. It is only a couple of minutes.
Following this tutorial makes sure you have a minimal java web project running, you can start from there if your problem cannot be fixed.

Related

Struts 2 Hello World

I have a problem at this example
I work with eclipse for Java EE and Apache Tomcat 8.
My project structure:
The web.xml code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Hello World Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
The other files code is the same as the struts website.
When I run the index.jsp file I get the following error:
**HTTP Status 404 - /helloworld/index.jsp
type Status report
message /helloworld/index.jsp
description The requested resource is not available.**
Can someone spot the reason why can't I run it?
First of all the project is created by using Maven configuration, and to access the Struts action you should use url
Step 6 - Build the WAR File and Run The Application
Execute mvn clean package to create the war file.
Copy the war file to your Servlet container. After your Servlet
container successfully deploys the war file go to this URL
http://localhost:8080/helloworld/index.action where you should see
the following:
(source: apache.org)
Web application context is where the application was deployed. In the docs url it's /helloworld, on the image it's /Hello_World_Struts2_Ant. Use it as a part of the url. It doesn't matter which app context did you use during deployment but url depends on it. If you want to change the web app context you should read Java - How to change context root of a dynamic web project in Eclipse. After the context you use action name with .action extension to execute action.
Don't use URLs like localhost:8080/helloworld/index.jsp because you might not get the resource because it's already handled by the web server.

Removing #WebServlet causes java.lang.ClassNotFoundException

I'm using Tomcat 7 in eclipse Juno with servlet 3.0 specs (jdk 1.7).
When I create a new servlet using Eclipse IDE it automaticaly create a new mapping using #WebServlet("/foo") statement and everything works fine (the servlet works).
Removing the #WebServlet("/foo") mapping and using the manual one in web.xml:
<web-app>
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-path>foo.Servlet</servlet-path>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/foo</url-pattern>
</servlet-mapping>
</web-app>
causes Tomcat crash:
SEVERE: Allocate exception for servlet java.lang.ClassNotFoundException:
I'm sure that foo.Servlet.Servlet1 is the correct path and name.
I've to manually compile the servlet before starts Tomcat? I run the project directly from eclipse ide, setting up a Tomcat 7 Runtime Environment.
Your Servlet declaration in web.xml is not correct, You need to change
<servlet-path>foo.Servlet</servlet-path>
with
<servlet-class>foo.Servlet</servlet-class>
Also you should add the schema declaration in your web.xml file, it would have saved you all this trouble by showing the error in your xml editor because there is nothing such as <servlet-path> in it.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">

Getting HTTP Status 404 error when trying to deploy war file of my web application on tomcat

I know this questions was asked earlier yet any of the answers given did not fix my problem.
I have created a web application named JSP_web_application_01 using JSP in Eclipse and I'm on ubuntu 12.04 LTS. I have index.jsp file inside WebContent directory. I made the .war file of it using command prompt and in order to deploy it I put it inside the webapps folder of tomcat and stopped tomcat using the command sudo $CATALINA_HOME/bin/shutdown.sh and again started it by sudo $CATALINA_HOME/bin/startup.sh
And it inflated the .war file(JSP_web_application_01.war) and created the JSP_web_application_01 folder structure and everything but what I get is an http 404 status code when I try to access it from the browser using :
http://localhost:8080/JSP_web_application_01/
I get this :
HTTP Status 404 - /JSP_web_application_01/
type Status report
message /JSP_web_application_01/
description The requested resource is not available.
Apache Tomcat/7.0.47
This is my web.xml file that is inside WebContent/WEB-INF folder
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>JSP_web_application_01</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
This is my first time of trying to host a web application. So, any help would be much appreciated.
Your Steps seems to be ok , Replace the welcome file list with a single file, If you want to load index.html . then ,
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>JSP_web_application_01</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Also Clean and Build your project to get rid of errors before you deploy it as .war
Read here and here to know more about Deployment Descriptor.
Hope it helps!
Check the project files must be decompressed under JSP_web_application_01 especially index.jsp. If it correct, restart web server, tail the log file under $CATALINA_HOME/logs, check the start info correct.

web.xml servlet tag breaks down with Tomcat6 on EC2

ENV: Amazon Linux with Tomcat6 on EC2.
I create a simple dynamic web project with an index.jsp on Eclipse, load it to cloud and it shows up correctly. But once I create a servlet and do the same process, the page says service not available and gives error code 503.
I have tried to remove the servlet tags in web.xml, then it works again.
Just to clarify, I have two existing dynamic web projects that I'd like to have deployed on cloud. Both are running fine on local Tomcat6.
edit:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>Se</display-name>
<servlet-name>Se</servlet-name>
<servlet-class>Servlet.Se</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Se</servlet-name>
<url-pattern>/Se</url-pattern>
</servlet-mapping>
</web-app>
Above is my web.xml, if I remove servlet,servlet-mapping blocks, it works again.
The UnsupportedClassVersionError usually happens because you are using a newer JDK version for compiling than the version used at runtime. Try compiling with the same JDK version used by Tomcat.
SEVERE: Error deploying web application archive Test.war
java.lang.UnsupportedClassVersionError: Servlet/Se : Unsupported major.minor version 51.0 (unable to load class Servlet.Se)
This type of error occurs when you have compiled your running your application on a different version of JRE than it was originally intended for or compiled on.
51.0 means that it is expecting JRE version 7 and (it is most probable that) you must be running it on JRE 6 on your ec2 server. First determine what is the version of the JRE on your ec2 server with the command
$ java -version
and make sure that is matches the one with on which the code was initially compiled on. It is most probable that you compiled your code on JRE7 and on ec2 server, JRE6 is configured and you might want to upgrade it on ec2 server, or downgrade on your machine.

Eclipse not deploying my web app properly

I am trying to create a base Spring project with Maven on Eclipse Kepler (with m2eclipse installed). No errors are reported by Eclipse but when I hit Run on Server (or run Maven Install) only the original files from META-INF and WEB-INF files are deployed. This does not include my dispatcher-servlet.xml config file thus causing a FileNotFoundException:
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
How can I fix this?
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/dispatcher-servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
And this is a screencap of my project's folder:
As you can see only selected files are shown in Deployed resources.
Since it is a maven project .
you might have converted maven project to dynamic web project I guess.
Follow the steps
Go to project properties (right click at last click peoperties)
click/select Deployment assembly at the left side
the root(/) deploy path may be pointing to src/main/webapp , select this and click remove button
click on add button , select a directive type folder, select your WebContent folder
Now try to clean and run your application on server.
Solution 2
Actually you need to copy/put all your WebContent files and folder to src/main/webapp
and restart your server.
Note that the maven dynamic web project it always look in to src/main/webapp by default.
Hope it helps
Add <sourceDirectory>src</sourceDirectory> in the <build> block.
Then Run Maven with "clean install" goal.
And refresh your project.
Now check your target folder. You should see war file or * extension file.
Hope it will solve