1

I have wrote some methods to achieve Struts 1 functions in Struts 2

Struts 1 ActionForward:

new ActionForward("/home/ShowPage.do?page=edit",true);

Same I did in Struts 2:

public String myActionForward(String url,boolean isRedirect) throws Exception
{
    if(isRedirect){
        response.sendRedirect(url);
    }else{
        RequestDispatcher rd = request.getRequestDispatcher(url);
        rd.forward(request, response);
    }
    return null;
}
myActionForward("/home/ShowPage.do?page=edit",true);

Struts 1: To get result path:

String url = mapping.findForward(result).getPath();

Same I did in Struts 2:

public String myGetPath(String result) throws Exception
{
    Map<String,ResultConfig> results = ActionContext.getContext().getActionInvocation().getProxy().getConfig().getResults();
    ResultConfig rc = results.get(result);
    String path = rc.getParams().get("location");
    return path;
}

String url = myGetPath(result);

Like that I have wrote some alternative methods in Struts 2.

The above alternative methods are working fine. But I need to know, are these methods make any problem in future or I need to change anything in above methods to achieve the same as in Struts 1.

Roman C
  • 49,761
  • 33
  • 66
  • 176
john
  • 859
  • 2
  • 12
  • 25

1 Answers1

2

You should use Struts2 Result implementation instead of using servlet stuff directly until you know what are you doing. There's redirect or redirectAction, and dispatcher result types that should be used instead of direct servlet API. Struts might wrap the servlet stuff for some feature change and you might get not working code in the future.

The second method is valid because it uses Struts2 API. However, you need to look how to create URLs programmatically in the actions from ActionMapping.

Community
  • 1
  • 1
Roman C
  • 49,761
  • 33
  • 66
  • 176