N
Nathan Given
Hello Everyone,
I am a newbie struts programmer... I have programmed jsps and
servlets without struts before using the Front Controller pattern, but
now I am trying out something new.
On my login page I have a checkbox, if it is checked, I want to print
out some extra information on the logged in page; if it is not
checked, I don't want to print out that extra info.
The problem I am having is that I am using the request object to store
the information ( like this: request.setAttribute("extra_info","Hello
New User") )
But, on the page, when I use request.getAttribute("extra_info") it
comes out null.
Here are some code snippets...
----LoginAction class-------
execute(ActionMapping actionMapping, ActionForm actionForm,
HttpServletRequest request, HttpServletResponse response) throws
Exception {
....
//if the passwords match...
//get the session
HttpSession session = request.getSession(true);
//set the user object to the session
session.setAttribute("user", user);
if(((LoginForm)actionForm).getCheckzip()){
//run the zip code stuff
...
request.setAttribute("checkzip","yes");
} else {
System.out.println("LoginAction: setting checkzip to no");
request.setAttribute("checkzip","no");
}//if else
return actionMapping.findForward(target);
} //end execute method
------------ end login action class --------------
As you can see, I set "checkzip" with the string value of "yes" using
request.setAttribute() if the box is checked, and "no" if the the
check box is not checked.
---------- struts-config.xml ---------------
<struts-config>
<form-beans>
<form-bean name="loginForm"
type="edu.byu.cid.ssp.bank.LoginForm" />
</form-beans>
<action-mappings>
<action path="/login" type="edu.byu.cid.ssp.bank.LoginAction"
name="loginForm" input="/login.jsp" validate="true" scope="request">
<forward name="success" path="/welcome.jsp" redirect="true"
/>
<forward name="failure" path="/login.jsp" />
</action>
</action-mappings>
</struts-config>
-------- end struts-config.xml -------------
So, on successful login, the user should be redirected to welcome.jsp.
On welcome.jsp I have the following...
------------ welcome.jsp ----------------
<%= request.getAttribute("checkzip") %>
----------- end snippet -------------------
that always comes out null, always. It should at least come out "yes"
or "no" right?
I've done this using the Front Controller pattern, and the last couple
of lines line in my Controller.java file was
RequestDispatcher dispatcher =
request.getRequestDispatcher("/welcome.jsp");
dispatcher.forward(request, response);
Thanks!
I am a newbie struts programmer... I have programmed jsps and
servlets without struts before using the Front Controller pattern, but
now I am trying out something new.
On my login page I have a checkbox, if it is checked, I want to print
out some extra information on the logged in page; if it is not
checked, I don't want to print out that extra info.
The problem I am having is that I am using the request object to store
the information ( like this: request.setAttribute("extra_info","Hello
New User") )
But, on the page, when I use request.getAttribute("extra_info") it
comes out null.
Here are some code snippets...
----LoginAction class-------
execute(ActionMapping actionMapping, ActionForm actionForm,
HttpServletRequest request, HttpServletResponse response) throws
Exception {
....
//if the passwords match...
//get the session
HttpSession session = request.getSession(true);
//set the user object to the session
session.setAttribute("user", user);
if(((LoginForm)actionForm).getCheckzip()){
//run the zip code stuff
...
request.setAttribute("checkzip","yes");
} else {
System.out.println("LoginAction: setting checkzip to no");
request.setAttribute("checkzip","no");
}//if else
return actionMapping.findForward(target);
} //end execute method
------------ end login action class --------------
As you can see, I set "checkzip" with the string value of "yes" using
request.setAttribute() if the box is checked, and "no" if the the
check box is not checked.
---------- struts-config.xml ---------------
<struts-config>
<form-beans>
<form-bean name="loginForm"
type="edu.byu.cid.ssp.bank.LoginForm" />
</form-beans>
<action-mappings>
<action path="/login" type="edu.byu.cid.ssp.bank.LoginAction"
name="loginForm" input="/login.jsp" validate="true" scope="request">
<forward name="success" path="/welcome.jsp" redirect="true"
/>
<forward name="failure" path="/login.jsp" />
</action>
</action-mappings>
</struts-config>
-------- end struts-config.xml -------------
So, on successful login, the user should be redirected to welcome.jsp.
On welcome.jsp I have the following...
------------ welcome.jsp ----------------
<%= request.getAttribute("checkzip") %>
----------- end snippet -------------------
that always comes out null, always. It should at least come out "yes"
or "no" right?
I've done this using the Front Controller pattern, and the last couple
of lines line in my Controller.java file was
RequestDispatcher dispatcher =
request.getRequestDispatcher("/welcome.jsp");
dispatcher.forward(request, response);
Thanks!