aspose file tools*
The moose likes JSF and the fly likes getting exception in JSF Tutorial of JR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "getting exception in JSF Tutorial of JR" Watch "getting exception in JSF Tutorial of JR" New topic
Author

getting exception in JSF Tutorial of JR

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I copied all the files as it is, explained in JSF Tutorial of JR, but getting this exception:





Thanks.
Awais Sheikh
Ranch Hand

Joined: Jun 07, 2006
Posts: 48
Have you set your class path?? Please place these files in lib folder of tomcat and include these jar files in your class path.

servlet-api.jar
jsp-api.jar
jsf-api.jar
jsf-impl.jar

Hope it works.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Awais Sheikh:
Have you set your class path?? Please place these files in lib folder of tomcat and include these jar files in your class path.

servlet-api.jar
jsp-api.jar
jsf-api.jar
jsf-impl.jar

Hope it works.


I have these files in class path.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Even when I try to view this simple JSP, I get exception:



It shows that, even f:view is not working... what could be the reason, I have both the JAR files required by JSF in class path.



Thanks.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I managed to handle second example (simple jsp file), but finding very surprise behaviour:

1. I created one more file, test.faces (name of jsp file is also test (test.jsp)), which has the same code of jsp file (test.jsp)

2. I changed mapping in web.xml like this:



Now, I am able to see the output of test.jsp when I open test.faces (http://localhost:8081/JSFLogin/pages/test.faces).

If I try to view jsp file (http://localhost:8081/JSFLogin/pages/test.jsp), then I get this exception:





And If I change test.jsp and keep test.faces as it is, and I open test.faces, then I can see the changes done by me (so actually it is the output of jsp file but still browser has this URL: http://localhost:8081/JSFLogin/pages/test.faces)


very-very confused.


Thanks.
[ July 06, 2006: Message edited by: rathi ji ]
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by rathi ji:
I managed to handle second example (simple jsp file), but finding very surprise behaviour:

1. I created one more file, test.faces (name of jsp file is also test (test.jsp)), which has the same code of jsp file (test.jsp)

2. I changed mapping in web.xml like this:



Now, I am able to see the output of test.jsp when I open test.faces (http://localhost:8081/JSFLogin/pages/test.faces).

If I try to view jsp file (http://localhost:8081/JSFLogin/pages/test.jsp), then I get this exception:





And If I change test.jsp and keep test.faces as it is, and I open test.faces, then I can see the changes done by me (so actually it is the output of jsp file but still browser has this URL: http://localhost:8081/JSFLogin/pages/test.faces)


very-very confused.


Thanks.

[ July 06, 2006: Message edited by: rathi ji ]


I can guess, what's actually happening:

A JSF page, has to be viewd from FacesServlet. So when I try to view test.jsp, I get exception because there is no such mapping for *.jsp files.

When I see test.faces in browser, it actually calls FacesServlet service() method, and in that service() method, service() method of test.java (something similer to that) is called (there is some logic written in FacesServlet, which sees the file name (in my case, test) and calls a class which has this name)... now the test.java is actually generated from test.jsp so content of this jsp file is rendered on browser...

Does it making any sense???
:roll:
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

That first step is the hardest, isn't it?

Let's see if I can help.

First, define your JSF pages as ".jsp" files, except that you'll need an <f:view> in them to wrap the JSF tags.

Next, setup a URL mapping in web.xml:


Some prefer "/faces/" as part of the URL pattern.

Now build a WAR and fire up the webapp. To get the JSF rendition of "hello.jsp", type in the URL: <a href="http://localhost:8080/mywebapp/hello.<b rel="nofollow">jsf</b>" target="_blank">http://localhost:8080/mywebapp/hello.jsf . Your URL may vary depending on host port and app context name.

If you invoke <a href="http://localhost:8080/mywebapp/hello.<b rel="nofollow">jsp</b>," target="_blank">http://localhost:8080/mywebapp/hello.jsp, you'll bypass the Faces servlet and get errors. The Faces servlet knows to drop the ".jsf" and add a ".jsp" when it goes to build the view page.


Customer surveys are for companies who didn't pay proper attention to begin with.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Tim Holloway:
That first step is the hardest, isn't it?

Let's see if I can help.

First, define your JSF pages as ".jsp" files, except that you'll need an <f:view> in them to wrap the JSF tags.

Next, setup a URL mapping in web.xml:


Some prefer "/faces/" as part of the URL pattern.

Now build a WAR and fire up the webapp. To get the JSF rendition of "hello.jsp", type in the URL: jsf[/b]]http://localhost:8080/mywebapp/hello.jsf . Your URL may vary depending on host port and app context name.

If you invoke jsp[/b],]http://localhost:8080/mywebapp/hello.jsp, you'll bypass the Faces servlet and get errors. The Faces servlet knows to drop the ".jsf" and add a ".jsp" when it goes to build the view page.


Thansk Tim.

I did what all you mentioned...

But when I access file with jsf extension (http://localhost:8081/JSFLogin/pages/test.jsf), container try to find test.jsp and gives '404 - page not found' exception. Because of the reason you given: "The Faces servlet knows to drop the ".jsf" and add a ".jsp" when it goes to build the view page"...


Awais Sheikh
Ranch Hand

Joined: Jun 07, 2006
Posts: 48
You can write your own extensions what ever u want as I am using my own names extensions. .

You wrote "Now, I am able to see the output of test.jsp when I open test.faces (http://localhost:8081/JSFLogin/pages/test.faces)".
You write test.faces instead of test.jsp because in mapping file you mentioned ".faces" extension in url-pattern.
Now, Mr. Tim used ".jsf" in url-pattern in web.xml thats why he wrote hello.jsf.
So, make it sure that you have changed in your web.xml file and restared your webserver after deploying war file.
Hope this will help you, if you have any other confusion feel free to ask.

Thanks,
Awais
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Awais Sheikh:
You can write your own extensions what ever u want as I am using my own names extensions. .

You wrote "Now, I am able to see the output of test.jsp when I open test.faces (http://localhost:8081/JSFLogin/pages/test.faces)".
You write test.faces instead of test.jsp because in mapping file you mentioned ".faces" extension in url-pattern.
Now, Mr. Tim used ".jsf" in url-pattern in web.xml thats why he wrote hello.jsf.
So, make it sure that you have changed in your web.xml file and restared your webserver after deploying war file.
Hope this will help you, if you have any other confusion feel free to ask.

Thanks,
Awais


Thanks Awais, I know this.

You read my previous post carefully, my doubt is different.
:roll:
nach mmmmm
Greenhorn

Joined: Apr 22, 2011
Posts: 1
hi, did you find the solution to this problem? I still don't get why the hello.jsf tries to find the hello.jsp ... let me know the solution if you know it.

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting exception in JSF Tutorial of JR
 
Similar Threads
Error while jsp connecting to database
Problem with resource bundle
java.lang.NullPointerException in Opening JSP fle
Journal Article - JavaServer Faces 1.0 Part I
Getting NumberFormat Exception