nightin_gale
nightin_gale

Reputation: 831

Using JSF instead of JSP in WebApplication in IDEA

I am geting used to be Java programmer, and I've just taught servlets. But IDEA ctreates index.jsp, when I choose "Create Web Application". I've run into one article where found out from about JSF. It was described as a better and newest version of WebApp desiging. I've written a project where index.jsp are used (web->src->main->webapp) inside this path. It was created by IDEA. Now I wanna substitude JSP with XHTML. I've done it, assebled my project and deployed. But when I go to

localhost:8080/web/

I see nothing. When I use "index.JSP", I can see content of my JSP-page. Please, help me to correct my project. What should I do?

Upvotes: 0

Views: 572

Answers (1)

Happy
Happy

Reputation: 1855

In order to make JSF working, you have some configuration to do:

  • Make sure you have a faces-config.xml at the same level as WEB-INF folder, containing this for JSF 2.0:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config 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-facesconfig_2_0.xsd"
        version="2.0">
</faces-config>
  • JSF uses a servlet provided by Java EE, javax.faces.webapp.FacesServlet. You must add some elements into your web.xml, to declare this servlet:
<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>

Using this configuration, you must put your JSF at the same level as WEB-INF and give them the extension .xhtml. Of course you can set the pattern.

JSF is not only make to replace JSF files. This is a big framework which allow you to write only the business logic. You will need to learn more about JSF before using it. Take a look right here.

Upvotes: 2

Related Questions