Solved

(String) request.getSession().getAttribute("forward") returns null?

Posted on 2004-10-08
3
3,558 Views
Last Modified: 2006-11-17
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,
0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Assisted Solution

by:reginab
reginab earned 50 total points
ID: 12264034
if the string forward is null it mean the set of forward was unsuccessful with this (String) request.getSession().getAttribute("forward");

they check to ensure the request.getSession returned value, forward appears to be an attribute which is set elsewhere in the code, from the snippet I cannot really tell, though perhaps likely this is from some file where attributes are listed, a bean, an xml file, a properties file, one of those.  forward is a session attribute though so whereever you have those defined you will likely find forward there.
0
 
LVL 21

Assisted Solution

by:MogalManic
MogalManic earned 50 total points
ID: 12270488
The 'forward' attribute might be set on the request instead of the session.  Try this:
  String forward = (String) request.getAttribute("forward");
if the previous JSP page sets the variable you must specify the scope.  The scope can be three possible values:
   -Page - The variable can ONLY be accessed in the current JSP page (This is the default)
   -Request - The variable can be accessed in the current page, included pages and forwarded actions
   -Session - The variable can be accessed by ALL future pages by the same user
0
 
LVL 16

Accepted Solution

by:
suprapto45 earned 50 total points
ID: 12274185
Hi,

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(Constants.RETURN_TO_VIEW));
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(forward) will be used to determine the next location the program will go.

So it works like a statement to determine to where your application should go.

I hope that helps.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
We asked our MSP customer base what their favorite tools were and how they help them serve clients. We focused our questions on favorite tools in the following categories: >PSA tools >RMM tools >Alert management tools >Communication tools and Mo…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question