From 9adb555fe41f6322310be1fea406d9d8d44acafe Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Wed, 26 Dec 2012 14:30:03 +0700 Subject: New tags URLs --- src/java/com/juick/http/www/Blogs.java | 53 ++++++++-------- src/java/com/juick/http/www/Main.java | 6 +- src/java/com/juick/http/www/NewMessage.java | 8 +-- src/java/com/juick/http/www/PageTemplates.java | 14 +++-- src/java/com/juick/http/www/Tags.java | 87 -------------------------- src/java/com/juick/http/www/User.java | 2 +- src/java/com/juick/http/www/UserThread.java | 6 +- web/style3.css | 2 +- 8 files changed, 49 insertions(+), 129 deletions(-) delete mode 100644 src/java/com/juick/http/www/Tags.java diff --git a/src/java/com/juick/http/www/Blogs.java b/src/java/com/juick/http/www/Blogs.java index 0250a157..fb0657ad 100644 --- a/src/java/com/juick/http/www/Blogs.java +++ b/src/java/com/juick/http/www/Blogs.java @@ -22,6 +22,7 @@ import com.juick.server.TagQueries; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.net.URLEncoder; import java.sql.Connection; import java.sql.PreparedStatement; @@ -42,6 +43,16 @@ import javax.servlet.http.HttpServletResponse; public class Blogs { protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String paramTagStrQuery = request.getParameter("tag"); + if (paramTagStrQuery != null) { + String url = "/tag/" + URLEncoder.encode(paramTagStrQuery, "UTF-8"); + String paramBeforeStr = request.getParameter("before"); + if (paramBeforeStr != null) { + url += "?before=" + paramBeforeStr; + } + Utils.sendPermanentRedirect(response, url); + } + com.juick.User visitor = Utils.getVisitorUser(sql, request); Locale locale = request.getLocale(); ResourceBundle rb = ResourceBundle.getBundle("Blogs", locale); @@ -52,9 +63,14 @@ public class Blogs { String paramShow = request.getParameter("show"); int paramTag = 0; - String paramTagStr = request.getParameter("tag"); - if (paramTagStr != null && paramTagStr.length() < 64) { + String paramTagStr = null; + if (request.getRequestURI().startsWith("/tag/")) { + paramTagStr = URLDecoder.decode(request.getRequestURI().substring(5), "UTF-8"); paramTag = TagQueries.getTagID(sql, paramTagStr, false); + if (paramTag == 0) { + response.sendError(404); + return; + } } int paramBefore = 0; @@ -135,20 +151,10 @@ public class Blogs { out.println("
" + getTags(sql, 30) + "
"); + out.println("" + getTags(sql, 36) + "
"); out.println("" + rbnm.getString("Tags") + ":
"); - printUserTags(sql, out, visitor.UID); + printUserTags(sql, out, visitor); out.println("