JSPPP.  Because your time is too valuable to waste manually formatting JSPs.  
  Home | JSPPP at SourceForge | Download | JSPPP In Action | CVS | To do | Contact Me

Here are a few examples of what JSPPP can do right now.

So how about starting off by showing proper formatting in a JSP that has JavaScript embedded inside Java? Since I'm showing the input and output side by side, I used a smaller line length. The default line length would output the entire jsp:useBean tag on one line. JSPPP turns

this: into this:
<jsp:useBean id="theBean" scope="request" class="package.class" />
<HTML>
<HEAD>
<TITLE>Java with Embedded JavaScript Example</TITLE>
</HEAD>
<BODY>
<% if (theBean.someStuff()) { %>
  <SCRIPT TYPE="Javascript">
       function foo() {
          doThis();
    }
      </SCRIPT>
    <% } else { %>
  <SCRIPT TYPE="Javascript">
        function foo() {
          doThisInstead();
        }
    </SCRIPT>
<% } %>
</BODY>
</HTML>
              
<jsp:useBean
    id="theBean"
    scope="request"
    class="package.class"
/>
<HTML>
  <HEAD>
    <TITLE>
      Java with Embedded JavaScript Example
    </TITLE>
  </HEAD>
  <BODY>
    <% if (theBean.someStuff()) { %>
      <SCRIPT TYPE="Javascript">
        function foo() {
          doThis();
        }
      </SCRIPT>
    <% } else { %>
      <SCRIPT TYPE="Javascript">
        function foo() {
          doThisInstead();
        }
      </SCRIPT>
    <% } %>
  </BODY>
</HTML>
              

Or in the other direction? JavaScript that has embedded Java. JSPPP turns

this: into this:
<jsp:useBean id="theBean" scope="request"
class="package.class" />
<HTML>
<HEAD>
<TITLE>JavaScript with Embedded Java Example
</TITLE>
<SCRIPT language="JavaScript">
function foo() {
<% if (theBean.isDoThis()) { %>
      doThis();
  <% } else { %>
  doThat();
       <% } %>
       }
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
              
<jsp:useBean
    id="theBean"
    scope="request"
    class="package.class"
/>
<HTML>
  <HEAD>
    <TITLE>
      JavaScript with Embedded Java Example
    </TITLE>
    <SCRIPT language="JavaScript">
      function foo() {
        <% if (theBean.isDoThis()) { %>
          doThis();
        <% } else { %>
          doThat();
        <% } %>
      }
    </SCRIPT>
  </HEAD>
  <BODY></BODY>
</HTML>
              

Now for something more interesting. How about some Struts tags within JavaScript? Please note the extra indent layer for the attributes of the tags that wouldn't fit in the line length, and the extra space after the <logic:iterate> tag since it has information inside it. If the tag didn't contain elements, this extra space would not have been written. Again, JSPPP was run with a small line length for these to fit side by side. JSPPP turns

this: into this:
<html>
<head><title>An example with JSP tags, Struts tags and
using the left angle bracket as a less than sign with
space and without space in JavaScript.</title>
<script language="javascript">
function test() {
var i = 0;
var j = 1;

if (i<j) {
<logic:iterate indexId="index" id="bean"
name="someFormBean" type="org.example.some.form.Class"
property="someProperty">
<%= bean.getSomeProperty() %>
if (i < j) {
Note:  <bean:write id="someFormBean"
property="someProperty" />
}
</logic:iterate>
}
}</script></head><body></body></html>
              
<html>
  <head>
    <title>
      An example with JSP tags, Struts tags and
      using the left angle bracket as a less than
      sign with space and without space in
      JavaScript.
    </title>
    <script language="javascript">
      function test() {
        var i = 0;
        var j = 1;

        if (i<j) {
          <logic:iterate
              indexId="index"
              id="bean"
              name="someFormBean"
              type="org.example.some.form.Class"
              property="someProperty">

            <%= bean.getSomeProperty() %>
            if (i < j) {
              Note:
              <bean:write
                  id="someFormBean"
                  property="someProperty"
              />
            }
          </logic:iterate>
        }
      }
    </script>
  </head>
  <body></body>
</html>
              

Anchor tags have special spacing requirements. JSPPP preserves whitespace before and after end anchor tags so that you don't end up with unwanted results like a space after your link text that's also part of the link. Here's an example of a link which is incorrectly formatted . There's a space between the link text and the period, which is part of the link. Here's an example of a link which is correctly formatted. There is no extra space. JSPPP handles spacing around end tags in a special way so that whitespace which is present will be preserved, and whitespace which is not present will be preserved. The emphasis below indicates that in the actual HTML, the tag has &lt; and &gt; in it so that it doesn't confuse the parser or the browser. JSPPP turns

this: into this:
<html>
  <head>
    <title>Anchor tags with various spacing.</title>
  </head>
  <body>
    <p>
      A link with
      <a href="example.com">text inside</a>, a comma
      afterwards, and still more text should be
      rendered with the comma immediately after the
      link.
    </p>
    <p>
      A link with <a href="example.com">text inside</a>
      and no comma afterwards, however, can be free to
      roam completely on it's own line, with nothing
      after it.
    </p>
    <p>
      A link with <a href="example.com">so much text
      inside that it has to wrap a line and continue on
      the next line must have the final </a> tag
      next to the last word</a>, with no whitespace,
      rather than on it's own line.  A comma should
      also appear next to the end </a> tag, with
      no whitespace in between them.
    </p>
  </body>
</html>
              
<html>
  <head>
    <title>Anchor tags with various spacing.</title>
  </head>
  <body>
    <p>
      A link with
      <a href="example.com">text inside</a>,
      a comma afterwards, and still more text should be
      rendered with the comma immediately after the
      link.
    </p>
    <p>
      A link with
      <a href="example.com">text inside</a>
      and no comma afterwards, however, can be free to
      roam completely on it's own line, with nothing
      after it.
    </p>
    <p>
      A link with
      <a href="example.com">
        so much text inside that it has to wrap a line
        and continue on the next line must have the
        final </a> tag next to the last word</a>,
      with no whitespace, rather than on it's own line.
      A comma should also appear next to the end
      </a> tag, with no whitespace in between
      them.
    </p>
  </body>
</html>
              


SourceForge Logo - Back To The SourceForge Main Page
JSPPP is available under the GNU General Public License. JSPPP is ©2002-2007 Christopher Evans. Use the Contact Me link in the link bar to e-mail me.