Rewrite Tag:

html:rewrite Tag - This tag renders a request URI based on exactly the same rules as the link tag does, but without creating the hyperlink.

Rewrite Tag:

Rewrite Tag<html:rewrite>:

     

html:rewrite Tag - This tag renders a request URI  based on exactly the same rules as the link tag does, but without creating the  hyperlink.
 
Note :

  1. This request URI value is useful when required to generate a string constant for use by a JavaScript procedure.
  2. This tag will automatically apply URL rewriting, to maintain session state in the absence of cookies.
  3. The content displayed for the hyperlink will be taken from the body of the tag. The base URL for the hyperlink
     is calculated based on properties given with the tag.
Name Description
action

This attribute specifies the logical name of a Action that contains the actual content-relative URI of the destination of this transfer. This hyperlink may be dynamically modified by the inclusion of query parameters, as described in the tag description.
You must specify exactly one of the action attribute, the forward attribute, the href attribute, or the page attribute.

anchor

Optional anchor tag ("#xxx") to be added to the generated hyperlink. Specify this value without any "#" character.

forward

Logical name of a global ActionForward that contains the actual content-relative URI of the destination of this transfer. This hyperlink may be dynamically modified by the inclusion of query parameters, as described in the tag description. 
You must specify exactly one of the action attribute, the forward attribute, the href attribute, or the page attribute.

href

The "href" attribute specifies URL to which this hyperlink will transfer control if activated. This hyperlink may be dynamically modified by the inclusion of query parameters, as described in the tag description. You must specify exactly one of the action attribute, the forward attribute, the href attribute, or the page attribute.

name

The name of a JSP bean that contains a Map representing the query parameters (if property is not specified), or a JSP bean whose property getter is called to return a Map (if property is specified).

page

The module-relative path (beginning with a "/" character) to which this hyperlink will transfer control if activated. This hyperlink may be dynamically modified by the inclusion of query parameters, as described in the tag description. You must specify exactly one of the action attribute, the forward attribute, the href attribute, or the page attribute.

property

The name of a property of the bean specified by the name attribute, whose return value must be a java.util.Map containing the query parameters to be added to the hyperlink. You must specify the name attribute if you specify this attribute.

scope

The scope within which to search for the bean specified by the name attribute. If not specified, all scopes are searched.

Example Illustrating the use of the Rewrite<html:rewrite> tag.
Here you will learn to use the Struts Html<html:rewrite> tag. 
We will cover an example that will show a working of<html:rewrite>tag.

Example code :
Creating an Action Class : Not Required here.
Creating Form Bean  : Not Required here.

Defining the global-forwards :
Add the following entry in the struts-config.xml file for global-forward. 

<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>

Developing the Action Mapping in the struts-config.xml :
Here, Action mapping helps to select the  Form Bean, the Action class etc, for specific requests. 

<action path="/Welcome" forward="/welcomeStruts.jsp"/>

Developing the HtmlRewriteTag.jsp page :

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
  
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JSP Page</title>
  </head>
  <body bgcolor="#999933">
  <h3><font color="#FFFF33">html:rewrite Tag Demo</font></h3>
  <A HREF="<html:rewrite action="Welcome.do" />" >
   Click 
for URL <html:rewrite action="Welcome.do" />
   </A> 

  </body>
</html>

Developing the welcomeStruts.jsp page :

<%taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>

<html:html locale="true">
<head>
<title><bean:message key="welcome.title"/></title>
<html:base/>
</head>
<a href="HtmlRewriteTag.jsp">Go Back........</a><br/>
<body bgcolor="#999933">

<logic:notPresent name="org.apache.struts.action.MESSAGE"
    
scope="application">
  <font color="red">
  ERROR:  Application resources not loaded -- check servlet container
  logs for error messages.
  </font>
</logic:notPresent>

<h3><bean:message key="welcome.heading"/></h3>
<p><bean:message key="welcome.message"/></p>
</body>
</html:html>

Add the following line in the index.jsp to call the form :

<a href="HtmlRewriteTag.jsp">HtmlRewriteTagDemo</a><br/>

Building and Testing the Example  :
Build , deploy and Test  the application . 
Open the browser and navigate to the HtmlRewriteTag.jsp page. 

Your browser displays the following page.


Click  the hyperlink to analyze the generated URL, welcomeStruts.jsp  page, and see the output .

Output after clicked..........

Above actions   displays the working of  <html:rewrite>tag.