Problems with JSF Using GlassFish - java

[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.

Related

Simple HTML page not served by Tomcat (HTTP 404)

I am still running into some issues that already have been discussed here, however I still do not know what I am doing wrong.
My application structure is:
/usr/share/tomcat/webapps/greeting
--index.html
--src
--META-INF
--WEB-INF
--web.xml
--classes
--sk
--simo
--Greeting.class
When requesting http://localhost:8080/greeting/ I receive an HTTP 404 response.
When requesting http://localhost:8080/greeting/hi, I receive an HTTP 405 response. This is not an issue, as the Servlet only processes POST requests.
My question is: How can I make the Tomcat server provide the index.html file.
This is my web.xml file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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_3_0.xsd"
version="3.0">
<display-name>Hello, World Application</display-name>
<description>
This is a simple web application with a source code organization
based on the recommendations of the Application Developer's Guide.
</description>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/greeting/*</url-pattern>
</servlet-mapping>
<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>
Some information on the server:
[miso#edubox conf]$ /sbin/tomcat version
Server version: Apache Tomcat/7.0.76
Server built: Mar 12 2019 10:11:36 UTC
Server number: 7.0.76.0
OS Name: Linux
OS Version: 3.10.0-957.1.3.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_212-b04
JVM Vendor: Oracle Corporation
1) Definition of each servlet consists of two parts: 1) Binding of servlet class to a logical name and 2) Mapping this logical name to URLs.
In your web.xml you have defined only the 2nd part. Now you should add there also the servlet class name. If you keep your logical name "default", then add following code:
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>sk.simo.Greeting</servlet-class>
</servlet>
2) Alternatively, use #WebServlet(value="/greeting"). But then remove your servlet mapping from web.xml.
3) Independent on the answers above, the mapping of folders to context root is important. If you have not change it (I suppose you have not, this is good), then path "/usr/share/tomcat/webapps/greeting" means, that everything in your application is available via URLs that have context root "/greeting". It means, if you want to call a servlet via "/greeting/hi", servlet should be mapped to "/hi", not to "/greeting" and not to "/greeting/hi". So use following in your servlet: #WebServlet(value="/hi"). This you can call it via ".../greeting/hi".
The main issue was an errorneous redeployment. As soon as I deleted the app's top level directory "greeting" and restored its contents, the index.html finally has shown up.
The servlet mapping now follows the example of the Tomcat 7 "sample" app:
web.xml:
<servlet>
<servlet-name>Greeting</servlet-name>
<servlet-class>sk.simo.Greeting</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Greeting</servlet-name>
<url-pattern>/hi</url-pattern>
</servlet-mapping>
I reference it via:
<form action="hi" method="POST">
This works fine.

web.xml and pom.xml documentation

I need documentation about web.xml and pom.xml files. i would like learn web develop, so i start some tutorials about that. I use IDE eclipse and i choose the option maven project for develop the tutorials. i dont have errors but i cant deploy the projects in web. May be my problems are that i not understand in totality the concept of this files. Some documentation about this i sure that help me. I searched in Satck, in foros but i dont found documentation. I wonder how web developers know the code they need these files
web.xml is web application configuration file defines the servlet container used in the application. You can typically add start-up code, url-pattern as this will be called on application start. Example below extracted from Jersey RestFull service.
<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_3_0.xsd"
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">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.xxxx.shopper</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>com.xxxx.shopper.service.Startup</listener-class>
</listener>
</web-app>
pom.xml is maven configuration file defines build process and loads any dependencies.
Good Reads:
1. https://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
2. Difference between web projects with pom.xml and web.xml
3. Why do we use web.xml?

Java EE 404 Error on XHTML but Not HTML

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.

Servlet cannot be resolved in web.xml

For some reason idea lights dispatcher servlet and when I launch tomcat get the 404 error. I`m using spring mvc and Maven, here is the picture of web.xml
Appreciate every answer=)
webapp/web.xml
<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_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Found the problem, was using the tomcat7-maven-plugin with compile version of maven-compiler-plugin 1.8, after changing it to 1.7 the problem gone.
However is there any similar solutions to tomcat7-maven-plugin?, cause I didnt find tomcat8-maven-plugin in internet
Thanks everyone for participation
Open settings below:
Project settings -> Facets -> Web -> Deployment Descriptors
check the path here and ensure it's available. If not, click the green + to add your web module path.
You need to add servlet mapping also and then add spring-webmvc-version.jar in classpath
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I was having this same problem. It turned out that I was using an old companies settings.xml file for Maven user settings file. If someone is having this problem try using the Maven template users file.
Add spring mvc.jar file (if you are using spring and mvc) to the class libraries
Make sure that [name]-sevlet.xml file is set properly.
use name inside the "sevlet-name" name "servlet-name" in the web.xml.
I add the path for Web module. Using Intellij click project structure and then select Facets. Deployment Descriptors probably must be empty(its not good), so add the path.

appengine java development server displaying source code

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

Categories