Struts Portlet Redirect Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission from Liferay, Inc.
Objective The goal of this tutorial is to prevent multiple submits 1.Update existing JSP file –view.jsp 2.Add page flow path –struts-config.xml 3.Update Action to handle redirect –AddBookAction.java
view.jsp Add this hidden form field redirect" type="hidden" value=" ">
struts-config.xml Lets add /ext/library/success so that we have a landing path
AddBookAction.java We are going to modify our java to use a redirect instead of a forward A forward still submits to the page that it lands on. But a redirect will no longer retain the submit state on the landing page Comment out the forward line //setForward(req, "portlet.ext.library.success"); Add this line to the code res.sendRedirect(req.getParameter("redirect"));
AddBookAction.java What is “redirect”? “redirect” is the name of the hidden field we added to view.jsp res is the response object sendRedirect is an portlet method that grabs a request value from either the querystring or form submit. It than redirects to the redirect value Make sure that your redirect value is a valid URL
Deploy the Files to Tomcat Deploy files to Tomcat once you are finished Open up a cmd prompt –Click “Start”, “Run” and then type “cmd” Navigate to your ext directory and then type “ant deploy” …\ext>ant deploy
Final Steps 1.Restart Tomcat 2.Open up a new browser and type LOGIN: PASSWORD: test
Review Key Concepts Add a hidden “redirect” form field to view.jsp “redirect” is the URL of the view.jsp Make sure that the path exist in struts-config.xml In your java, replace your forward path with a sendRedirect path.
Revision History Jerry Niu9/13/2006-9/14/2006 Slide create and updates