Previously all the JSPs in my application were in the same folder. To organize things a bit, I categorized them according to action and now they are nice, but the problem is all the links in my application are relative. And they all expect that they are in the same base folder, but now they're not. Instead of prepending every single link my JSPs with the context path, I was going to use <base href="" > to generate a full URI up to and including the context path. The problem is: how do I generate an accurate URI? If I use ServletRequest to generate the URI this was:
getScheme() + "://" + getServerName() + ":" + getServerPort() + getContextPath()


The URL that the user sees will now have a port number, if it didn't have one before. OR, if the server is forwarding the request from somewhere else, it might expose a whole new URI bypassing the forwarding mechanism. My alternative was this:

String context = request.getContextPath();

String fullUrl = request.getRequestURL().toString();
URL url = new URL(fullUrl);
String path = url.getPath();
String base = fullUrl.substring(0,fullUrl.indexOf(path)) + context;

Where base is the base of my web application as it was typed by the user. Does anyone forsee any problems with doing it this way? Any other ideas or warnings against using <base href="" >


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to