Posts

Showing posts with the label Struts

Custom Request Processor in Struts

I assume that you know the basics of struts and you are using lower version than that of struts 2.0. Struts is a powerful MVC framework which can be extended to do some excellent work. There may be situations where you need some regular works at every actions. Such as validating the user, checking his/her roles, log user activities etc. Struts provides a way for that. ActionServlet is the only servlet in Struts. Before redirecting to the programmer's action, ActionServlet creates an object of RequestProcessor. The RequestProcessor class in the Struts distribution provides a default implementation for each of the request-processing steps. That means you can override only the methods that interest you, and use default implementations for rest of the methods. The processPreprocess method in RequestProcessor can be overridden to do some common tasks such as 1. Validating User Session 2. Validating User Role 3. Putting Action Form's Data Into User Log Table. You have to do...

Preventing Duplicate Form Submission in Struts using TOKEN

Duplicate form submission may occur in the following situations:- Using Refresh button Using the browser back button to traverse back and resubmit form Using Browser history feature and re-submit form. Malicious submissions to adversely impact the server or personal gains Clicking more than once on a transaction that take longer than usual What happens in form submission? Suppose you have a form named adduser.jsp and an Action named saveUser.do. So, on clicking submit in the adduser.jsp page struts finds the mapping saveUser.do and redirect to this url. So, in the browser url you will find /app/saveUser.do. and when you click on refresh same url is called and same form is submitted again. Struts provides several ways to protect this. HTTP redirect after form submission using TOKEN HTTP redirect Suppose form submission result is shown in a page called success.jsp. So, if redirect is set true in forward of action in struts.config URL in the URL bar becomes /app/success.j...