Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF - JasperException

 
John teras
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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

8:
9: </head>
10: <body>
11: <f:view>
12: <center>

13:

14:



Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find FacesContext
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.jsp.data_jsp._jspService(data_jsp.java:93)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

javax.servlet.jsp.JspException: Cannot find FacesContext
javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:399)
com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:105)
org.apache.jsp.jsp.data_jsp._jspx_meth_f_005fview_005f0(data_jsp.java:108)
org.apache.jsp.jsp.data_jsp._jspService(data_jsp.java:82)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Can somebody let me know the solution for this exception
 
Tomasz Lipinski
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you open your page using jsp or jsf extension? I think there is the problem. File name is data.jsp but if you want JSF to open it type data.jsf in address field.
 
John teras
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extension is jsp. I have used the JSF tags libray in the jsp page. And on"<f:view>", Container throws exception.
 
Tomasz Lipinski
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok your file is named data.jsp, that's ok, but what do you type in your address field? It should be something like http://localhost:8080/data.jsf . jsf at the end, not jsp!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amitgggggggg,

We don't have a whole lot of rules here at the JavaRanch, but one we do insist on is that you use a real name. I know that there's a good chance someone's already using a name like "Amit Gupta", but could you try and come up with something a little more professional-looking? Thanks!

JSF can only managed by the FacesServlet. That means that in your web.xml file, you need to have defined an instance of the FacesServelt and set up a URL mapping to route the JSF page requests to it. The routing part is essential, because unlike a lot of the old-time desktop frameworks, JSF isn't in continuous control of the application - you can mix JSF, plain old JSP, Struts and custom servlets all in the same app.
 
John teras
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done all the configuration in both web.xml and faces-config.xml. Below code for web.xml:

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>

Mapping are correct. Can anybody let me know, In which scenarios, JasperException comes?

Thanks...!
 
Tomasz Lipinski
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I assumed that you have *.jsf url-pattern in your mapping. In this case you should either open page using data.faces or change pattern to whatever you like best.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jasper is the JSP compiler. Your exception was thrown because the JSP tag processors generated a reference to the FacesContext object, but that object only gets created when the page was processed by the FacesServlet. It gets created and destroyed for each HTTP request.

Your URL pattern only routes URLs ending with ".faces". So to route properly, your URL would have to be /jsp/data.faces . This would cause the URL to get routed to the FacesServlet, which would then decode it, replacing the ".faces" with ".jsp" and process your faces.jsp page properly.
 
John teras
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Tim, Its working
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic