I created a Dynamic Web Project on Eclipse with the name JavaEEWebContent. The file structure of the project looks something like this.
After compiling when I do a "Run on Server", it runs fine.
When I go the link http://localhost:8080/JavaEEWebContent/, it works fine and displays me the homepage(in my case its index.html).
The problem:
When I go to http://localhost:8080 it shows
I know that the landing page for http://localhost:8080 looks something like this :
Any idea why it is not coming for me or what could go wrong?
Also I am using Tomcat 8.5.54.
This is how my web.xml looks like if that helps:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<welcome-file-list>
<welcome-file>index3.html</welcome-file>
<welcome-file>index2.html</welcome-file>
<welcome-file>index2.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>addNumbers</servlet-name>
<servlet-class>com.servlet.addNumbers.AddNumbers</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>addNumbers</servlet-name>
<url-pattern>/addNumbers</url-pattern>
</servlet-mapping>
</web-app>
Please help.
Nothing's wrong. Eclipse is deploying your web application, and only your web application, when it launches Tomcat. What you're expecting to see is a separate web application. You'll find it in the web-app/ROOT folder of your downloaded copy of Tomcat.
Related
I'm learning Java EE through a simple "Hello World" application, and when I run the program using index.html it works well. However, when I run the same program with index.xhtml, it throws a 404 Error saying "The requested resource is not available."
My folder structure is as follows:
When I run the program using index.html, I use the following URL: http://localhost:8081/index.html, and the page shows up with Hello World. And when I run using index.xhtml, I tried both: http://localhost:8081/example2/index.xhtml and http://localhost:8081/index.xhtml. Both give a 404 Error.
My web.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
I've also tried multiple browsers (Chrome and Firefox). Any ideas why I'm getting a 404 on XHTML but not HTML?
You can config the home page in the web.xml with the code below:
<display-name>NameOfProject</display-name>
<!-- Configuration of your home page -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
So you can use both:
http://localhost:8081/NameOfProject/ or
http://localhost:8081/NameOfProject/index.xhtml
The solution was pretty simple. When I checked the Tomcat logs, there was a ClassNotFoundException because Tomcat does not come with the jsf-api and jsf-impl jars. I created a new directory in WEB-INF called lib and put the 2 jars there. Yes, you need both jars. Now the XHTML file is found and the 404 goes away.
I have created simple dynamic web project on eclipse. I am trying to submit the html form and passing the request to servlet. When I click on submit i get this exception:
HTTP Status 500 wrapper can not find servlet class com.tcs.navigator.Servlet.labServlet or a class it depends on
in jsp form actoin tag I had given same action path as per web xml which is :
action = "labServlet"
content of web.xml is :
<?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">
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>To Upload Files for processing</description>
<display-name>labServlet</display-name>
<servlet-name>labServlet</servlet-name>
<servlet-class>com.tcs.navigator.Servlet.labServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>labServlet</servlet-name>
<url-pattern>/labServlet</url-pattern>
</servlet-mapping>
</web-app>
I tried following workarounds:
clean tomcat directory
open/close project
clean projects
restart eclipse
Verifying class path
created new dynamic web project with same code
But still the same exception persist.
all libraries like servlet-api.jar are present in build path.
you have kept capital S in "Servlet.labServlet" . system is getting it as a Class named Servlet. name your servlet starting with caps like "LabServlet" in the code and start all your package name with small letters. so your complete class path should be
com.tcs.navigator.servlets.LabServlet
I have a j2ee app running on GAE. There is that pre-generated index.html, which is called every time I run the server - let's say http://localhost:8080. But I want to write my own front-end using AngularJS. For that, I created the whole project with Yeoman and copied all the files to folder in my j2ee project.
Right now -> I can call manually the AngularJS webapp like this: http://localhost:8080/webapp/app/index.html
But obviously, that is not the way one wants to go. I would like to call it simply on http://localhost:8080. How can I achieve this?
So it took me longer than expected, but here's how I got it working using the welcome file:
Here's my folder structure:
web.xml file:
<?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" version="2.5">
<servlet>
<servlet-name>So123</servlet-name>
<servlet-class>so123.So123Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>So123</servlet-name>
<url-pattern>/so123</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>webapp/app/index.html</welcome-file>
</welcome-file-list>
</web-app>
Hope this helps.
https://developers.google.com/appengine/docs/java/config/webxml#The_Welcome_File_List
You can also change the root directory in the appengine-web.xml file. Full documentation here.
<public-root>/app</public-root>
[In case it is helpful, I am working from the book Core JavaServer Faces (3rd edition) and am on page 12, or thereabouts.]
I am trying to launch a JSF application using GlassFish but am having problems that I can't identify. I can start GlassFish correctly and see the screen that is depicted in the book, so that appears to be fine. I then copy the file login.war that I've created and placed in the directory containing the src and web directories for this project into the domains/domain1/autodeploy directory of GlassFish.
Going to http://localhost:8080 in Chrome shows the correct screen; however http://localhost:8080/login, as described in the book and corresponding to the login.xhtml page that I have created, simply returns an HTTP 404 Error telling me 'The requested resource () is not available'.
My web.xml file is as follows:
<?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/javee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/nx/javaee
http://java.sun.com/xml/ns/javaee/we-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-patter>/faces/*</url-patter>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
</web-app>
Can anyone offer any help? I am using the Eclipse IDE, my version of GlassFish, as detailed on the error page described above, is 3.1.2.2. If there is any more information that would be helpful, e.g. directory structures, please do ask me for it.
Thanks, Conor.
You should set your application context-root to login if you need to access it with http://localhost:8080/login. There are several ways how to do it, e.g. check this Glassfish tip or in Eclipse IDE, in project Properties click on Web Project Settings and enter new Context root of your application.
This is not a bug, so until you will run more then one application on your server, you can leave it this way if you wish.
When I access a jsp page like this on an appengine development server:
localhost:8888/index.jsp/
it's displaying the source code of index.jsp in the browser. if you access without the trailing slash (i.e. index.jsp) then it renders jsp but with the trailing slash (i.e. index.jsp/) it displays the source code
Any idea why is this? and how to fix it?
It seems to happen only in development server and not in production. Production gives a 404 Not Found error, which is fine.
I am using SDK 1.6.4
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/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>RegisterPage</servlet-name>
<jsp-file>/register.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>RegisterPage</servlet-name>
<url-pattern>/signup</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
==========
so...
index.jsp -> renders page
index.jsp/ -> returns source code
register.jsp/ -> returns source code
register.jsp -> renders jsp
signup/ -> renders register.jsp
signup -> renders register.jsp
so it seems like it's the urls with *.jsp/ that have the issue
You should move all the *.jsp files into the /WEB-INF directory, and update your web.xml.
This way the *.jsp files will not be accessible directly, and the source code will be hidden.
<?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/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>RegisterPage</servlet-name>
<jsp-file>/WEB-INF/register.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>RegisterPage</servlet-name>
<url-pattern>/signup</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>IndexPage</servlet-name>
<jsp-file>/WEB-INF/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>IndexPage</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index</welcome-file>
</welcome-file-list>
I have the some problem when i have used "redirect" and apache tomcat 7, because the redirect is not supported in new version of apache. For solve your problem search news in changelog of your version of apache (if you use it) for the tag you used in your page, or publish code of your page to be able to suggest other solutions. May be that you're using deprecated tags. Also, keep in check the file localhost[DATE].log for more details