• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

Struts HTML Rewrite Tag ( < html:rewrite >)

September 27, 2010 //  by Krishna Srinivasan

Struts HTML Tag Library

Struts HTML tag library provides tags which are used to create input forms and HTML user interfaces. The tags in the Struts HTML library form a bridge between a JSP view and the other components of a Web application. Since a dynamic Web application often depends on gathering data from a user, input forms play an important role in the Struts framework. Consequently, the majority of the HTML tags involve HTML forms.

Syntax to use Struts HTML tag library

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

< html:rewrite >

< html:rewrite > -Renders a request URI based on exactly the same rules as the < html:link> tag does, but without creating the < a> hyperlink.

Example Code for < html:rewrite>

1.Create an Jsp page and name it as rewrite.jsp.It is the Welcome page for a user. In this example a hyperlink is provided to click to redirect to action class.

rewrite.jsp

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

< html>
    < head>

        < title> HTML Rewrite example </title>
    < head>
    < body bgcolor="#DDDDDD">
        < h1 > Struts html:rewrite example </h1>

        < a href="< html:rewrite action="rewrite.do"/>"> Click here...< a>
		  </body>
</html>

2.Simple Action class rewriteaction.java which is a sub class of Action which is used as actionforward to output page.
rewriteaction.java

package com.myapp.struts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

public class rewriteaction extends org.apache.struts.action.Action {

    private static final String SUCCESS = "success";

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        return mapping.findForward(SUCCESS);
    }
}

3.Create or modify struts config file struts-config.xml with action mappings.Struts-config file contains the information about the configuration of the struts framework to the application.It contains the action mappings which helps to select Action and other information for specific user’s request’s.


<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

< struts-config>

< action-mappings>
        < action path="/rewrite" type="com.myapp.struts.rewriteaction" >
        < forward name="success" path="/rewriteoutput.jsp"/>
		</action>
</action-mappings>

	</struts-config>

4.Create another simple Jsp page rewriteoutput.jspwhich is a output page for the user.


< html>
    < head>
        < meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        < title> Struts HTML Rewrite tag output page< /title>
    < /head>
    < body bgcolor="DDDDDD">
        < h1> Struts Rewrite Output Page < /h1>

    < /body>
< /html>

5.Building and running the application
Output

Access page:http://localhost:8084/rewrite/
The Output Redirected Page is Displayed

also read:

  • Struts 2.0 Introduction and Validations using Annotations
  • Introduction to Struts Actions
  • What’s new in Struts 2.0?
  • Internationalization and Taglibs in Struts 1.2

Category: StrutsTag: Struts Tags

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Struts HTML Link Tag ( < html:link >)
Next Post: Struts BEAN Struts Tag ( < bean:struts >) »

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

How to Write Comparators as Lambda Expressions in Java

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact