Forwarding and Redirecting

63 views
Skip to first unread message

anepally yadagiri

unread,
Sep 4, 2012, 9:46:57 AM9/4/12
to web4j...@googlegroups.com
Dear All,

Greetings for the day!!!

Based on some condition, I am forwarding and redirecting my request to another page.

Ex:

 if(verification.equals(verificationcode)){
                 setResponsePage(REDIRECT);
             }else{
                 setResponsePage(FORWARD);
             }

But it is always redirecting, The request is not forwarding.

Please let me know how to resolve this issue.

--
Thanks & Regards
Yadagiri,

Go Green : Think before you print this E-mail or its attachment. You can save a paper if you do  not really need to print.





John O'Hanley

unread,
Sep 4, 2012, 5:03:51 PM9/4/12
to web4j...@googlegroups.com
Please show more code. Please show how REDIRECT and FORWARD are defined.

- John

anepally yadagiri

unread,
Sep 5, 2012, 12:35:10 AM9/5/12
to web4j...@googlegroups.com
Hi John,

Following is the full code.

public class VerifycodeAction extends ActionTemplateListAndEdit {
   
    private static final Logger fLogger = Util.getLogger(VerifycodeAction.class);
    public static final SqlId CHECK_VERIFICATION_CODE = new SqlId("CHECK_VERIFICATION_CODE");
    public VerifycodeAction(RequestParser aRequestParser){
        super(FORWARD, REDIRECT, aRequestParser);
    }
   
    public static final RequestParameter SERIALNO = RequestParameter
    .withLengthCheck("serialno");
   public static final RequestParameter VERIFICATIONCODE = RequestParameter
    .withLengthCheck("verificationcode");
 
 
    @Override
    protected void attemptAdd() throws DAOException {
        // TODO Auto-generated method stub
        fLogger.info("In SignupAction serialnoAndVerificationCode().");
         serialno = getParam(SERIALNO);
         addToSession("serialno", serialno);
         verificationcode = getParam(VERIFICATIONCODE);
         try{
             fLogger.info("Serial No :"+serialno+" "+"Verification code :"+verificationcode);
             SafeText verification = utility.getSerialnoAndVerificationCodeCorrect(serialno);
             
             if(verification.equals(verificationcode)){
                 setResponsePage(REDIRECT);
             }else{
                 setResponsePage(FORWARD);
             }

         }catch(Exception e){
             e.printStackTrace();
         }
    }

    @Override
    protected void attemptChange() throws DAOException {
        // TODO Auto-generated method stub
       
    }

    @Override
    protected void attemptDelete() throws DAOException {
        // TODO Auto-generated method stub
       
    }

    @Override
    protected void attemptFetchForChange() throws DAOException {
        // TODO Auto-generated method stub
       
    }

    @Override
    protected void doList() throws DAOException {
        // TODO Auto-generated method stub
       
    }

    @Override
    protected void validateUserInput() {
        ModelFromRequest builder = new ModelFromRequest(getRequestParser());

        try {
            if (getErrors().isNotEmpty()) {
                return;
            }
            Lmodel = builder.build(Verifycode.class, SERIALNO, VERIFICATIONCODE);
        } catch (ModelCtorException ex) {
            addError(ex);
        }
    }
    boolean flag = true;
    SafeText serialno;
    SafeText verificationcode;
    Utility utility = new Utility();
    Verifycode Lmodel;
    VerifycodeDAO fverifycodeDAO = new VerifycodeDAO();
    /*private static ResponsePage FORWARD;*/
    private static final ResponsePage REDIRECT = new ResponsePage(
    "/pdt/main/patient/changepassword/ChangePasswordAction.list");

    private static ResponsePage FORWARD = LoginTemplatedPage.get(
    "Home", "view.jsp", VerifycodeAction.class);


Thanks
Yadagiri
On Wed, Sep 5, 2012 at 2:33 AM, John O'Hanley <webm...@javapractices.com> wrote:
Please show more code. Please show how REDIRECT and FORWARD are defined.


- John

--
You received this message because you are subscribed to the Google Groups "web4j-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/web4j-users/-/7q_8ah5QGiwJ.
To post to this group, send email to web4j...@googlegroups.com.
To unsubscribe from this group, send email to web4j-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/web4j-users?hl=en.

John O'Hanley

unread,
Sep 5, 2012, 8:17:24 PM9/5/12
to web4j...@googlegroups.com
I can't see anything which is obviously wrong.

Typically, the base class you're using expects you to use success/fail messages to control forward/redirect behavior - not to explicitly set the response page like that. Example:

http://www.web4j.com/predict/javadoc/src-html/hirondelle/predict/main/lists/PredictionListAction.html#line.26

Are you absolutely sure the data and boolean test are really causing the forward-ing line to be called?

Also note that the ResponsePage class has been updated, such that TemplatedPage helper classes are usually no longer needed.

- John

Reply all
Reply to author
Forward
0 new messages