Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Struts - A MVC web framework
Tomcat - JSP/Servlet container
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
JSP - A mailing list about Java Server Pages specification and reference
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Urgent JSP Help Needed!

Urgent JSP Help Needed!

2003-07-29       - By Michael Rogan

 Back
Reply:     1     2     3  

Hello,

Could someone please take a look at the two files below as soon as possible?
Something is wrong with the code and I am unable to figure it out.  It
generates 16 errors --  mostly "expected ;", but from what I can see all the
required semicolons are there!

If someone more experienced woth JSP could help, I would greatly appreciate it!
 This is an urgent problem and is frustrating me a great deal.

Thanks in advance!

-Mike

File #1: breadcrumb.jsp

<%@(protected) import="java.util.Properties Source code of java.util.Properties, java.io.InputStream Source code of java.io.InputStream, java.io.IOException Source code of java.io.IOException"
%>

<!-- BreadCrumb maker 1.0 -->
<%--

Reads a breadcrumb.properties file containing stuff like this:

start=<b>
end=</b>
pre=<a href="$path">
post=</a>
middle=\ &gt;
/=home
/cat1=Category 1
/cat2=Category 2
/cat1/index.jsp=&nbsp; The main page

For the path 'http://localhost:8080/breadcrumb/cat1/index.jsp', that will
create a string:

<b><a href="/breadcrumb/">home</a> &gt;<a href="/breadcrumb/cat1">Category 1</a
> &gt;<a href="/breadcrumb/cat1/index.jsp">&nbsp; The main page </a>


NOTE: If you change this file, be sure to touch any files including it, or the
changes won't be picked up.

Jeff Turner <jeff@(protected)>
http://opensource.socialchange.net.au/breadcrumbs/
16/08/2001
$Revision$ $Date$

--%>


<%! public static final String CONFIG="/ssi/breadcrumb.properties"; // if
starting with '/', will be relative to htdocs. Otherwise, relative to calling
page (*not* this included page) %>
<%! public static final int MAX_DEPTH=20; // max number of iterations before we
halt with an error %>
<%! public static final String PATH_TOKEN="$path"; // If this string is
encountered in the CONFIG file, it is replaced with the current path  %>
<%! public static final boolean PRINTERRORS=true; // If false, any errors will
result in "" output. Otherwise, behaviour is determined by COMMENTERRORS %>
<%! public static final boolean COMMENTERRORS=false; // If true, errors will be
printed in comments. If false, errors will be visible.  %>

<%!
/**
* Method to create a breadcrumb trail (or whatever it's called).
*/
String search(HttpServletRequest req) {
Properties props = new Properties();
try {
       InputStream in = getServletConfig().getServletContext()
.getResourceAsStream(CONFIG);
       props.load(in);
} catch (Exception e) {

       return printErr("could not find or read "+CONFIG);
}
try {
String start = (String)props.get("start");
String end = (String)props.get("end");
String post = (String)props.get("post");
String pre = (String)props.get("pre");
String middle = (String)props.get("middle");

StringBuffer result = new StringBuffer();


// Note: this algorithm traverses the path backwards, from the end to the root.
// Hence the ordering of 'post' before 'pre'

int count = 0;
String path = req.getRequestURI().substring( req.getContextPath().length() );  
// remaining path
String desc = null; // description for current path
boolean inMiddle = false;  // true if we've previously hit a non-null path
boolean last=false;  // true if we're on the last path ("/")

while ( true )
{
       if (last) path = "/";                   // we need *some* character for
the root.. this is as good as any
       desc = (String)props.get(path);
       if (desc != null)
       {
               if (inMiddle)
               {
                       result.insert(0, middle);
               } else inMiddle = true;
               if (post != null)
               {
                       result.insert(0, subst(req, post, path));
               }
               result.insert(0, subst(req, desc, path));
               if (pre != null)
               {
                       result.insert(0, subst(req, pre, path));
               }
       }

       if (last) break;
       // set up the path for our next iteration
       path = path.substring(0, path.lastIndexOf(System.getProperty("file
.separator"))); // strip from the last '/' onwards. In the last case, this will
result in ""
       if (path.equals("")) last = true;

       // .. because I'm not confident some weird usage won't break the
algorithm
       count++;
       if (count > MAX_DEPTH) {
               return printErr("Inifinite loop detected in breadcrumbs");
       }
}
result.insert(0, start);
return result.toString();
} catch (Throwable t) {
       return printErr("Couldn't generate breadcrumbs: "+t);
}
}

/**
* Replaces all occurrences of tokens in original, with values. In the case of
* PATH_TOKEN, replaces it with the context path plus the context-relative path.
*/
private static String subst( HttpServletRequest req, final String original,
final String path)
{
       return replaceSubString(original, PATH_TOKEN, req.getContextPath()+path
);
}

private static String printErr(String msg)
{
       if (!PRINTERRORS) return "";
       StringBuffer buf = new StringBuffer();
       if (COMMENTERRORS) {
               buf.append("<!--");
       } else {
               buf.append("<font color='red'>");
       }
       buf.append(msg);
       if (COMMENTERRORS) {
               buf.append("-->");
       } else {
               buf.append("</font>");
       }
       return buf.toString();
}

/**
* Replace substrings of one string with another string and return altered
string.
*
* @(protected) original input string
* @(protected) oldString the substring section to replace
* @(protected) newString the new substring replacing old substring section
* @(protected) converted string
*/
private static String replaceSubString( final String original,
                                           final String oldString,
                                           final String newString )
   {
       final StringBuffer sb = new StringBuffer();

       int end = original.indexOf( oldString );
       int start = 0;
       final int stringSize = oldString.length();

       while( end != -1 )
       {
           sb.append( original.substring( start, end ) );
           sb.append( newString );
           start = end + stringSize;
           end = original.indexOf( oldString, start );
       }

       end = original.length();
       sb.append( original.substring( start, end ) );

       return sb.toString();
   }
%>

<%= search(request) %>

*******************************************************************************
****

File #2: breadcrumb.properties

# Breadcrumbs file. Used to decorate a path.
#
# A path, eg '/foo/bar/index.jsp', will match the following paths, in order:
# '/'
# '/foo/'
# '/foo/bar/'
# '/foo/bar/index.jsp'
#
# The format for this file is simple name=value pairs.
# Possible entries:
#
# start # inserted before everything else, eg <ul>
# end # inserted after everything else, eg </ul>
# pre # inserted before every matched path, eg <li>
# post # inserted after every matched path, eg </li>
# middle # inserted between every pair of matching paths, eg '|'
# / # matches home directory
# /* # matches specified directory
#
# The values for the above variables may contain the string '$path', which will
# be replaced with the server-relative path to the currently matched path
# segment.
# For example:
# pre=<a href="$name">
# post=</a>
#
# will wrap each path segment in a link to that location. If '/index.jsp'
# matches, it will be rendered as '/mysite/index.jsp'.
#
# A full example
# For the path 'http://localhost:8080/breadcrumb/cat1/index.jsp', the example
# path matchers will create a string:

# <b><a href="/breadcrumb/">home</a> ><a href="/breadcrumb/cat1">Category 1</a>
><a href="/breadcrumb/cat1/index.jsp">? The main page </a>
#
#
# Jeff Turner
# http://opensource.socialchange.net.au/breadcrumbs/
# 16/08/2001
# $Revision$ $Date$


start=<b>
end=</b>
pre=<a href="$path">
post=</a>
middle=\ >

/=Home Page
/cat1=Category 1
/cat1/index.jsp=Main cat1 page
/cat1/subcat1/=Subcat 1
/cat1/subcat1/index.jsp=Main subcat1 page

/cat2=Category 2
/cat2/index.jsp=Main cat2 page
/cat2/subcat1/index.jsp=Main subcat2 page

===========================================================================
To unsubscribe: mailto listserv@(protected) with body: "signoff JSP-INTEREST".
For digest: mailto listserv@(protected) with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com



©2008 junlu.com - Jax Systems, LLC, U.S.A.