Solved

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

Posted on 2004-10-08
3
3,154 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
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now