Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use RequestProcessor? 1

Status
Not open for further replies.

jollyplay

Programmer
Dec 16, 2003
90
Hello

i heard that if we need to implement common code along action servlet, we can override processPreprocess method of RequestProcessor class. Could you please send me sample code or any link for the same and how to implement in our struts applicatin. Please do the needful.

Thank you.


Regards, balachandar
 
Hi,

RequestProcessor contains the processing logic for every servlet request from the container. The best example would be to check does the user login and has the username in session.

Code:
**
 * User: vreddy
 * Date: Aug 5, 2005
 * Time: 9:46:48 AM
 *
 * @author Venu Reddy <a href="mailto:venu_dvmr@yahoo.com">Venu Reddy</a>
 */
public class TestRequestProcessor extends RequestProcessor {

    protected boolean processPreprocess(HttpServletRequest request,
                                        HttpServletResponse response) {
        HttpSession session = request.getSession(false);
        //If user is trying to access login page
        // then don't check
        if (request.getServletPath().equals("/loginInput.do")
                || request.getServletPath().equals("/login.do"))
            return true;
        //Check if userName attribute is there is session.
        //If so, it means user has allready logged in
        if (session != null &&
                session.getAttribute("userName") != null)
            return true;
        else {
            try {
                //If no redirect user to login Page
                request.getRequestDispatcher
                        ("/Login.jsp").forward(request, response);
            } catch (Exception ex) {
            }
        }
        return false;
    }

    protected void processContent(HttpServletRequest request,
                                  HttpServletResponse response) {
        super.processContent(request, response);
    }
}

And in the struts-config.xml the mapping would be under

Code:
<controller>
    <set-property property="processorClass" value="TestRequestProcessor"/>
  </controller>

Hope this will help you.. for more details google..

Cheers
Venu
 
Dean venu,

Thank you for your reply. i got good understanding about this.

Regards,
balachandar.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top