Solved

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

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Let's recap what we learned from yesterday's Skyport Systems webinar.
Part Two of the two-part Q&A series with MalwareTech.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

627 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