0

I'm so new for JavaServer Faces. I'm trying to create a project in Netbeans. (New Project >Java Web>Web Application). While creating I changed JSF Servlet URL Pattern.

It was like this:

demo

And I changed it as "*.jsf" then created. Netbeans edited web.xml file.

    <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<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>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>index.jsf</welcome-file>
</welcome-file-list>
</web-app>

But my index page is still xHTML.

index page

Lastly, when I run to file, IDE trying to open index.html and browser can't find index.HTML so I go index.jsf and page opens.

I've been searching for a while, I just find about people suggests editing to web.xml but its already edited. So do you have any suggestion?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • In your web.xml you have mapped the servlet with url *.jsf, it means that your pages are mapped with that extension. If you only want to access the pages with extension xhtml try to change *.jsf in *.xhtml. – SiMag Jul 13 '16 at 14:42
  • Actually I want to access the pages wtih extension jsf. But someway index.html not turn to index.jsf . and Its kinda problem. Why is still index.html ? Is it supposed to be index.html ? – Bilal Ekrem Harmanşa Jul 13 '16 at 14:48
  • If you want that index.html turn to index.jsf you have to add another url-pattern, see the Subodh Joshi [answer](http://stackoverflow.com/a/38355009/6546865) with the links he posted. – SiMag Jul 13 '16 at 14:58
  • Sorry for that comment. I made a word mistake. I even couldnt xhtml to html. so all I have is xhtml files and its default URL extension – Bilal Ekrem Harmanşa Jul 13 '16 at 15:22

1 Answers1

2

Then you can use below servlet-mapping

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

you can use more than one pattern as well please check below

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
    <url-pattern>*.jsf</url-pattern>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

For more and detail information you can check BalusC's evergreen answers for following questions.

For your question why its created index.html rather than index.xhtml you can check following link

it will tell you step by step process to create a JSF project and at last it creating index.xhtml page rather than index.html. So from this link you can get which step you missed in your case.

Please check below two screens

1. Step 1

enter image description here

2. Step 2

enter image description here

You can check highlighted(Yellow Color) text its extension is .XHTML and not .HTML

Community
  • 1
  • 1
Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
  • Well I am sorry for comment up there I made a mistake I was trying to write xhtml but I did html. It should be ----Actually I want to access the pages wtih extension jsf. But someway index.xhtml not turn to index.jsf . and Its kinda problem. Why is still index.xhtml ? Is it supposed to be index.xhtml ? ---- My index page is same as you. Its like picture you post it. But I want it as index.jsf . I am looking sites you post but i still couldnt get my answer maybe I miss out something idk :/ let me look it again – Bilal Ekrem Harmanşa Jul 13 '16 at 15:20
  • In your servlet mapping use `*.jsf` then you can access your page `abc.jsf` no issue if your actual page name is`abc.xhtml` .URL pattern use to call JSF servlet and process the JSF life cycle . – Subodh Joshi Jul 13 '16 at 15:35
  • Yes I can access. I was thinking why its still abc.xhtml in netbeans and thinking it must be abc.jsf in netbeans side too. So I guess I dont have problem I just didnt know its no issue being abc.xhtml I thought its a problem. Thank you for giving me time and sorry for wasting your time :( – Bilal Ekrem Harmanşa Jul 13 '16 at 15:39