tags:

views:

45

answers:

6

I am developing a java project.

I want to display an extention of any webpage as '.jsf' evenif it is 'jsp' or 'xhtml'.

What should I do?

A: 

You should configure your server to process .jsf files as .jsp pages. How to actually do this depends on the server you are using - an information you haven't provided.

Disclaimer: I'm not familiar with either jsf or jsp, so I don't know what consequences this server modification will have on actual jsf pages.

Kim L
This is not a server level configuration in servlet/jsp containers.
Lauri Lehtinen
A: 

Redirect all request to to the servlet that needs to handle the jsf requests

<servlet-mapping>
  <servlet-name>MyServlet</servlet-name>
  <url-pattern>*</url-pattern>
</servlet-mapping>
Redlab
A: 

STEPS (For new jsp project) :

  1. In web.xml, change to *.jsf

  2. Change to index.jsp

  3. Create new welcome.jsp

  4. In index.jsp page, include :

  1. Run project and see extention in browser.
Sarang
What is this? This doesn't look like an answer. If this is actually an update to your question, then you should have used the `edit` link.
BalusC
A: 

If this is for using JavaServer Faces, then the configuration of the JSF servlet enables the automatic mapping of .jsf to the underlying .xhtml or .jsp file.

Thorbjørn Ravn Andersen
+1  A: 

Then just configure the FacesServlet accordingly?

<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>

If you actually meant "I want to block direct access to *.jsp and *.xhtml so that the visitor is forced to invoke them by *.jsf", then add a security constraint to web.xml on the desired url-patterns and an empty auth-constraint:

<security-constraint>
    <display-name>Restrict direct access to JSP and XHTML files</display-name>
    <web-resource-collection>
        <web-resource-name>JSP and XHTML files</web-resource-name>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.xhtml</url-pattern>
    </web-resource-collection>
    <auth-constraint />
</security-constraint> 
BalusC
A: 

I think you have it the wrong way round.

The user-agent will make requests to your servlet, with a given URI identifying the resource they wish to access. You decide what the correct URI for a given resource is, and how to respond to this request. So it's conceptually not a case of your webpage having an "address" that you want to display differently. Rather, it's a case of what URIs you want to use to map to which resources.

If you don't want to expose the extension, then you don't need URIs to have any extension at all, they're just strings. You will, however, need to think about how to resolve potential name clashes (as djna notes in the comment). I believe that this is configured for you at the Faces level, and actually BalusC's answer should have all the technical information necessary to do this.

I just wanted to point out the backwards nature of your thought processes, clearing this up will hopefully make it easier to grok the process in general. It's better that you understand it, than simply paste something into your web.xml that makes the problem go away (for now).

Andrzej Doyle