aspose file tools*
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
Author

Redirect in tag lib ?

Haroldo Nascimento
Ranch Hand

Joined: Aug 14, 2003
Posts: 79
Hi,
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 java.io.IOException;
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 (this.name);
}

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

/**
* Retorna a pagina forward.
*/
public String getPage() {
return (this.page);
}

/**
* Define a forward page.
*
* @param page A nova forward page
*/
public void setPage(String page) {
this.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(
org.apache.struts.Globals.MODULE_KEY);
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();
this.name = "USER_VIEW";
this.page = "/form/login.jsp";
}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61233
    
  66

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirect in tag lib ?