You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matt Hughes <mh...@feith.com> on 2004/10/08 17:11:03 UTC

Upgrading Woes

Hi,

I just starting working on a project at work that is using a very old 
version of Struts (1.0).  Having used the newest version of Struts, I am 
desperate to upgrade this application to use the newest version, but I 
have fixed all I can fix without a little assistance.

The application has many custom tags and many of them are being used to 
do a forward.  For example, every page has a <loggedIn /> tag that makes 
sure the user is logged in, and if not redirects him to the login page.  
I know that's not using Struts to the best of its ability and it's 
something I look forward to changing in the future, but right now I just 
want to get my application to compile using the latest version of Struts.

Basically the problem is that inside the Tag code, they want to find an 
ActionForward.  This was written before you could have multiple 
ActionServlet's in Struts.  So how do I get an ActionForward that would 
give me the same result as the old ActionServlet.findForward(String 
name)  and how do I get there.  This is one peice of code that is breaking:

public class .... extends TagSupport {

....

    public boolean otherDoEndTagOperations() throws JspException {
       
        //Retrieve the ActionMappings saved in the ServletContext by 
Struts' ActionServlet
        //(see org.apache.struts.action.ActionServlet.initOther() ).
        //ModuleConfig config = 
TagUtils.getInstance().getModuleConfig(pageContext);
*      ActionMappings mappings = 
(ActionMappings)this.pageContext.getServletContext().getAttribute(Action.MAPPINGS_KEY);
*      ActionServlet servlet = mappings.getServlet();
        MessageResources resources = 
(MessageResources)this.pageContext.getServletContext().getAttribute(Action.MESSAGES_KEY);
        HttpServletRequest request = 
(HttpServletRequest)this.pageContext.getRequest();
        HttpServletResponse response = 
(HttpServletResponse)this.pageContext.getResponse();
        
if(!this.allowDirectAccess&&request.getAttribute(AdminAction.ADMIN_MAGIC)==null) 
{
            ActionForward forward = 
servlet.findForward(this.illegalAccessRedirect);
            try {
                if (forward == null) {
                    
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,resources.getMessage("tag.requestcheck.error.illegalredirect"));
                    return false;
                }
                processForward(forward, request, response);
            }catch(IOException e) {
                throw new JspException(e.getMessage());
            }
            return false;
        }

        HttpSession session = pageContext.getSession();
        
if(session==null||session.getAttribute(AdminConstants.SESSION_ADMIN_KEY)==null) 
{
            ActionUtils.saveRequestURLToSession(request);
            ActionForward forward = 
servlet.findForward(this.timeoutRedirect);
            try {
                if (forward == null) {
                    
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,resources.getMessage("tag.requestcheck.error.timeoutredirect"));
                    return false;
                }
                processForward(forward, (HttpServletRequest)request, 
(HttpServletResponse)response);
            }catch(IOException e) {
                throw new JspException(e.getMessage());
            }
            return false;
        }
        return true;
    }

    /**
     * This code is borrowed from 
org.apache.struts.action.ActionServlet.processActionForward().
     */
    protected void processForward(ActionForward forward, 
HttpServletRequest request,
    HttpServletResponse response) throws IOException {
       
        if (forward != null) {
            String path = forward.getPath();
            if (forward.getRedirect()) {
                if (path.startsWith("/"))
                    path = request.getContextPath() + path;
                response.sendRedirect(response.encodeRedirectURL(path));
            } else {
                __logger.debug("Forwarding to "+path);
                RequestDispatcher rd =
                pageContext.getServletContext().getRequestDispatcher(path);
                try {
                    rd.forward(request, response);
                }catch(ServletException e) {
                    __logger.error("", e);
                    throw new IOException(e.getMessage());
                }
            }
        }
    }
...

}

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Upgrading Woes

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
On 10/08/2004 04:11 PM Matt Hughes wrote:
> I just starting working on a project at work that is using a very old 
> version of Struts (1.0).  Having used the newest version of Struts, I am 
> desperate to upgrade this application to use the newest version, but I 
> have fixed all I can fix without a little assistance.
> 
> The application has many custom tags and many of them are being used to 
> do a forward.  For example, every page has a <loggedIn /> tag that makes 
> sure the user is logged in, and if not redirects him to the login page.  
> I know that's not using Struts to the best of its ability and it's 
> something I look forward to changing in the future, but right now I just 
> want to get my application to compile using the latest version of Struts.
> 
> Basically the problem is that inside the Tag code, they want to find an 
> ActionForward.  This was written before you could have multiple 
> ActionServlet's in Struts.  So how do I get an ActionForward that would 
> give me the same result as the old ActionServlet.findForward(String 
> name)  and how do I get there.  This is one peice of code that is breaking:

Matt,
you need the ActionMapping.findForward()

You'll have to work out how to get it in the JSP yourself though. 
Probably a Globals constant key to access it in the PageContext.

Adam
-- 
struts 1.2 + tomcat 5.0.19 + java 1.4.2
Linux 2.4.20 Debian


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org