< html:rewrite /> html tag

< html:rewrite /> html tag

Previous Home Next

 

This is same as link tag .The rewrite tag is used to generate a URI based on exactly same rules as the link tag. But it defers without creating the <a> hyperlink. This tag is used when we want to create URI as string constants in JavaScript code.

There are four ways to specify the base URL:-
  • The action attribute :- This contains the actual content relative URI of the destination of this transfer.
  •  You must specify exactly one of the action attribute, the forward attribute, the href attribute, or the page attribute  
  • The forward attribute :-This is identified the name of the global forward element that received control these request. 
  • The href attribute :-This attributes is used to forward the current request.
  • The page attribute :-It specifies an application relative path  which this hyperlink will transfer control if activated.  Example The href attribute to specify an absolute URL for the frame: The page attribute to specify an absolute URL for the frame:

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

<a href="<html:rewrite action="Hello.do" />" 
This is url and click here
<html:rewrite action="Hello.do " />
</a>

 

Directory Structure of RewriteTagExample in Struts 1.3 Using MyEclipse IDE




index.jsp

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
<title>Struts html:rewrite tag example</title>
</head>
<body>
<h3>Struts html:rewrite tag example</h3>
<h4>
<a href='<html:rewrite action="rewriteAction.do"/>'>Click Me Struts Rewrite Tag</a>
</h4>
</body>
</html>

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 
<web-app>
  <display-name>Maven Struts Examples</display-name> 
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>
        org.apache.struts.action.ActionServlet
    </servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>
         /WEB-INF/struts-config.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet> 
  <servlet-mapping>
       <servlet-name>action</servlet-name>
       <url-pattern>*.do</url-pattern>
  </servlet-mapping> 
</web-app>

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
  <form-beans>
    <form-bean name="textForm" type="org.r4r.struts.TextForm"/>
  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings >
    	<action path="/rewriteAction" type="org.r4r.struts.RewriteAction">	
         <forward name="success" path="/success.jsp"/>
		</action>
  </action-mappings>
  <message-resources parameter="org.r4r.struts.ApplicationResources" />
</struts-config>

RewriteAction.java

package org.r4r.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class RewriteAction extends Action {
	public ActionForward execute(ActionMapping mapping,ActionForm form,
		HttpServletRequest request,HttpServletResponse response) throws Exception{
		return mapping.findForward("success");
	}

}

ApplicationResources.properties

# Resources for parameter 'org.r4r.struts.ApplicationResources'
# Project Struts1.3_TextTagExample
#label message
label.name = User Name 
label.course = Course Name
label.college = College Name
label.phone = Phone No
label.submit = Submit
label.reset = Reset

success.jsp

<html>
<head>
<title>Struts html:rewrite tag example</title>
</head>
<body>
<h3>Struts html:rewrite tag Example</h3>
<h4>This OUTPUT generated by html:rewrite tag in struts 1.3</h4>
</body>
</html>

Output




Previous Home Next