aspose file tools*
The moose likes JSF and the fly likes what url to use? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "what url to use?" Watch "what url to use?" New topic
Author

what url to use?

tun lynn
Greenhorn

Joined: Apr 26, 2012
Posts: 3
I have a JSF Simple Login Applicationfrom roseindia...

http://www.roseindia.net/jsf/JSFLoginApplication.shtml

here is the web.xml for mapping...

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>

<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

one would think ....the usual stuff..

after making a war file, I deploy it to the tomcat7 server...

I tried accessing with url: http://localhost:8080/hello/login.jsp (here, the app name is called "hello" ..it doesn't matter what I called)

I am getting:
root cause
java.lang.RuntimeException: Cannot find FacesContext

and the message:

org.apache.jasper.JasperException: An exception occurred processing JSP page /login.jsp at line 5

2: <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
3: <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
4:
5: <f:view>
6: <html>
7: <head><title>JSF Simple Login Example</title></head>
8:


can anybody help me which url to use for invoking the web app and the suggest any setting for the web.xml mapping??


Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 200

Look in your web.xml. I took a look at the one on the site you linked to, so I assume you're using their web.xml.

You're mapping the Faces Servlet:



So your url should match that pattern in order to tell the Faces Servlet to handle the request.

http://localhost:8080/hello/login.jsf

Note the use of "jsf" instead of "jsp"
tun lynn
Greenhorn

Joined: Apr 26, 2012
Posts: 3
first of all, thanks for taking time to look at it and replying to me...

yes, I did try that as well, in fact, I tried like
1) /*
2) *.jsp
3) *.jsf
4) /faces/*....etc in my web.xml

and my url would look something like

http://localhost:8080:/hello/faces/login.jsp (or) jsf...
but sor some reason it still doesn't work...

something wrong in the url-pattern (in web.xml) & the way I am invoking the application??...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16014
    
  20

Well, some would say that your first mistake was in employing RoseIndia, but that's just mean. RoseIndia used to be an excellent resource. It just happens to have gone dramatically downhill is all.

Myself, I'd normally go on a rant about why coding your own logins instead of using the J2EE security system is a bad idea, but you have deeper issues to resolve, first.

You don't want "/*" as a URL pattern for any servlet, whether it's the FacesServlet or a completely non-JSF app. The URL pattern is going to match ALL incoming URLs, and that includes the image URLs, the JavaScript URLs, and so forth. You don't want them running through the FacesServlet, because it cannot handle them. You only want JSF view requests and postbacks to go through the FacesServlet.

Thus, a lot of people like to use the URL pattern "/faces/*", but I prefer "*.jsf", myself.

Your biggest problem - aside from the fact that you're using the old outdated JSP tag form of JSF View Definition is that you're making the common mistake of confusing resource paths and URLs.

Resource paths are relative file paths within a WAR. URLS have the same basic syntax, but they're simply locator strings that are decoded and applied by the logic in the web application.

Clients cannot directly request resources. They can only make URL requests. The logic in the webapp receives the URL request, decodes it, and often (not always) uses that information to copy out one or more resources to the HTTP response output stream. There's a default servlet that's part of the webapp server which can take things like image file URLs such as "http://myhost:8080/myapp/images/pic1.jpg", convert it to the resource path "/images/pic1.jpg" and serve up the resource located at that place in the WAR. Likewise, the default processor will take URLs that end with ".jsp", look for a corresponding JSP resource and compile and execute the JSP file.

For more complex matters like JSF, the FacesServlet intercepts matching URLs. In the case where the FacesServlet URL pattern is "*.jsf", the URL is converted from something like "http://myhost:8080/myapp/facesview.jsf" into a resource path of "/facesview.jsp". The FacesServlet then reads /facesview.jsp, digests it to produce a JSF component tree it, runs through the JSF lifecycle, and uses the updated component tree to generate the HTML that gets sent back to the client. In JSF2 and enhanced JSF1 webapps, an additional subsystem may be employed that looks to see if there's a resource named "/facesview.xhtml" and if there is, it gets digested and processed by the FacesServlet which then employs the additional enhancements that the Facelets subsystem adds.

The FacesContext is not a "permanent" object. It will not exist unless the FacesServlet is actively processing a request and each request gets a FacesContext created just for its own use. Once the request has been processed, that FacesContext is destroyed. If you make a non-JSF URL request, for example "http://myhost:8080/myapp/facesview.jsp", that URL won't match the "*.jsf" URL filter and won't be routed to the FacesServlet, so a FacesContext won't be created.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
wood burning stoves
 
subject: what url to use?