How to send redirect from a tag?
Hello!I was thinking of developing a tag that could be implemented on some certain pages that only would be viewed if the user has logged in. If the user has not log in then the user should be re directed to the log in page.
I was thinking of something like this:
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
public class CheckLoginTag extends TagSupport
{
public int doStartTag() throws JspException
{
try
{
HttpSession session = pageContext.getSession();
if(session != null)
{
if(session.getAttribute("LOGGEDIN") != null)
{
if(!((String)session.getAttribute("LOGGEDIN")).equals("YES"))
{
((HttpServletResponse)pageContext.getResponse()).sendRedirect("/start.do");
}
}
else
{
((HttpServletResponse)pageContext.getResponse()).sendRedirect("/start.do");
}
}
else
{
((HttpServletResponse)pageContext.getResponse()).sendRedirect("/start.do");
}
}
catch (Exception e)
{
e.printStackTrace();
}
return SKIP_BODY;
}
}
But since a tag returns on the doStartTag-method I do not think that this is correct. I do not think it is correct to return after we have done a sendRedirect?
So if any one could advise me how to solve this correct please let me know.
Best regards
Fredrik
