Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How-to get the JSF application context path?

195661Oct 7 2005 — edited Oct 17 2005
I want to do a redirect from within a JSF backing bean. How do I get the application context path?

I plan to do this in the constructor of the backing beans in order to validate the user has previously logged in.

public BackingBeanName()
{
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = HttpSession)facesContext.getExternalContext().getSession(false);
HttpServletRequest request = (HttpServletRequest)facesContext.getExternalContext().getRequest();
userid = (String)session.getAttribute("userid");
if (userid == null) {
logger.info("userid attribute is not in session");
ExternalContext ec = facesContext.getExternalContext();
appContextPath = ???????????????????????;
String redirectTo = appContextPath + "/logon.jsp";
try {
ec.redirect(redirectTo);
}
catch (IOException e) {
String msg = "redirect to " + redirectTo + " failed";
logger.severe(msg);
return; // throw an exception instead of return;
}
}
}

Regards,
Al Malin
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 14 2005
Added on Oct 7 2005
4 comments
2,555 views