File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Redirect in tag lib ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Redirect in tag lib ?" Watch "Redirect in tag lib ?" New topic

Redirect in tag lib ?

Haroldo Nascimento
Ranch Hand

Joined: Aug 14, 2003
Posts: 79
How I can redirect my page jsp that belongs to another web application(the same web server)? I need to do ie in one taglib. I cant to use response.sendRedirect, because I cant to get HttpServletResponse, but only the ServletResponse.
The object is redirect to page login, when the user dont have session (login).
My code is it.
package com.upaid.struts.tag;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.config.ModuleConfig;
public final class CheckLogonTag extends TagSupport {

private String name = "USER_VIEW";
private String page = "../PortalWeb/form/login.jsp";
* Obtem o nome do Bean.
* @param name Bean
public String getName() {
return (;

* Define o nome do Bean.
* @param name Bean
public void setName(String name) { = name;

* Retorna a pagina forward.
public String getPage() {
return (;

* Define a forward page.
* @param page A nova forward page
public void setPage(String page) { = page;
public int doStartTag() throws JspException {
return (SKIP_BODY);
public int doEndTag() throws JspException {
// Existe um login valido ?
boolean valid = false;
HttpSession session = pageContext.getSession();

if ((session != null) && (session.getAttribute(name) != null)) {
valid = true;
// Forward direcionado com base do resultado
if (valid) {
return (EVAL_PAGE);
} else {
ModuleConfig config =
(ModuleConfig) pageContext.getServletContext().getAttribute(
try {

pageContext.forward(config.getPrefix() + page);

} catch (ServletException e) {
throw new JspException(e.toString());
} catch (IOException e) {
throw new JspException(e.toString());
return (SKIP_PAGE);

* Inicializa as variaveis.
public void release() {
super.release(); = "USER_VIEW"; = "/form/login.jsp";
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

I cant to use response.sendRedirect, because I cant to get HttpServletResponse, but only the ServletResponse.

Even though pageContext gives you ServletResponse, if you are using HTTP the object will be an instance of an HttpServletResponse (which extends Servlet response).
So you can upcast as in:

If you want to be absolutely sure, you can check with instanceof prior to the cast.
[ March 08, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Redirect in tag lib ?
It's not a secret anymore!