• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to redirect to other URL ?  RSS feed

 
pingkan paula
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to struts, I got a task in which i must redirect to other website when a user log out
This is the code which extends TilesRequestProcessor, can anyone give me some clue where in this code i should put a line to redirect user to other url? Any feedbacks will be fully appreciated

code:

public class SmukAntamRequestProcessor extends TilesRequestProcessor {

protected boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) {
boolean continueProcessing = true;
if (request.getServletPath().equals("/loginInput.do")
|| request.getServletPath().equals("/login.do"))
return true;
HttpSession session = request.getSession();
//Check if userName attribute is there is session.
//If so, it means user has allready logged in
if (session != null &&
session.getAttribute(AppSmukConstants.SESS_USER_NAME) != null)
return true;
else {
try {
//If no redirect user to login Page
request.getRequestDispatcher
("/login.do").forward(request, response);
} catch (Exception ex) {
}
}
return false;

}

protected boolean processRoles(HttpServletRequest request,
HttpServletResponse response,
ActionMapping mapping)
throws IOException, ServletException {
// Is this action protected by role requirements?
String roles[] = mapping.getRoleNames();
if ((roles == null) || (roles.length < 1)) {
return (true);
}

HttpSession session = request.getSession();
if (session == null) return (false);
List rolesInSession = (List) session.getAttribute(AppSmukConstants.SESS_USER_ROLE);

// Check the current user against the list of required roles
for (int i = 0; i < roles.length; i++) {
if (rolesInSession.contains(roles[i]) ) {
if (log.isDebugEnabled()) {
log.debug(" User '" + request.getRemoteUser() +
"' has role '" + roles[i] + "', granting access");
}
return (true);
}
}

// The current user is not authorized for this action
if (log.isDebugEnabled()) {
log.debug(" User '" + request.getRemoteUser() +
"' does not have any required role, denying access");
}

response.sendError(
HttpServletResponse.SC_FORBIDDEN,
getInternal().getMessage("notAuthorized", mapping.getPath()));

return (false);

}
}
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to extend the RequestProcessor just to redirect to a different site when the user logs out.

Just create a forward specifying the full URL of the link you want to forward to (including the HTTP://) and specify redirect="true". Then just find the forward and return it from the execute() method of your logout action as you would with any forward.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!