1

I have a Primefaces+JSF web site whose home page is localhost:81/Mywebapp/login.jsf

I want to redirect the user to that home page if he goes to: localhost:81/Mywebapp/ so he doesnt need to write the complete URL.

How can I do that? I suppose it is some configuration in JBoss

Any help? thanks

Tony
  • 10,088
  • 20
  • 85
  • 139

3 Answers3

4

Actually it should be in your web.xmlfile, try to put to it's end this entry

<welcome-file-list>
    <welcome-file>/login.jsf</welcome-file>
</welcome-file-list>

EDIT

I also solved this once by making a new index.jsp like this

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
    <jsp:forward page="/login.jsf" />
</body>
</html>

Or put there a html file with this meta

 <meta http-equiv="Refresh" content= "0; URL=login.jsf"/>  

and set one of them as your welcome file. One of these solutions should do the job for you:-)

Petr Mensik
  • 26,874
  • 17
  • 90
  • 115
0

Sorry for the second answer, the formatting in the comments doesn't really cut it:

 <welcome-file-list>
            <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
...
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
...
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
        <url-pattern>*.jsf</url-pattern>
        <url-pattern>subdir/*</url-pattern>
    </servlet-mapping>

Peter's answer should work just fine, but if you're really concerned about the extensions (it doesn't really matter) then just add the places you want mapped under the servlet. This maps *.xhtml, *.jsf and anything under 'subdir/'.

If you had a hard file:
- index.xhtml

Myapp/index.xhtml and 
Myapp/index.jsf 
would map to the same file. xhtml is since your default suffix is xhtml

I hope this helps, honestly, with Primefaces 2 I'd definitely be using xhtml as that's the spec. With 3 it doesn't matter as much, but I still stay with xhtml as it isn't something I'd normally have on my server.

Best of luck (Petr's forwarding trick isn't a bad idea--it can really help in tough situations)

Daniel B. Chapman
  • 4,647
  • 32
  • 42
0

You can always do this with URL rewriting engines like PrettyFaces. You have to activate it in your web.xml and then define rewriting rules like this:

<url-mapping id="login">
  <pattern value="/login" />
  <view-id value="/legacy/user/login.xhtml" />
</url-mapping>

Because you mentioned explicitly login.jsf I think it's a good idea to think about including a security framework which is doing this (and many other things) for you. Seam security provides typesafe annotations for this:

@ViewConfig
public interface SeamPages
{
  static enum Pages0
  {
    @ViewPattern("/jsf/admin/important.xhtml")
    @UrlMapping(pattern="/admin/important")
    @LoginView("/jsf/access/loginRequired.xhtml")
    @AccessDeniedView("/jsf/access/accessDenied.xhtml")
    @RestrictAtPhase(PhaseIdType.RESTORE_VIEW)
    @LoggedIn
    ENUM0;
  }
}

This will solve three common requirements:

  • The URL /yourApp/admin/important will be redirected to the JSF page /jsf/admin/important.xhtml.
  • If the user is not @LoggedIn he will be redirect to /jsf/access/loginRequired.xhtml
  • IF the user does not have the rights to access the page he will be redirected to /jsf/access/accessDenied.xhtml
Thor
  • 6,607
  • 13
  • 62
  • 96