Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
tomcat users xml 7 129
getting param value 7 58
spring JDBC Template example error 26 289
null output 3 35
This article describes how to reset your Windows 10 password when you've forgotten it.
ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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