aspose file tools*
The moose likes JSP and the fly likes IllegalStateException of pageContext.forward( ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "IllegalStateException of pageContext.forward( )" Watch "IllegalStateException of pageContext.forward( )" New topic
Author

IllegalStateException of pageContext.forward( )

Stephen Lee
Ranch Hand

Joined: Dec 11, 2001
Posts: 74
I am now using Custom Tag Library for my jsp page. In the class which subclass the TagSupport, I have used pageContext.forward("xxx.jsp") to forward to another jsp for some cases. However, when I view the jsp file which has used the custom tag and foward to another page, a java.lang.IllegalStateException is thrown. I have checked the API, it said that this exception occurs if ServletResponse is not in a state where a forward can be performed. However, I do not understand the meaning!
However, the page is fowarded and there is not problem, I just see the error message in console.
Why is this exception thrown? Thanks!
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
Verify that you have not sent any output to the client before you called the forward method.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Stephen Lee
Ranch Hand

Joined: Dec 11, 2001
Posts: 74
I ensure that I have not sent any output to the client before I called the forward method.
The code is as followings:
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/app.tld" prefix="app" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<app:checkLogin/>
in the tag <app:checkLogin/> it has the forward method to the other jsp page.
Thanks!
Stephen
John Bateman
Ranch Hand

Joined: Mar 09, 2000
Posts: 320
Can you post the taglib code here too?
Thanks


SOURCE CODE should be SURROUNDED by "code" tags.
Stephen Lee
Ranch Hand

Joined: Dec 11, 2001
Posts: 74
The following is the code of app.tld:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>Application Tag Library</shortname>
<uri>http://jakarta.apache.org/taglibs/struts-example-1.0</uri>
<info>This tag library contains functionality specific to the Struts Example Application.</info>
<tag>
<name>checkLogin</name>
<tagclass>CheckLoginTag</tagclass>
<bodycontent>empty</bodycontent>
<info>Validate that there is a currently logged on user, by checking for
the existence of a session-scope bean under the specified name.
If there is no such bean, forward control to the specified page,
which will typically be a logon form.
name - Name of the session-scope bean to check for [user]
page - Context-relative path to the logon page [/logon.jsp]
</info>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>page</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>

While in the JSP file, I have deleted some code, it becomes:
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/app.tld" prefix="app" %>
<app:checkLogin/>
In the CheckLoginTag class, the code is as following:
public final class CheckLoginTag extends TagSupport {
private String name = Constants.USER_KEY;
private String page = "/loginPage";
public String getName() {
return (this.name);
}
public void setName(String name) {
this.name = name;
}
public String getPage() {
return (this.page);
}
public void setPage(String page) {
this.page = page;
}
public int doStartTag() throws JspException {
return (SKIP_BODY);
}
public int doEndTag() throws JspException {
boolean valid = false;
HttpSession session = pageContext.getSession();
if ((session != null) && (session.getAttribute(name) != null))
valid = true;
if (valid) {
return (EVAL_PAGE);
}
else {
try {
pageContext.forward(page);
} catch (Exception e) {
throw new JspException(e.toString());
}
return (SKIP_PAGE);
}
}
public void release() {
super.release();
this.name = Constants.USER_KEY;
this.page = "/loginPage";
}
}
This file is used to forward to the /loginPage. However, exception is thrown. Thanks!
Stephen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IllegalStateException of pageContext.forward( )
 
Similar Threads
Unable to generate error from Action class !
pageContext.forward
Custom tag: attribute cannot contain quote?
Problem relaying attributes between customa tag class and jsp
How to handle an Exception thrown in a Scriptlet in a .Tag File