Link Rewriting
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Quercus
Servlets and Filters
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Introduction
User's Guide
Reference
Tutorials

How it works
XTP Copy
Formatting
Link Rewriting
JSP tag libraries
Formatting
User's Guide
JSP tag libraries

XTP can be used to rewrite links. Rewriting links to encode sessions is a tedious and error-prone task. If you use URL-encoded sessions, every <a> link and every <form> action needs a rewritten link using response.encodeURL(). XTP can rewrite those for you automatically.

stylesheet.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <!-- make sure '<' is not printed as '&lt;' -->
  <xsl:output disable-output-escaping='true'/>

  <!-- copy input to output -->
  <xsl:template match='*|@*'>
    <xsl:copy>
      <xsl:apply-templates select='node()|@*'/>
    </xsl:copy>
  </xsl:template>

  <!-- rewrite <a href> -->
  <xsl:template match="a[@href]">
    <a href='<%= response.encodeURL("{@href}") %>'>
      <xsl:apply-templates select="node()|@*[name(.)!="href"]"/>
    </a>
  </xsl:template>
</xsl:stylesheet>

Your XTP page may look something like:

test.xtp
<?xml-stylesheet href='stylesheet.xsl'?>
<h1>My test</h1>

Adding: 2 + 2 = <%= 2 + 2 %>

<p>New? <%= session.isNew() %>

<p>And <a href='test.xtp'>linking</a>

The transformed file will look like:

<?xml-stylesheet href='stylesheet.xsl'?>
<h1>My test</h1>

Adding: 2 + 2 = <%= 2 + 2 %>

<p>New? <%= session.isNew() %>

<p>And <a href='<%= response.encodeURL("test.xtp") %>'>linking</a>


Formatting
User's Guide
JSP tag libraries
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.