• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirect in tag lib ?

 
Haroldo Nascimento
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64615
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic