Click to See Complete Forum and Search --> : redirecting from servlet
jrthor2
08-20-2008, 03:42 PM
I am trying to do a redirect from a logout servlet, where it takes a parameter passed in and logs the user out, and if the parameter is not null or blank, redirect to that parameter. It seems to work if my parameter is /contextroot/page.jsf. It fails when the parameter value is /contextroot/directory/page.jsf. Here is the code to redirect:
if ((null != redirectPage) || ("".equalsIgnoreCase(redirectPage))) {
logger.debug("we have a redirect page");
response.sendRedirect(redirectPage);
}
Khalid Ali
08-20-2008, 11:00 PM
First of all please post the actual error that you might get,
second this method takes in relative url value, my first guess will be that
does the directory name contain a space?
jrthor2
08-21-2008, 08:09 AM
No, there are no spaces in the directory. Here is part of the error. It appears to be trying to go to /index.jsp, but that's not th value of my redirectPage.
[8/21/08 8:04:32:353 EDT] 00000022 jsf E com.sun.faces.application.ApplicationAssociate createAndMaybeStoreManagedBeans Can't instantiate class: 'com.xxx.home.Index'.. class com.xxx.home.Index : javax.faces.el.EvaluationException: java.lang.IllegalStateException
javax.faces.FacesException: Can't instantiate class: 'com.xxx.home.Index'.. class com.xxx.home.Index : javax.faces.el.EvaluationException: java.lang.IllegalStateException
at com.sun.faces.config.ManagedBeanFactory.newInstance(ManagedBeanFactory.java:232)
at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate. java:291)
at com.sun.faces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:81)
at com.ibm.faces.databind.SelectItemsVarResolver.resolveVariable(SelectItemsVarResolver.java:40)
at com.ibm.faces.databind.SelectItemsVarResolver.resolveVariable(SelectItemsVarResolver.java:40)
at com.sun.faces.el.impl.NamedValue.evaluate(NamedValue.java:125)
at com.sun.faces.el.impl.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:249)
at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:140)
at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:123)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:124)
at com.ibm.faces.renderkit.html_extended.ScriptCollectorRenderer.encodeBegin(ScriptCollectorRenderer.ja va:62)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:717)
at javax.faces.webapp.UIComponentTag.encodeBegin(UIComponentTag.java:595)
at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:482)
at com.ibm.faces.taglib.html_extended.ScriptCollectorTag.doStartTag(ScriptCollectorTag.java:109)
at com.ibm._jsp._index._jspx_meth_hx_scriptCollector_0(_index.java:816)
at com.ibm._jsp._index._jspx_meth_f_view_0(_index.java:921)
at com.ibm._jsp._index._jspService(_index.java:82)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:87)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:989)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:930)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:118)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:766)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:674)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:498)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:464)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:12 2)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtension ServletWrapper.java:225)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:321)
at com.ibm.faces.context.MultipartExternalContextImpl.dispatch(MultipartExternalContextImpl.java:411)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:257)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:220)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:989)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:930)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
at com.xxx.raweb.web.util.TimerFilter.doFilter(TimerFilter.java:50)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:186)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
at com.xxx.util.Log4jMDCFilter.doFilter(Log4jMDCFilter.java:70)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:186)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
at com.xxx.raweb.web.util.RequestDumpFilter.doFilter(RequestDumpFilter.java:191)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:186)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:766)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:674)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:498)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:464)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:321)
at com.ibm.ws.webcontainer.servlet.FilterProxyServlet.dispatch(FilterProxyServlet.java:73)
at com.ibm.ws.webcontainer.servlet.FilterProxyServlet.service(FilterProxyServlet.java:52)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:989)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:930)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:118)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:766)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:674)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:689)
at com.ibm.ws.wswebcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:101)
at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.invokeFilters(DefaultExtensionProcessor. java:791)
at com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor. java:563)
at com.ibm.ws.wswebcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcesso r.java:113)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3276)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:113)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:383)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java :165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
Caused by: java.lang.ClassNotFoundException: class com.xxx.home.Index : javax.faces.el.EvaluationException: java.lang.IllegalStateException
at java.beans.Beans.instantiate(Beans.java:223)
at java.beans.Beans.instantiate(Beans.java:63)
at com.sun.faces.config.ManagedBeanFactory.newInstance(ManagedBeanFactory.java:226)
... 83 more
chazzy
08-21-2008, 09:58 AM
it looks like you're writing a JSF app. what does your directory structure look like?
jrthor2
08-21-2008, 11:57 AM
Yes, we have a jsf application. The directory structure looks like this:
WebContent
/directory1/
main.jsf
/directory2/
main.jsf
profile.jsf
If I log in, and then click my logout link, logout works fine. If I login, and go to say /directory1/main.jsf and logout, it fails, and from the exception, it appears it's trying to go to /index. What happens is when you click logout, it hits our LougoutSerlet.java file. That file logs the user out, then does a redirect to the page they were on. If the page they were previously on is what we consider a "protected" page, meaning, you have to be logged in to see it, it goes through our SessionFilter.java. The problem though, is on certain pages it's not hitting my Session Filter at all, it goes straight to the exception.
chazzy
08-21-2008, 01:48 PM
what do your navigation rules look like? and by directory structure, i was looking for /web-inf/lib and web-inf/classes setup. you might also have a managed bean defined wrong. i don't know why you think it's going to your index page, but it does look like it's trying to access a managed bean defined by an "Index" class and failing there.
Khalid Ali
08-21-2008, 09:02 PM
Here is text for servlet api for sendRedirect method
"If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to."
And take a look at your exception there are 2 main things to look at.
1. See how your logic might be working when you send a redirect,
2. second make sure all the classes are there which are being accessed, last part of the exception says this
"Caused by: java.lang.ClassNotFoundException: class com.xxx.home.Index : javax.faces.el.EvaluationException: java.lang.IllegalStateException
at java.beans.Beans.instantiate(Beans.java:223)
at java.beans.Beans.instantiate(Beans.java:63)
at com.sun.faces.config.ManagedBeanFactory.newInstance(ManagedBeanFactory.java:226)
"
jrthor2
08-22-2008, 01:17 PM
I got my issue fixed. For some reason, the pages that would not logout had a <base href> set in the header that was messing things up. I removed that and it is working fine.