Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ajax auto save 15 98
rebasing and merging used in SCM 1 66
java cigar challenge 58 206
How to find missing packages when using Netbeans IDE 8.1 ? 19 46
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

867 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

20 Experts available now in Live!

Get 1:1 Help Now