We want to redirect the action to another website or URL.
for that syntax is used
1 | <result name="success" type="redirect">${url}</result> |
type=”redirect” is used to redirect this action to the specified URL.
here URL is a variable in the action class with getter and setter methods.
We are getting the URL value from the JSP page to get the URL value in struts.xml we used ${url}.
First.jsp
1 2 | <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib uri="/struts-tags" prefix="s" %> |
Redirect To another Web site
1 |
Struts.xml
1 | ${url} |
RedirectAction.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | package com.ebhor; import com.opensymphony.xwork2.ActionSupport; public class RedirectAction extends ActionSupport { private String url; public String redirect() { System.out.println("Redirect to "+getUrl()); return SUCCESS; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } } |
Output