So, I decided to "upgrade" my site, written by JSP, to display a static URL instead of the usual dynamic URL.
So far, I have written a servlet to redirect a static URL to the corresponding dynamic URL. Data is stored in a database table.
This is the code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { StringBuilder redirectTo = new StringBuilder(); redirectTo.append(getBaseURL()); redirectTo.append(getBaseURI()); redirectTo.append("/index.jsp"); String url = request.getRequestURI(); if (url.contains(".jsp")) return; try { KeyPageId_Lang k = SiteMap.getRedirectFromCanonicalURL(url); if (k!=null) { redirectTo.append("?id=" + k.getkPageId()); redirectTo.append("&lang=" + k.getkLanguage()); } else { log.error("CanonucalURLRedirect: No translation found for " + url); } } catch (Exception e) { log.error("CanonucalURLRedirect ERROR: " + e.getMessage()); } response.sendRedirect(redirectTo.toString());
So if I enter: http: // localhost / jsp / en / home , it successfully redirects to http: //localhost/jsp/index.jsp? Id = 1 & lang = en
If no static URL is found, it will be redirected to the default value /index.jsp
Also, on index.jsp, I have the following line:
<link rel="canonical" href="<%=canonicalURL%>" />
For search engines, index friendly static URLs.
Now I searched a lot, and still can't find a way to replace the dynamic URL with a static URL in the browser navigation bar to display localhost / jsp / en / home instead of localhost / index. JSP ID = 1 &? languages ββ= ep
Any idea?
Thanks!
source share