Hi!
From the following code, what does it mean if forward is null?
Why does this func passes string “forward”
request.getSession().getAttribute("forward");
+++++++++++++++++++++++++
public ActionForward create(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
…
…
String forward = (String) request.getSession().getAttribute("forward");
…
…
if (forward==null)
return (mapping.findForward(Constants.RETURN_TO_VIEW));
else
return (mapping.findForward(forward));
+++++++++++
thanks,
Well, 'forward' attribute is obtained from the session. So previously, there must be someone who already locate some value on that session and now you grab it (either from servlet, Struts class or etc). If the session is having no value, then it means null (nobody has ever locate some value on it or it has been set to empty).
So if the Java program know the 'forward' attribute is null, it will send your program into return (mapping.findForward(Const
That particular codes is Struts ActionForward which means that Constants.RETURN_TO_VIEW must contain some value to determine (probably in struts-config.xml) where to go if the session is null. Otherwise, mapping.findForward(forwar
So it works like a statement to determine to where your application should go.
I hope that helps.