For Programmers: Free Programming Magazines  


Home > Archive > Java Beans > July 2006 > creating dynamic links (href) in jsp









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author creating dynamic links (href) in jsp
val

2006-07-31, 3:59 am

Sorry for crossposting but maybe this group is better for my question:
What in your oppinion is the best way of generating dynamic menu (html
links) in jsp? I did it following way:
e.g. i include in index.jsp the menu.jsp page with parameters like this:

<jsp:param name="menu" value="contact.jsp : Send email , admin.jsp :
Administration" />

then in menu.jsp i get the parameter menu and process it like this :

StringTokenizer stMenu = new StringTokenizer(request.getParameter("menu"),
",");
StringBuffer sbMenu = new StringBuffer();

while (stMenu.hasMoreElements()) {
String sLink = stMenu.nextToken();
sbMenu.append("<a href=\"");
/* get the url */
sbMenu.append( sLink.substring(0, sLink.indexOf(":")) );
sbMenu.append("\">");
/* now get description */
sbMenu.append( sLink.substring( sLink.indexOf(":")+1, sLink.length()) );
sbMenu.append("</a>");
}
out.println( sbMenu.toString() );

isn`t that too clumsy? Are there better ways to implement such a link
producer?
or would it be better to create a bean holding all the link mappings for
each site and just retrieve it in jsp?

Regards
Val



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com