Saturday, November 22, 2014

splitting and comparing strings in Java

Should request.getServletPath().toLowerCase() give /index.jsp then...

<%
String location = request.getServletPath().toLowerCase();
for (String pieceOfLocation: location.split("/", 0)) {
   for (String anotherPieceOfLocation: pieceOfLocation.split("\\.")) {
      if (!anotherPieceOfLocation.equals("jsp")) {
         location = anotherPieceOfLocation;
      }
   }
}
if (location.equals("index")) {
   location = "default";
}
%>
<%=location%>

 
 

...with give back default

No comments:

Post a Comment